My home Zabbix instance was running out of space today, so I had to resize the partition that it lived on so that it would last a few more days while I worked out how to migrate it from my VMWare host to my ProxMox host.
Resizing Hard Drive
First thing first, I needed to expand the HDD in the hypervisor.
After resizing the hard drive, you may to rescan the disk for Linux to recognise the new size.
The following command will rescan all the disks.
# for x in /sys/class/scsi_disk/*; do echo '1' > $x/device/rescan; done
If the disk is still the same size in fdisk
, then you’ll need to reboot the server.
Resizing Partition
Depending on the partition layout, you will need to either resize 1 or 2 partitions, assuming that the partitions are at the end of the disk.
In layout 1, you’ll have just a single partition that is the LVM partition.
In layout 2, you’ll have an extended partition that contains the LVM partition.
The process to resize partitions are the same, except that in layout 2, you’ll need to resize 2 partitions, with the extended one being resized first so that it’s able to contain the LVM partition.
I’m using parted
to resize my partitions in this case.
First up is to start parted
on /dev/sda
# parted /dev/sda
I normally use Bytes as a unit, and then use the print free
command to see where the partition needs to end to fill up the Free Space.
(parted) unit b
(parted) print free
Number Start End Size Type File system Flags
32256B 1048575B 1016320B Free Space
1 1048576B 255852543B 254803968B primary ext2 boot
255852544B 256900095B 1047552B Free Space
2 256900096B 53687091200B 53430191104B primary lvm
53687091201B 75161927679B 5369757696B Free Space
To resize it, a simple resizepart
command is used.
(parted) resizepart 2 75161927679B
In the case of an extended partition containing the LVM partition, the command above just needs to be run against the 2 partition numbers, with the extended partition being extended first, and the LVM partition being extended second with the ending byte being one less than the extended partition.
In this example, partition 2 is the extended partition, and partition 5 is the LVM partition.
(parted) resizepart 2 75161927679B
(parted) resizepart 5 75161927678B
Resizing Physical Volume
After resizing the partition, you’ll need to resize the physical volume. This is as simple as running the following:
# pvresize /dev/sda2
Replace /dev/sda2
with the partition that has just been extended.
Resizing Logical Volume
Next, the logical volume will need to be resized with lvresize [lv path]
.
You can choose to resize to fill up the empty space, or you can select a specific size. In this example, I’ve resized the logical volume to use all available space.
Replace /dev/VolGroup/lv_root
with the path of the logical volume that needs resizing.
# lvresize -l +100%FREE /dev/VolGroup/lv_root
You should see the following output once the logical volume is resized.
Size of logical volume VolGroup/lv_root changed from 48.54 GiB (12426 extents) to 68.54 GiB (17546 extents).
Logical volume lv_root successfully resized
Resize Filesystem
The last thing to do is to resize the filesystem. This can be done live on ext4 with the resize2fs tool.
Replace /dev/mapper/VolGroup-lv_root
with the path to the filesystem that needs resizing.
If you’re unsure of the filesystem, lvscan
will display the path to the filesystem.
# resize2fs /dev/mapper/VolGroup-lv_root
Once the resize is complete, you should be able to run a df
and see the new filesystem size.
In my case, the filesystem was grown from 50G to almost 70G
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
68G 44G 20G 69% /
Thanks for this, you just saved me a ton of time and frustration! 🙂
Happy to help
These instructions were concise and clear and did just what I wanted to do, without adding any ugly and useless extraneous partitions to the volume group, and on a live root filesystem, no less. Thanks a bunch!
Happy to help
A much easier way to accomplish this is to run the command vgdisplay to get the number of free PEs then run the following command string
lvextend -l + /dev// -r
By adding -r to the end of the the command it will automagically resize the volume at the same time as extending it. The vgdisplay command will allow you to see exactly how many physical extent you actually have so there is no guesstimation
Thanks for that, will be helpful in future.
[…] A special thanks to SirLagz for his guide on this topic: http://sirlagz.net/2016/01/20/live-resizing-lvm-on-linux/ […]
Legend.
Only article I could find on resizing LVM without creating a brand new partition. Ubuntu forums and StackExchange are useless when it comes to anything LVM but somehow populate the top Google search results. So thank you good sir.
Glad this was of help 🙂 Feel free to repost this to any relevent Ubuntu/Linux Stack Exchange Question 🙂
You might need xfs_growfs instead of resize2fs
See https://stackoverflow.com/questions/26305376/resize2fs-bad-magic-number-in-super-block-while-trying-to-open