LVM - nimrody/knowledgebase GitHub Wiki
Increasing the size of a live Linux root partition
- Power down the machine, increase the disk size allocated by the hypervisor (VMWare/Virtualbox/etc.)
- Boot the machine.
fdisk -l
should show the new total size (but partitions are still using the old smaller size)
Note: No need to power down the machine. Resize and run echo 1 > /sys/class/scsi_disk/2\:0\:0\:0/device/rescan
(lsblk
should show /dev/sda
as having more disk space)
-
Run
parted
. Resize the extended partition, then the logical partition that is within:print resizepart 2 -1 # 2 is the extended partition (-1 means as big as you can) resizepart 5 -1 # 5 is the logical partition within the extended partition
Ignore the message about updating
fstab
unless you have created a new partition (we haven't) -
Resize LVM's physical partition:
pvresize /dev/sda5
(usepvdisplay
to show the physical volumes) -
Resize the logical partition:
lvresize /dev/nir-lnx-11-vg/root /dev/sda5
(uselvdisplay
to show the logical volumes) -
Finally, resize the filesystem:
resize2fs /dev/mapper/nir--lnx--11--vg-root
Useful LVM commands
-
pvdisplay -m
-
vgdisplay -v
(vgs -o +devices,lv_path
) -
lvscan
-
lvs --segments
-
lvdisplay -m
-
Resizing a virtualbox disk
- Download gparted ISO image
- Follow instructions here:
o boot the live image and open terminal
o deactivate LVM for gparted to remove the lock icon:
vgchange -a n xubuntu-vg
o "refresh" gparted display then resize the extended partition and then the inner logical partition opvresize /dev/sda5
(followed bypvdisplay
if you want) o reactivate LVMvgchange -a y xubuntu-vg
olvextend -r /dev/xubuntu-vg/root /dev/sda5
(-r
means resize the ext2 filesystem)
For our xubuntu machines:
First resize the physical disk (the resize argument is megabytes, so the following is about 100GB)
VBoxmanage modifyhd MyLinux.vdi --resize 100000
Then follow the instructions here (repeated below for our xubuntu installation):
- Download gparted live ISO image or go to https://gparted.org/ and select the latest live ISO)
- Power down the virtual machine, mount the ISO as a CD-ROM and reboot the machine.
- The virtual machine will boot into gparted -- the partition editor (not before asking you for your preferred language and other stuff -- accept all defaults).
- You will see a single large partition holding the linux volumes and a "free space" entry.
- If there is a "lock" icon next to the partition, gparted will refuse to let you resize it. If so, use the following procedure:
- Right click your mouse and open a terminal with root permisions (Your prompt should look like "#" instead of the usual "$")
- Run
vgchange -a n xubuntu-vg
-- this will disable the LVM partition. Otherwise gparted will not allow you to resize the partition. - Go back to the gparted app and refresh its display. The lock should disappear
- Right click on the partition and extend it (you will have to do this twice - for the extnended parition and the logical partition inside).
- Right click your mouse and open a terminal with root permissions if you don't already have one (prompt should look like "#")
- Run
pvresize /dev/sda5
to resize the linux LVM physical volume (usevgs -o +devices,lv_path
to get the device name which in my case was/dev/sda5
and the path which was/dev/xubuntu-vg/root
) - Run
lvextend -r /dev/xubuntu-vg/root /dev/sda5
to extend the logical volume (the -r asks it to resize the filesystem too) - Run
shutdown -h now
, remove the CD-ROM and boot again.