X-Git-Url: http://pere.pagekite.me/gitweb/homepage.git/blobdiff_plain/71aeea56d24c27fedf97c11797baadbf0523f1a3..73aaf2c83ac56f22ee70aa8fc65e6c17e0a8162a:/blog/archive/2010/11/index.html diff --git a/blog/archive/2010/11/index.html b/blog/archive/2010/11/index.html index eabd92132f..1ed4b47fe3 100644 --- a/blog/archive/2010/11/index.html +++ b/blog/archive/2010/11/index.html @@ -695,6 +695,100 @@ Installed using apt-get, removed with aptitude + Tags: debian, debian edu, english. + + + +
+ +
+
+ Migrating Xen virtual machines using LVM to KVM using disk images +
+
+ 2010-11-22 11:20 +
+ +
+ +

Most of the computers in use by the +Debian Edu/Skolelinux project +are virtual machines. And they have been Xen machines running on a +fairly old IBM eserver xseries 345 machine, and we wanted to migrate +them to KVM on a newer Dell PowerEdge 2950 host machine. This was a +bit harder that it could have been, because we set up the Xen virtual +machines to get the virtual partitions from LVM, which as far as I +know is not supported by KVM. So to migrate, we had to convert +several LVM logical volumes to partitions on a virtual disk file.

+ +

I found +a +nice recipe to do this, and wrote the following script to do the +migration. It uses qemu-img from the qemu package to make the disk +image, parted to partition it, losetup and kpartx to present the disk +image partions as devices, and dd to copy the data. I NFS mounted the +new servers storage area on the old server to do the migration.

+ +
+#!/bin/sh
+
+# Based on
+# http://searchnetworking.techtarget.com.au/articles/35011-Six-steps-for-migrating-Xen-virtual-machines-to-KVM
+
+set -e
+set -x
+
+if [ -z "$1" ] ; then
+    echo "Usage: $0 <hostname>"
+    exit 1
+else
+    host="$1"
+fi
+
+if [ ! -e /dev/vg_data/$host-disk ] ; then
+    echo "error: unable to find LVM volume for $host"
+    exit 1
+fi
+
+# Partitions need to be a bit bigger than the LVM LVs.  not sure why.
+disksize=$( lvs --units m | grep $host-disk | awk '{sum = sum + $4} END { print int(sum * 1.05) }')
+swapsize=$( lvs --units m | grep $host-swap | awk '{sum = sum + $4} END { print int(sum * 1.05) }')
+totalsize=$(( ( $disksize + $swapsize ) ))
+
+img=$host.img
+#dd if=/dev/zero of=$img bs=1M count=$(( $disksize + $swapsize ))
+qemu-img create $img ${totalsize}MMaking room on the Debian Edu/Sqeeze DVD
+
+parted $img mklabel msdos
+parted $img mkpart primary linux-swap 0 $disksize
+parted $img mkpart primary ext2 $disksize $totalsize
+parted $img set 1 boot on
+
+modprobe dm-mod
+losetup /dev/loop0 $img
+kpartx -a /dev/loop0
+
+dd if=/dev/vg_data/$host-disk of=/dev/mapper/loop0p1 bs=1M
+fsck.ext3 -f /dev/mapper/loop0p1 || true
+mkswap /dev/mapper/loop0p2
+
+kpartx -d /dev/loop0
+losetup -d /dev/loop0
+
+ +

The script is perhaps so simple that it is not copyrightable, but +if it is, it is licenced using GPL v2 or later at your discretion.

+ +

After doing this, I booted a Debian CD in rescue mode in KVM with +the new disk image attached, installed grub-pc and linux-image-686 and +set up grub to boot from the disk image. After this, the KVM machines +seem to work just fine.

+ +
+
+ + + Tags: debian, debian edu, english.
@@ -733,7 +827,7 @@ Installed using apt-get, removed with aptitude
  • October (9)
  • -
  • November (8)
  • +
  • November (9)
  • @@ -790,11 +884,11 @@ Installed using apt-get, removed with aptitude
  • bootsystem (10)
  • -
  • debian (40)
  • +
  • debian (41)
  • -
  • debian edu (48)
  • +
  • debian edu (49)
  • -
  • english (69)
  • +
  • english (70)
  • fiksgatami (1)