Here we show you how to expand an LVM volume or partition in Linux by first resizing logical volume followed by resizing the file system to take advantage of the additional space.
See here if you’re instead trying to do the opposite and shrink an LVM volume.
Note: In this example we are working in CentOS 7, some commands may differ in different Linux distributions.
In this example we will work through expanding logical volume /var/centos/var from 5GB to 10GB. We currently have this logical volume mounted to /mnt.
Overview of Logical Volume Manager (LVM)
Before working through the resizing process it’s important you first understand some basic concepts around physical volumes, volume groups, logical volumes, and the file system.
- Physical Volume (PV): This can be created on a whole physical disk (think /dev/sda) or a Linux partition.
- Volume Group (VG): This is made up of at least one or more physical volumes.
- Logical Volume (LV): This is sometimes referred to as the partition, it sits within a volume group and has a file system written to it.
- File System: A file system such as ext4 will be on the logical volume.
LVM Resize – How to increase or expand the logical volume
This process is extremely easy to do with LVM as it can be done on the fly with no downtime needed, you can perform it on a mounted volume without interruption. In order to increase the size of a logical volume, the volume group that it is in must have free space available.
To view the free space of your volume group, run vgdisplay command as shown below and look at the “Free PE / Size” field.
[root@CentOS7 ~]# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 20.74 GiB PE Size 4.00 MiB Total PE 5309 Alloc PE / Size 4030 / 15.74 GiB Free PE / Size 1280 / 5.00 GiB VG UUID VvG6Sp-wIgb-LTh0-szdU-s9R1-a6K9-qHassI
In this example we have 5GB of free space in the volume group, as shown by “Free PE / Size 1279 / 5.00 GiB”.
Note: If you do not have any or enough free space in the volume group, you will first need to expand the volume group to complete the resize. Alternatively if you have multiple LVM partitions, you could shrink a different logical volume first to create space within the volume group.
Now that we have confirmed there is space free within the volume group, confirm the name of the logical volume you want to increase as well as how much space you plan on adding. The below lvdisplay command will show all logical volumes and their current size. It will also show the volume group that the logical volume is a member of, so ensure that the correct volume group has been checked for enough space with vgdisplay as previously mentioned to prevent trying to increase a logical volume that is inside some other volume group.
As shown in the example below, we are going to be working with the logical volume “var” which is in volume group “centos”, the volume group we saw in vgdisplay. In this example we only have just the one volume group, but you may have more so you need to check.
[root@CentOS7 ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/var LV Name var VG Name centos LV UUID 7PNgg2-ZmnG-a26g-zRoT-PRVM-RDc1-oq6J4M LV Write Access read/write LV Creation host, time CentOS7, 2015-04-16 07:50:25 +1000 LV Status available # open 0 LV Size 5.00 GiB Current LE 1280 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
Now it’s time to expand the logical volume. In the below example we are using the -L flag to increase by a size specified (M for Megabytes, G for Gigabytes, T for Terabytes). You can alternatively remove the + to increase to the amount specified rather than by the amount specified.
lvextend -L+5G /dev/centos/var Rounding size to boundary between physical extents: 4.90 GiB Size of logical volume centos/var changed from 5.00 GiB (1280 extents) to 10.00 GiB (2560 extents). Logical volume var successfully resized
The above command will increase the logical volume /dev/centos/var by 5GB, currently it is already 5GB so this will increase it to a total of 10GB. You could achieve the same with “lvextend -L 10G /dev/centos/var” which will increase the logical volume to 10GB as well, as this is what was specified with no +. Alternatively if you instead want to just use all free space in the volume group rather than specifying a size to increase to, run “lvextend -l +100%FREE /dev/centos/var”.
We can run the below lvdisplay command shown below to check that the extend completed as expected.
[root@CentOS7 ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/var LV Name var VG Name centos LV UUID 7PNgg2-ZmnG-a26g-zRoT-PRVM-RDc1-oq6J4M LV Write Access read/write LV Creation host, time CentOS7, 2015-04-16 07:50:25 +1000 LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2
Now that the logical volume has been extended, we can resize the file system. This will extend the file system so that it takes up the newly created space inside the logical volume. The command may differ depending on the type of file system you are using.
Use this for ext3/4 based file systems
resize2fs /dev/centos/var
Alternatively, use this for xfs based file systems
xfs_growfs /dev/centos/var
After the file system has been resized the space should be ready to use. If you run a ‘df’ command to view the disk space you should see that it’s been increased successfully.
[root@CentOS7 mnt]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 9.8G 1.4G 8.5G 14% / devtmpfs 908M 0 908M 0% /dev tmpfs 914M 0 914M 0% /dev/shm tmpfs 914M 8.6M 905M 1% /run tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sda1 497M 96M 402M 20% /boot /dev/mapper/centos-var 10G 33M 10G 1% /mnt
In this example I have run a ‘mount /dev/centos/var /mnt’ to mount the logical volume to /mnt, as shown above /mnt is correctly reporting a size of 10G.
Summary
We have now successfully expanded a file system and corresponding LVM logical volume without any down time. This was done by first expanding the logical volume, and then performing an on-line resize of the file system.
THANK YOU! The only site that explains resizing a LVM without adding another partition.
Cheers, happy to help!
Agreed! This was very helpful as well. I have a headless server running Fedora 25 that was granted 512 GB of space (what can I say, those base-2 numbers stick) and I couldn’t figure out why my root partition was only using 15 GB. Any other resources online mention creating a new partition which I didn’t even entertain as an option, since it’s an unacceptable solution
Following your procedure I was able to expand the root partition by 300 GB and now I can start copying my 250 GB KVM image file again…. ;-)
Awesome! Glad to hear that the guide helped :)
when you get issues with your installation, you’ll find out why it was good idea to have partitions for your data.
THANKS SO MUCH!
Others tutorials on others websites didn’t work!
You saved me from format and reinstall all system. Thanks!
No problem :) happy to help!
Thank you so much for this informative article. I was stuck on a sunday afternoon with our sql server not being able to work due to space shortage on the hard disk drive.
No problem, good to hear that you were able to get it fixed!
If the lvdisplay is showing the logical volume without path.
How can I get the path so I can mount the volume? Thx
Can you provide the output that you get?
You should be able to find it at /dev/vg_name/lv_name, so as long as you can get the vg/lv names from vgdisplay and lvdisplay it should be there by default.
Appreciated! Especially the
> you can perform it on a mounted volume without interruption.
“little detail” :)
No problem! Good to hear it helped :)
…and it works like a charm on Fedora 26 too. Newly thanks.
Great to hear!
Thank you! This guide was exactly what I needed after adding some space in VMware to a Linux appliance and using a Gparted live CD to add the space to the partition.
No worries :)
excellent repository.
Well that was easy. Thanks for taking the complexity out of the problem.
This works for CentOS 5.11. It was the fourth Internet recipe I tried. VERY much appreciated!
Nice Explanation
Super explanation, thanks. A little detail though, I think the resize command should be:
resize2fs /dev/mapper/centos-var
No problem! I think both work :)
Ty it’s helped me out alot
No problem!
In CentOS 7 you can use the -r option to lvextend to resize the file system as well as resizing the volume size, instead of a separate call to resize2fs / xfs_growfs. Particulary useful if you want to shrink a partition as it does all the calculations for you. Doing it manually risks wrecking the file system if you make a mistake when shrinking.
While I haven’t tested it it should also error out without making any changes if it can’t shrink the filesystem (e.g. too much data present in your ext4, and you can’t shrink an xfs filesystem).
Yeah you can do it in one go like that.
Thanks A LOT!
No problem!
Tricky subject with amazing and pretty simple explanation.
does it delete my data in the LV?
Which command are you referring to? The process as a whole, no it shouldn’t, if you you’re running something like lvremove on the other hand that then could be bad.
It worked on a virtual Ubuntu 18.04 saving me a lot of headaches later! Thank you!
Same. Thank you Jarrod!
excellent article.
simple and crystal clear
Great article – thanks – there was one typo I think where you said to
“We can run the below lvdisplay command shown below to check that the extend completed as expected.”
but the example in the box was vgdisplay
“[root@CentOS7 ~]# vgdisplay”
Thanks, I’ve fixed it up.
Thank you. After a lot of searching, your instructions were thorough and perfect for expanding our VM running an important climate research modeling tool, but running out of space!
Your guide is simply EXCELLENT. Worked like a charm! Thank you very very much!
I had to use:
xfs_growfs
eg.:
sudo xfs_growfs /var
Instead of the xfs_growfs /dev/debian-vg/var
cause it was giving me error:
xfs_growfs: /dev/debian-vg/var is not a mounted XFS filesystem
But thanks for this instruction. I’ll put this page to my bookmark
I hate to be the only detractor, but I think the “How to increase an LVM partition” in this article’s title is inaccurate. What is described here is how to increase an LVM logical volume, not an LVM partition.
Will these steps works for ONLINE File System(FS) extension even the FS is in inconsistent state.
I’m extending the FS by increasing the existing device size and it fails at step resize2fs saying the permission denied. I’m using lvresize command instead of lvextend.
Correction proposed for this issue is: unmount the MP, e2fsck and resize2fs but my use case does not allow unmount.
Any help on extending the FS without un mounting the MP and correcting the FS and extending the FS.
I cannot thank you enough. the amount of times i had to do this on production systems is…
What does it mean if in vgdisplay and lvdisplay, the VG Size and LV Size are negative?!
Haven’t seen that one before, sorry.
I successfully shrunk my `vgmint/root` volume using your related tutorial. There’s now 68G of free space according to `vgdisplay`:
$ sudo vgdisplay
--- Volume group ---
VG Name vgmint
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <930.28 GiB
PE Size 4.00 MiB
Total PE 238151
Alloc PE / Size 220574 / <861.62 GiB
Free PE / Size 17577 / 68.66 GiB
But I run into errors trying to extend my second volume, `vgmint/swap`.
$ sudo lvextend -L 48G /dev/vgmint/swap_1
Size of logical volume vgmint/swap_1 changed from 976.00 MiB (244 extents) to 48.00 GiB (12288 extents).
Logical volume vgmint/swap_1 successfully resized.
$ sudo resize2fs /dev/vgmint/swap_1
resize2fs 1.45.5 (07-Jan-2020)
resize2fs: Bad magic number in super-block while trying to open /dev/vgmint/swap_1
Couldn't find valid filesystem superblock.
$ sudo e2fsck -fy /dev/vgmint/swap_1
e2fsck 1.45.5 (07-Jan-2020)
/dev/vgmint/swap_1 is mounted.
e2fsck: Cannot continue, aborting.
$ umount /dev/vgmint/swap_1
umount: /dev/mapper/vgmint-swap_1: not mounted.
Any ideas what’s going wrong here?
A perfect guide, exactly what I needed. No fluff, right to the meat of the issue. Everything worked perfectly on RHEL 8.5.
Much apprecaited!