How to resize root LVM partition in Fedora without LiveCD or Rebooting

Solution 1:

You can grow a logical volume online. You'd have to unmount it to shrink it (which requires a LiveCD / Rescue Mode.)

  1. pvresize /dev/sda2 (assuming your LVM partition is sda2. Replace as required.)
  2. lvextend /dev/mapper/root -l+100%FREE (or, whatever your root logical volume is called.)
  3. resize2fs /dev/mapper/root (assuming ext2/3/4)

Solution 2:

Did your system really change from 20 to 50 GB? That seems really odd since your sda2 device is ~40GB, lv_root shows 36GB, and swap shows 6GB.

Your output of fdisk -l shows the total sectors of /dev/sda is 104857600. The last sector used by /dev/sda2 is 83886079. This tells me that you have not adjusted the partition size to use all the available space on the drive. The pvresize command doesn't change the partition table. You need to change the partition table first.


Solution 3:

Install gparted. Run as root (use ssh -X or x2go if remote). Select the partition. It should show free space past the end (to the right). If it doesn't, you need to reboot for your virtual machine to see the new size of the virtual device. That should be minimal downtime with systemd.

Right click and select resize. Drag the end to the end of the disk. Make sure you do not touch the beginning. gparted is able to move a partition during resize, but that will, of course destroy a running system. But moving the end is fine. Review the pending operation gparted will perform to make sure you are extending and not moving the partition. Click apply. gparted will change the partition on disk, then issue the kernel ioctl to reread the partition table, changing the size of the live block device as well. Then, since it sees it is an LVM PV, it runs pvresize for you. Exit gparted, and vgs now shows your new space.

I've heard rumors that parted can do all that without the overhead of a GUI, but I've never been able to figure out the voodoo. Parted has to be one of the worst CLI interfaces I've ever tried to use.

Don't use fdisk, you have to delete and reallocate the partition to resize, and by default it will wipe the LVM2 signature on write. I think I saw an "advanced" option to turn off that destructive behavior, but I've never tested it.

You could also try cfdisk (curses fdisk). It might have a usable partition resize. It is easy enough to run pvresize manually, and there is a command to tell the kernel to reread the partition table. But I'd have to test to make sure it doesn't wipe the LVM signature like fdisk.

Tags:

Fedora

Lvm