Sysadmin/Migrate virtual machine: Difference between revisions
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
* First, create the logical volume and attach it to the running VM: | * First, create the logical volume and attach it to the running VM: | ||
treehouse# scp | treehouse# scp VMNAME:/boot/{vmlinuz,initrd}-2.6.31-22-server /srv/vm/kernel/ubuntu/ | ||
treehouse# virsh vol-create-as treehouse | treehouse# virsh vol-create-as treehouse VMNAME-root 10G | ||
treehouse# virsh attach-disk | treehouse# virsh attach-disk VMNAME /dev/treehouse/VMNAME-root vdc | ||
treehouse# virsh console | treehouse# virsh console VMNAME | ||
* From within the VM, format the new volume and move things over | * From within the VM, format the new volume and move things over | ||
VMNAME# mkfs.ext4 -L VMNAME-root -O flex_bg,extent,uninit_bg,sparse_super /dev/vdc | |||
VMNAME# tune2fs -c -1 -i 0 /dev/vdc | |||
VMNAME# mount /dev/vdc /mnt | |||
VMNAME# rsync -PHAXphax --numeric-ids --delete / /mnt/ | |||
VMNAME# vim /mnt/etc/fstab | |||
VMNAME# umount /mnt | |||
VMNAME# ^D | |||
* Then edit the VM configuration to make it boot without GRUB, using externally provided kernel and initrd: | * Then edit the VM configuration to make it boot without GRUB, using externally provided kernel and initrd: | ||
treehouse# virsh edit | treehouse# virsh edit VMNAME | ||
<os> | <os> | ||
| Line 26: | Line 26: | ||
<kernel>/srv/vm/kernel/ubuntu/vmlinuz-2.6.31-22-server</kernel> | <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> | <initrd>/srv/vm/kernel/ubuntu/initrd.img-2.6.31-22-server</initrd> | ||
<cmdline>console=tty0 console=ttyS0,115200n8 vga=normal root=LABEL= | <cmdline>console=tty0 console=ttyS0,115200n8 vga=normal root=LABEL=VMNAME-root ro</cmdline> | ||
<boot dev='hd'/> | <boot dev='hd'/> | ||
</os> | </os> | ||
| Line 33: | Line 33: | ||
... | ... | ||
<disk type='block' device='disk'> | <disk type='block' device='disk'> | ||
<source dev='/dev/treehouse/ | <source dev='/dev/treehouse/VMNAME-root'/> | ||
<target dev='vda' bus='virtio'/> | <target dev='vda' bus='virtio'/> | ||
</disk> | </disk> | ||
| Line 41: | Line 41: | ||
* Reboot | * Reboot | ||
#treehouse virsh destroy | #treehouse virsh destroy VMNAME | ||
#treehouse virsh start | #treehouse virsh start VMNAME --console | ||
=== How to migrate a file-based guest to LVM (offline method) === | === How to migrate a file-based guest to LVM (offline method) === | ||