Difference between revisions of "Sysadmin/Migrate virtual machine"
< Sysadmin
Jump to navigation
Jump to search
m (moved Infrastructure Team/Migrate virtual machine to Sysadmin/Migrate virtual machine: restructure) |
|||
Line 1: | Line 1: | ||
− | == How to migrate a | + | == How to migrate a file-based guest to LVM == |
+ | |||
+ | treehouse# scp lightwave:/boot/{vmlinuz,initrd}-2.6.31-22-server /srv/vm/kernel/ubuntu/ | ||
+ | treehouse# virsh vol-create-as treehouse lightwave 10G | ||
+ | treehouse# virsh attach-disk lightwave /dev/treehouse/lightwave-root vdc | ||
+ | treehouse# virsh console lightwave | ||
+ | |||
+ | lightwave# mkfs.ext4 -L lightwave-root -O flex_bg,extent,uninit_bg,sparse_super /dev/vdc | ||
+ | lightwave# tune2fs -c -1 -i 0 /dev/vdc | ||
+ | lightwave# mount /dev/vdc /mnt | ||
+ | lightwave# rsync -PHAXphax --numeric-ids --delete / /mnt/ | ||
+ | lightwave# vim /mnt/etc/fstab | ||
+ | lightwafe# umount /mnt | ||
+ | lightwave# ^D | ||
+ | |||
+ | treehouse# virsh edit lightwave | ||
+ | |||
+ | <os> | ||
+ | <type arch='x86_64' machine='pc-0.11'>hvm</type> | ||
+ | <kernel>/srv/vm/kernel/ubuntu/vmlinuz-2.6.31-22-server</kernel> | ||
+ | <initrd>/srv/vm/kernel/ubuntu/initrd.img-2.6.31-22-server</initrd> | ||
+ | <cmdline>console=tty0 console=ttyS0,115200n8 vga=normal root=LABEL=lightwave-root ro</cmdline> | ||
+ | <boot dev='hd'/> | ||
+ | </os> | ||
+ | |||
+ | <devices> | ||
+ | ... | ||
+ | <disk type='block' device='disk'> | ||
+ | <source dev='/dev/treehouse/lightwave-root'/> | ||
+ | <target dev='vda' bus='virtio'/> | ||
+ | </disk> | ||
+ | ... | ||
+ | </devices> | ||
+ | |||
+ | #treehouse virsh destroy lightwave | ||
+ | #treehouse virsh start lightwave --console | ||
+ | |||
+ | |||
+ | == How to migrate an LVM-based guest to another host == | ||
(untested procedure) | (untested procedure) |
Revision as of 00:07, 5 July 2010
How to migrate a file-based guest to LVM
treehouse# scp lightwave:/boot/{vmlinuz,initrd}-2.6.31-22-server /srv/vm/kernel/ubuntu/ treehouse# virsh vol-create-as treehouse lightwave 10G treehouse# virsh attach-disk lightwave /dev/treehouse/lightwave-root vdc treehouse# virsh console lightwave
lightwave# mkfs.ext4 -L lightwave-root -O flex_bg,extent,uninit_bg,sparse_super /dev/vdc lightwave# tune2fs -c -1 -i 0 /dev/vdc lightwave# mount /dev/vdc /mnt lightwave# rsync -PHAXphax --numeric-ids --delete / /mnt/ lightwave# vim /mnt/etc/fstab lightwafe# umount /mnt lightwave# ^D
treehouse# virsh edit lightwave
<os> <type arch='x86_64' machine='pc-0.11'>hvm</type> <kernel>/srv/vm/kernel/ubuntu/vmlinuz-2.6.31-22-server</kernel> <initrd>/srv/vm/kernel/ubuntu/initrd.img-2.6.31-22-server</initrd> <cmdline>console=tty0 console=ttyS0,115200n8 vga=normal root=LABEL=lightwave-root ro</cmdline> <boot dev='hd'/> </os>
<devices> ... <disk type='block' device='disk'> <source dev='/dev/treehouse/lightwave-root'/> <target dev='vda' bus='virtio'/> </disk> ... </devices>
#treehouse virsh destroy lightwave #treehouse virsh start lightwave --console
How to migrate an LVM-based guest to another host
(untested procedure)
First, shutdown the VM, then do:
mount /dev/treehouse/beamrider-root /mnt ssh housetree mount /dev/housetree/beamrider-root /mnt rsync -PHAXphax --delete --numeric-ids /mnt/ housetree:/mnt/ rsync -a /etc/libvirt/qemu/beamrider.xml housetree:/etc/libvirt/qemu/ umount /mnt ssh housetree umount /mnt
Then log to $OTHERHOST and create the domain in virsh.
Downtime can be reduced to just a few minutes by doing a first rsync iteration from within the VM while it's still running.
Make sure you pass all the fancy switches to rsync or you'll loose information on the copy.