Debian – How to resize LVM disk in Debian 8.6 without losing data

debianfdiskresize2fs

I need to resize my first disk (/dev/xvda) from 40 GB to 80 GB. I'm using XEN virtualization, and the disk is resized in XenCenter, but I need to resize its partitions without losing any data. The virtual machine is running Debian 8.6.

Disk /dev/xvda: 80 GiB, 85 899 345 920 bajtů, 167 772 160 sektorů
Jednotky: sektorů po 1 * 512 = 512 bajtech
Velikost sektoru (logického/fyzického): 512 bajtů / 512 bajtů
Velikost I/O (minimální/optimální): 512 bajtů / 512 bajtů
Typ popisu disku: dos
Identifikátor disku: 0x5a0b8583

Device     Boot  Start      End  Sectors  Size Id Type
/dev/xvda1        2048   499711   497664  243M 83 Linux
/dev/xvda2      501758 83884031 83382274 39,8G  5 Extended
/dev/xvda5      501760 83884031 83382272 39,8G 8e Linux LVM

Disk /dev/xvdb: 64 GiB, 68 719 476 736 bajtů, 134 217 728 sektorů
Jednotky: sektorů po 1 * 512 = 512 bajtech
Velikost sektoru (logického/fyzického): 512 bajtů / 512 bajtů
Velikost I/O (minimální/optimální): 512 bajtů / 512 bajtů
Typ popisu disku: gpt
Identifikátor disku: 0596FDE3-F7B7-46C6-8CE1-03C0B0ADD20A

Device     Start       End   Sectors Size Type
/dev/xvdb1  2048 134217694 134215647  64G Linux filesystem

Disk /dev/mapper/xenhosting--vg-root: 38,1 GiB, 40 907 046 912 bajtů, 79 896 576 sektorů
Jednotky: sektorů po 1 * 512 = 512 bajtech
Velikost sektoru (logického/fyzického): 512 bajtů / 512 bajtů
Velikost I/O (minimální/optimální): 512 bajtů / 512 bajtů
Disk /dev/mapper/xenhosting--vg-swap_1: 1,7 GiB, 1 782 579 200 bajtů, 3 481 600 sektorů
Jednotky: sektorů po 1 * 512 = 512 bajtech
Velikost sektoru (logického/fyzického): 512 bajtů / 512 bajtů
Velikost I/O (minimální/optimální): 512 bajtů / 512 bajtů

Best Answer

This should be relatively easy, since you're using LVM:

  1. First, as always, take a backup.
  2. Resize the disk in Xen (you've already done this; despite this, please re-read step 1).
  3. Use parted to resize the extended partition (xvda2); run parted /dev/xvda, then at the parted prompt resizepart 2 -1s to resize it to end at the end of the disk (BTW: quit will get out of parted).
  4. Either (a) create another logical partition (xvda6) with the free space, then:

    1. reboot to pick up the partition table changes
    2. pvcreate /dev/xvda6
    3. vgextend xenhosting-vg /dev/xvda6

    or (b)

    1. extend xvda5 using resizepart 5 -1s
    2. reboot to pick up the partition table changes
    3. pvresize /dev/xvda5
  5. Finally, if you want to add that to your root filesystem, lvextend -r -l +100%FREE /dev/xenhosting-vg/root. The -r option to lvextend tells it to call resize2fs itself.

Another option you didn't consider:

Add another virtual disk. If you can do this in Xen w/o rebooting the guest, then you can do this entirely online (without any reboots). Partition the new disk xvdc (this will not requite a reboot, since its not in use), then proceed with pvcreate & vgextend using /dev/xvdc1.

Related Question