To resize a virtual drive

From DISI
Revision as of 14:03, 23 May 2014 by Frodo (talk | contribs)
Jump to navigation Jump to search

Resizing a virtual drive (machine must be off): 0) Read man page

man virt-resize

1) Shut Machine down

   virsh shutdown myvm

2) Be extra safe and make a copy of the disk (space permitting)

   cp myvm-disk1 myvm-disk1~preresize

3) Examine virtual drive's structure

virt-filesystems --long -h --all -a myvm-disk1~preresize

4) Create new drive (this uses the QCOW2 format. Multiple options available)

qemu-img create -f qcow2 -o preallocation=metadata myvm-disk1~postresize 15G

5) Use vm resize command to populate new disk with expanded partitions (and also expand LVM if applicable)

virt-resize --expand /dev/sda2 --lv-expand /dev/vg_myvm/root_lv myvm-disk1~preresize myvm-disk1~postresize

6) To expand more than 1 LVM partition, repeat the process

qemu-img create -f qcow2 -o preallocation=metadata myvm-disk1~postresize2 25G
virt-resize --expand /dev/sda2 --lv-expand /dev/vg_myvm/var_lv myvm-disk1~postresize myvm-disk1~postresize2

7) Swap file names around

mv myvm-disk1 myvm-disk1~original
mv myvm-disk1~postresize2 myvm-disk1

8) Start virtual machine

virsh start myvm

9) Cross fingers

10) If all is OK, clear out old and temporary disks

rm myvm-disk1~postresize
rm myvm-disk1~original