4

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ů
8

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.

  • @OldřichŠvéda that's a command inside parted ... you'd run parted /dev/xda first, then execute that. I'll clarify – derobert Jan 12 '17 at 22:26
  • Are the reboots really necessary to pick up the partition table changes? AFAIK partprobe is enough. And for step 4b, my man for resizepart says it takes 3 args and that it "doesn't manipulate partitions on hard drive". So, that seems redundant with next step (reboot) and apparently, a step is missing to actually resize the partition on disk. – xhienne Jan 12 '17 at 23:31
  • @xhienne partprobe won't work on disks that are in use. Unfortunately. You must have a different version of parted; that's not what's in Debian 8.6, though (or stretch, for that matter). See, e.g., gnu.org/software/parted/manual/html_node/… – derobert Jan 12 '17 at 23:33
  • Ooops, I missed the fact that resizepart was a parted subcommand (not mentioned in my parted man, good to know) and I was referring to the resizepart shell command. Thanks for your answer – xhienne Jan 13 '17 at 0:04
0

I'm currently running Devuan Jessie 1.0 (Stable) in a VM on ProxMox. The partition I needed to extend was /var/lib mounted on /dev/sda5 for elasticsearch. Since this wasn't OS critical, I could do it with the VM up. I just ensured that there was nothing using the partition with lsof. To accomplish this, I did the following:

  1. Check the partition to make sure it's not busy:

    lsof /dev/sda5
    
    • If you get any output from this command, you must determine what is using the partition in question and terminate the process. Here is a reference. LSOF Comand Examples
  2. Unmount the partition:

    umount /dev/sda5
    
  3. Run parted

    parted
    
  4. Inside parted:

    resizepart 5 -1s
    
  5. Quit parted:

    quit
    
  6. Check the disk:

    e2fsck -f /dev/sda5
    
  7. Extend the disk so the OS sees it:

    resize2fs /dev/sda5
    
  8. Remount:

    mount -a. 
    
  9. Check to make sure the OS sees the newly extended drive:

    df -h /dev/sda5
    

Now everything should be good to go. On a side note, lvextend threw an error, so for me, the resize2fs route was the simplest way to go. HTH.

  • The lsof might be redundant, since the umount will fail if anything is using the filesystem  — but better safe than sorry. – G-Man Nov 17 '17 at 16:23
  • I'm a Marine, so when I write a walk-through, I assume the reader has no prior knowledge. For a reader with no prior knowledge, an error when unmounting could throw them off track and would be very frustrating. I'm just trying to enable the masses. – Linux O'Beardly Nov 18 '17 at 17:27
  • Well, I said “might”. My point is you could just leave out the lsof and add a note to the umount that, if it fails, the user should look at the error message and check whether the filesystem is in use. For that matter, you say “I assume the reader has no prior knowledge.”, but you don’t explain what to do with the lsof results. I had a customer once who damaged a database by doing Step A and then Step B without realizing that he had to inspect the output of Step A to verify that it was safe to proceed with Step B. … … … … … … … … … … … … … … … P.S. Thank you for your service. – G-Man Nov 19 '17 at 21:27
  • You're welcome. And yes, you make a good point. – Linux O'Beardly Nov 20 '17 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.