LVM - nimrody/knowledgebase GitHub Wiki

Increasing the size of a live Linux root partition

  1. Power down the machine, increase the disk size allocated by the hypervisor (VMWare/Virtualbox/etc.)
  2. 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)

  1. 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)

  2. Resize LVM's physical partition: pvresize /dev/sda5 (use pvdisplay to show the physical volumes)

  3. Resize the logical partition: lvresize /dev/nir-lnx-11-vg/root /dev/sda5 (use lvdisplay to show the logical volumes)

  4. 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

  1. Download gparted ISO image
  2. 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 o pvresize /dev/sda5 (followed by pvdisplayif you want) o reactivate LVM vgchange -a y xubuntu-vg o lvextend -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):

  1. Download gparted live ISO image or go to https://gparted.org/ and select the latest live ISO)
  2. Power down the virtual machine, mount the ISO as a CD-ROM and reboot the machine.
  3. The virtual machine will boot into gparted -- the partition editor (not before asking you for your preferred language and other stuff -- accept all defaults).
  4. You will see a single large partition holding the linux volumes and a "free space" entry.
  5. If there is a "lock" icon next to the partition, gparted will refuse to let you resize it. If so, use the following procedure:
    1. Right click your mouse and open a terminal with root permisions (Your prompt should look like "#" instead of the usual "$")
    2. Run vgchange -a n xubuntu-vg -- this will disable the LVM partition. Otherwise gparted will not allow you to resize the partition.
    3. Go back to the gparted app and refresh its display. The lock should disappear
  6. Right click on the partition and extend it (you will have to do this twice - for the extnended parition and the logical partition inside).
  7. Right click your mouse and open a terminal with root permissions if you don't already have one (prompt should look like "#")
  8. Run pvresize /dev/sda5 to resize the linux LVM physical volume (use vgs -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)
  9. Run lvextend -r /dev/xubuntu-vg/root /dev/sda5 to extend the logical volume (the -r asks it to resize the filesystem too)
  10. Run shutdown -h now, remove the CD-ROM and boot again.