This guide was tested on CentOS 7 but should be in general applicable for other Linux distros with parted
and LVM
WARN You can’t resize partitions on the running OS in CentOS 6 (unless you’re brave enough to mess with the
sfdisk
) So the fastest option is to add new disk partition, create LVM PV from it and extend needed LVM VG accordingly Bad luck for you if you’re not using LVM ☠️
-
Add required amount of space to the virtual machine disk
-
Force Linux to rescan disk and load its new size - example for the /dev/sda and CentOS 7:
echo 1 > /sys/block/sda/device/rescan
-
Check that free space is detected - example for the /dev/sda:
# Check free space parted /dev/sda print free # Example output: Model: VMware Virtual disk (scsi) Disk /dev/sda: 429GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 32.3kB 1049kB 1016kB Free Space 1 1049kB 1075MB 1074MB primary xfs boot 2 1075MB 268GB 267GB primary lvm 268GB 429GB 161GB Free Space <<< DETECTED FREE SPACE
-
Resize partition - in this example using all the free space (161GB or 150GiB) to resize
/dev/sda2
:parted -a optimal /dev/sda resizepart 2 429GB
If you just need to resize a partition then you’re done, if you need to resize the LVM disk - see the next steps below.
-
Resize LVM PV and check:
# Resize pvresize /dev/sda2 # Check pvs
-
Resize LV and underlying FS (enabled by the option -r). Add 100GiB to the LV (leaving 50GiB free for the future usage) and check - example for the lv_data:
lvresize /dev/vg00/lv_data -r -L +100G # Check lvs
6a. Alternatively you can add all the available free space to the LV by doing so:
bash lvresize /dev/vg00/lv_data -r -l +100%FREE # Check lvs