My storage devices are mounted as follows:
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/md2 193G 35G 148G 19% /
/dev/md4 492G 73M 466G 1% /mnt
My KVM image is located at /kvm/vhdd/
which is on partition /dev/md2
ls -l /kvm/vhdd/wwe.img
-rw------- 1 libvirt-qemu kvm 163611607040 Mar 9 09:12 /kvm/vhdd/wwe.img
I need to move this image partition /dev/md4
, i.e. directory /mnt
.
How to do this? I can stop my virtual machine. But what I should do after stopping? Should I just make cp
? Or should I edit configs? I found
grep -R "/kvm" /etc/
/etc/libvirt/qemu.conf:# "/dev/ptmx", "/dev/kvm", "/dev/kqemu",
/etc/libvirt/storage/autostart/iso.xml: <path>/kvm/iso</path>
/etc/libvirt/storage/autostart/vhdd.xml: <path>/kvm/vhdd</path>
/etc/libvirt/storage/iso.xml: <path>/kvm/iso</path>
/etc/libvirt/storage/vhdd.xml: <path>/kvm/vhdd</path>
/etc/libvirt/qemu/wwe.xml: <emulator>/usr/bin/kvm-spice</emulator>
/etc/libvirt/qemu/wwe.xml: <source file='/kvm/vhdd/wwe.img'/>
/etc/libvirt/qemu/autostart/wwe.xml: <emulator>/usr/bin/kvm-spice</emulator>
/etc/libvirt/qemu/autostart/wwe.xml: <source file='/kvm/vhdd/wwe.img'/>
/etc/default/libvirtd:# Start libvirtd to handle qemu/kvm:
/etc/default/qemu-kvm:# /run/hugepages/kvm
/etc/apparmor.d/libvirt/libvirt-68d2ecf6-4569-49cc-871f-042a42ad1c03.files: "/kvm/vhdd/wwe.img" rwk,
Should I replace this path /kvm/vhdd/
in my configs? Please help, I am afraid to crash service, thanks.
Best Answer
Backup Original VM:
Move VM image to partition /mnt/kvm:
mkdir /mnt/kvm
mv /kvm/vhdd/wwe.img /mnt/kvm/wwe.img
Edit XML file: vim /etc/libvirt/qemu/wwe.xml
virsh start wwe
Note: You can restore to original state using orignal files at any time, however below is an alternate way used for cloning & moving VM in KVM Infra.
KVM - Clone Guests from available Image:
1- create a base VM and install OS, shut down the base VM
2- dump its XML file to template.xml and copy its image to template.qcow2
3- in template.xml point the disk source file to template.qcow2
4- run virt-sysprep on template.qcow2. to reset the image, e.g. will remove SSH keys, create new MAC address, clean up log files, etc..
5- after this point you don't need the base VM anymore. Delete it if not in use.
6- Cloning new VMs from Template: template.xml and template.qcow2
KVM - Move Guest to Another Host:
1- After above steps transfer xml & image file to new Host KVM: