Friday, May 3, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 5833  / 2 Years ago, mon, july 11, 2022, 4:43:14

Original Question: How to resize root partition without live CD?



I have a virtual machine that I need to make bigger. I made the VM img larger and now I need to resize the partitions so I can use the extra space.



This is my current partition table and the goal is to combine /dev/vda1 and /dev/vda2.

vda1 is my current root partition

vda2 is an extended partition that contains vda5(swap)



Device Boot      Start         End      Blocks   Id  System
/dev/vda1 * 2048 18874367 9436160 83 Linux
/dev/vda2 18876414 20969471 1046529 5 Extended
/dev/vda5 18876416 20969471 1046528 82 Linux swap / Solaris


This would be simple with Gparted and a live CD, but I can only ssh to the server, or open it in virt-manager but it is still command line only. How can I possibly resize the root partition?



The VM is Ubuntu server 12.04.


More From » partitioning

 Answers
7

Here is what worked in the end:


Enlage the img (virtual disk image) file for the VM:



  1. Create raw disc file


    sudo qemu-img create -f raw addon.raw 10G


  2. Backup current img


    sudo mv domain.img domain.old.img


  3. Combine original and extra to create img file of new larger size.


    sudo cat domain.old.img addon.raw >> domain.img



Now we have a larger image but the VM still has old partition table.


Now the tricky part.


The next steps are done on the host machine with VM shutdown


Download iso file for gparted:


wget -c http://sourceforge.net/projects/gparted/files/gparted-live-stable/0.6.4-1/gparted-live-0.6.4-1.iso

Boot the iso with the virtual image as the harddrive in the virtual system


kvm -m 512 -hda domain.img -cdrom gparted-live-0.6.4-1.iso -boot d

We are basically launching a virtual system kvm that will boot from the cdrom -boot d and gparted is in the cdrom -cdrom gparted-live-0.6.4-1.iso and in this virtual system treat domain.img as the harddrive -hda domain.img and allocate 512mb memory for this virtual system-m 512.


Now gparted pops up with a nice GUI (there is probably a command line option as well) ready to repartition your virtual disk.


Now you can manipulate the partition table just like you were using a liveCD on a real machine.


Most of this information was taken from this blog post by Chris Walden.


Thanks guntbert for pointing me in the right direction (i.e. it is possible to boot a VM from a liveCD).


[#29846] Monday, July 11, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emuralm

Total Points: 290
Total Questions: 111
Total Answers: 117

Location: China
Member since Thu, Sep 1, 2022
2 Years ago
;