To resize a virtual drive: Difference between revisions

From DISI
Jump to navigation Jump to search
(Created page with "Resizing a virtual drive (machine must be off): man virt-resize 0) Be extra safe and make a copy of the disk cp alpha-root alpha-root~preresize 1) Examine virtual drive's st...")
 
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Resizing a virtual drive (machine must be off):
Resizing a virtual drive (machine must be off):
0) Read man page
  man virt-resize
  man virt-resize
0) Be extra safe and make a copy of the disk
1) Shut Machine down
cp alpha-root alpha-root~preresize
    virsh shutdown myvm
1) Examine virtual drive's structure
2) Be extra safe and make a copy of the disk (space permitting)
  virt-filesystems --long -h --all -a alpha-root~preresize
    cp myvm-disk1 myvm-disk1~preresize
2) Create new drive (this uses the QCOW2 format. Multiple options available)
3) Examine virtual drive's structure
  qemu-img create -f qcow2 -o preallocation=metadata alpha-root~postresize 15G
  virt-filesystems --long -h --all -a myvm-disk1~preresize
3) Use vm resize command to populate new disk with expanded partitions (and also expand LVM if applicable)
4) Create new drive (this uses the QCOW2 format. Multiple options available)
  virt-resize --expand /dev/sda2 --lv-expand /dev/vg_alpha/root_lv alpha-root~preresize alpha-root~postresize
  qemu-img create -f qcow2 -o preallocation=metadata myvm-disk1~postresize 15G
4) To expand more than 1 LVM partition, repeat the process
5) Use vm resize command to populate new disk with expanded partitions (and also expand LVM if applicable)
  qemu-img create -f qcow2 -o preallocation=metadata alpha-root~postresize2 25G
  virt-resize --expand /dev/sda2 --lv-expand /dev/vg_myvm/root_lv myvm-disk1~preresize myvm-disk1~postresize
  virt-resize --expand /dev/sda2 --lv-expand /dev/vg_alpha/var_lv alpha-root~postresize alpha-root~postresize2
6) To expand more than 1 LVM partition, repeat the process
5) Swap file names around
  qemu-img create -f qcow2 -o preallocation=metadata myvm-disk1~postresize2 25G
  mv alpha-root alpha-root~original
  virt-resize --expand /dev/sda2 --lv-expand /dev/vg_myvm/var_lv myvm-disk1~postresize myvm-disk1~postresize2
  mv alpha-root~postresize2 alpha-root
7) Swap file names around
6) Start virtual machine
  mv myvm-disk1 myvm-disk1~original
  virsh start alpha
  mv myvm-disk1~postresize2 myvm-disk1
7) Cross fingers
8) Start virtual machine
  virsh start myvm
9) Cross fingers
There may be a permissions problem that causes the following error message upon starting the resized VM


[root@tet qemu]# virsh start tau
error: Failed to start domain tau
error: internal error Process exited while reading console log output: 2016-10-05T16:12:09.032816Z qemu-kvm: -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/tau.monitor,server,nowait: socket bind failed: Permission denied
2016-10-05T16:12:09.033101Z qemu-kvm: -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/tau.monitor,server,nowait: chardev: opening backend "socket" failed
To address this, change /var/lib/libvirt/qemu to be owned by qemu and under qemu group.
10) If all is OK, clear out old and temporary disks
rm myvm-disk1~postresize
rm myvm-disk1~original
===Alternative Resize method===
This method is for resizing a VM's image file directly.  It only works on certain image files.  <br />
1) Shutdown the vm
virsh shutdown <vm-name>
2) Find the VM's image file on the hypervisor (Typically somewhere under /var/lib/libvirt/images)
3) Apply an image resize:
qemu-img resize <vm-disk-image> <+/- amount of HDD space to add/subtract>
4) Start VM and re-partition once it is on.
[[Category:Sysadmin]]
[[Category:Sysadmin]]

Latest revision as of 18:49, 5 October 2016

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 There may be a permissions problem that causes the following error message upon starting the resized VM

[root@tet qemu]# virsh start tau
error: Failed to start domain tau
error: internal error Process exited while reading console log output: 2016-10-05T16:12:09.032816Z qemu-kvm: -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/tau.monitor,server,nowait: socket bind failed: Permission denied
2016-10-05T16:12:09.033101Z qemu-kvm: -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/tau.monitor,server,nowait: chardev: opening backend "socket" failed

To address this, change /var/lib/libvirt/qemu to be owned by qemu and under qemu group.

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

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

Alternative Resize method

This method is for resizing a VM's image file directly. It only works on certain image files.
1) Shutdown the vm

virsh shutdown <vm-name>

2) Find the VM's image file on the hypervisor (Typically somewhere under /var/lib/libvirt/images)

3) Apply an image resize:

qemu-img resize <vm-disk-image> <+/- amount of HDD space to add/subtract>

4) Start VM and re-partition once it is on.