RH401: preparing your satellite server virtual machine

If you've forgotten that Virtual Machine Manager creates a 'raw' disk by default (which does't support snapshots), you probably want to convert it to a qcow2 image.

backup your virtual machine configuration

[root@home ~]# virsh dumpxml satellite > satellite-backup.xml

or

[root@home ~]# cd /etc/libvirt/qemu/
[root@home qemu]# ls
networks  satellite.xml
[root@home qemu]# cp satellite.xml ~/satellite-backup.xml

create a snapshot xml file

[root@home ~]# cat satellite.xml 

    satellite-05072012
    test snapshot for satellite server


make sure that your vm is offline

[root@home ~]# virsh list --all
 Id Name                 State
----------------------------------
  - satellite            shut off

this should fail

[root@home ~]# virsh snapshot-create satellite satellite.xml
error: Requested operation is not valid: Disk 
           '/var/lib/libvirt/images/satellite.img' does not support snapshotting

[root@home ~]# cd /var/lib/libvirt/images
[root@home images]# ls
lost+found  satellite-1.img  satellite-2.img  satellite-3.img  satellite.img

[root@home images]# qemu-img info satellite.img
image: satellite.img
file format: raw
virtual size: 20G (21474836480 bytes)
disk size: 20G

raw disks doesn't support snapshots. qcow2 does. It uses a sparse file. I don't know how the performance is (since the underlying OS has to keep allocating space on demand) but here's how its done:

[root@home images]# qemu-img convert -f raw -O qcow2 -o preallocation=metadata 
                       satellite.img satellite.qcow2

[root@home images]# qemu-img info satellite.qcow2
image: satellite.qcow2
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 13G
cluster_size: 65536

do this for all the disks on your vm
edit the vm's config to make use of the new disks

[root@home ~]# virsh edit satellite
(replace the old raw disks with the new qcow2 disks)
...
   <driver name='qemu' type='qcow2'/>
   <source file='/var/lib/libvirt/images/satellite.qcow2'/>
...

save and exit. create a snapshot

[root@home ~]# export VIRSH_DEBUG=0
[root@home ~]# virsh snapshot-create-as satellite \
                      satellite-20120509-debug 'satellite server base install'
snapshot-create-as: found option : satellite
snapshot-create-as:  trying as domain NAME
Domain snapshot satellite-20120509-debug created

delete whatever is not required, if you are short of disk space like me

[root@home ~]# unset VIRSH_DEBUG
[root@home ~]# virsh snapshot-list satellite
 Name                 Creation Time             State
------------------------------------------------------------
 1336569081           2012-05-09 21:11:21 +0800 shutoff
 satellite-20120509   2012-05-09 21:20:20 +0800 shutoff
 satellite-20120509-debug 2012-05-09 21:26:45 +0800 shutoff

[root@home ~]# virsh snapshot-delete satellite 1336569081
[root@home ~]# virsh snapshot-delete satellite satellite-20120509

[root@home ~]# virsh start satellite

once you have verified that everything is working as expected, you may relocate or remove the raw disks.

No comments:

Post a Comment