Migrace z Xenu na KVM: Porovnání verzí

Z Wiki UnArt Slavičín
Skočit na navigaciSkočit na vyhledávání
Řádek 22: Řádek 22:
First of all, setup and start the [[DRBD]] devices, which will replicate your VM disks from the XEN to the KVM physical host machines.
First of all, setup and start the [[DRBD]] devices, which will replicate your VM disks from the XEN to the KVM physical host machines.


Then, you must customize the guests
Then, you must customize the XEN VM guests the following way:
 
===/etc/inittab in all VM guest===
You must comment out the following line, which is created by xen-create-image and directs console to the hvc0, which does not work in KVM:
#1:2345:respawn:/sbin/getty 38400 hvc0
 
Instead, place the normal tty1 console definition there:
1:2345:respawn:/sbin/getty 38400 tty1
 
Now, the console will not work in XEN. For enabling XEN console, you can place another line:
co:23:respawn:/sbin/getty -L hvc0 9600 vt102
 
Or you can redirect the hvc0 console to the tty1 in the host definition file by placing addition line
 
extra = "console=hvc0 xencons=tty"
 
===Modify host definition files===
You must rename your disks to sda/sdb/sdc...
 
By default, xen-create-
 
This is necessary for the next step.


=Klímova crazy migrace z KVM na XEN=
=Klímova crazy migrace z KVM na XEN=

Verze z 5. 10. 2011, 02:56

Migration of VMs between Xen and KVM - the simple way

I am writing this in English because I spent one whole day by googling and I found no simple howto's. So I spent another day by frustrating experiments with no results, only to find very simple way which made me happy.

What we want to achieve

Migration of VMs between two Xen and KVM machines.

The migration does not have to be completely online, but it must be quick and easy.

The Xen is Debian 5 Lenny, KVM is Ubuntu 10.04 (~Debian Squeeze).

The migration is possible because XEN is great and flexible system, allowing to customize all VMs in a way that they can be booted in KVM without any changes.

But I do not guarantee that this will work in XEN 4 (Debian Squeeze), because I can't try it currently.

Why I need this

Because:

How to do it

First of all, setup and start the DRBD devices, which will replicate your VM disks from the XEN to the KVM physical host machines.

Then, you must customize the XEN VM guests the following way:

/etc/inittab in all VM guest

You must comment out the following line, which is created by xen-create-image and directs console to the hvc0, which does not work in KVM:

#1:2345:respawn:/sbin/getty 38400 hvc0

Instead, place the normal tty1 console definition there:

1:2345:respawn:/sbin/getty 38400 tty1

Now, the console will not work in XEN. For enabling XEN console, you can place another line:

co:23:respawn:/sbin/getty -L hvc0 9600 vt102 

Or you can redirect the hvc0 console to the tty1 in the host definition file by placing addition line

extra = "console=hvc0 xencons=tty"

Modify host definition files

You must rename your disks to sda/sdb/sdc...

By default, xen-create-

This is necessary for the next step.

Klímova crazy migrace z KVM na XEN

  • Pomocí příkazu scp si překopírujeme obraz odpojeného virtuálu ze serveru s Xenem do server s KVM (pokud vám neběží jako nám na stejné mašině).
scp root@kraken.slfree.czf:/store/xen/domains/vpn/disk.img /store/disk.img
  • Nyní si na vytvoříme na KVM nový virtuál, kterému přiřadíme nový prázdný VIRTIO disk o velikosti malinko větší než je velikost zkopírovaného obrazu (+ ještě něco pro swap). Dále mu pak přidáme IDE disk, což bude samotný zkopírovaný obraz. Nakonec je ještě potřeba tomuto virtuálu nastavit bootování z CD-ROM, kterému jako obraz dáme některou LiveCD distribuci (já použil Ubuntu 10.10). Je vhodné si nastavit síť pro přístup do Internetu.
  • Po nabootování virtuálu do LiveCD spustíme terminál a přihlasíme se jako root (v Ubuntu otevřít gnome-terminal a napsat sudo -s).
  • Pomocí programů gparted nebo fdisk na VIRTIO disku vytvoříme novou tabulku oddílu a poté vytvoříme 2 oddíly - jeden malý pro boot (já dal 236MB ext2, nezapomenout nastavit příznak pro bootování!) a druhý nezformátovaný pro LVM.
  • Doinstalujeme lvm, vytvoříme výchozí VG a LV pro systém a swap.
apt-get install lvm2
pvcreate /dev/vda2
vgcreate rootg /dev/vda2
lvcreate -L velikost pro root -n root rootvg
lvcreate -L velikost pro swap -n swap rootvg
  • Vytvoříme swap.
mkswap -f /dev/mapper/rootvg-swap
  • Překopírujeme obraz původní virtuálu:
dd if=/dev/sda of=/dev/mapper/rootvg-root
  • Zvětšíme souborový systém do konce oddílu:
resize2fs /dev/mapper/rootvg-root
  • Připojíme si oddíly a do systému se chrootnume:
mount /dev/mapper/rootvg-root /mnt
mount /dev/vda1 /mnt/boot
mount -t proc none /mnt/proc
mount -t sysfs none /mnt/sys
mount -o bind /dev /mnt/dev
chroot /mnt /bin/bash
  • Doinstalujeme lvm, jádro a grub2.
apt-get install lvm2 linux-image-2.6.26-2-amd64 grub2
  • Pouze pro Debian Lenny: Právě tady nastává u lennyho problém. Možná se vám stalo, že se vám jádro nepodařilo zkonfigurovat. Na vině je bug v dmsetupu. Opravíme ho následujícím způsobem:
rm /dev/mapper/rootvg-root
cp -R /dev/dm-0 /dev/mapper/rootvg-root