Migration Xen
Sauter à la navigation
Sauter à la recherche
Introduction
Here is a howto to migrate domU from hosts to hosts under Ubuntu. There is multiple solutions.
Migration by rsync is recommended.
Migration by dd
On each host
- Create a logical volume to host the image
lvcreate -L5G -n migrate vg_hostname
- Format them in ext3
mkfs.ext3 /dev/vg_hostname
/migrate
- Mount them in the filesystem
mkdir /mnt/migrate
mount /dev/vg_hostname
/migrate /mnt/migrate/
On source host
- Create a snapshot of the running domU root disk
source
# lvcreate -L4G -s -nservice
-disk-snap /dev/vg_hostname
/service
-disk
- Stop the service
source
# xm shutdownservice
- Do the byte to byte copy
source
# dd if=/dev/vg_hostname
/service
-disk-snap conv=noerror,sync bs=64k | dd of=/mnt/migrate/service
.dd bs=64k
- Transfer the file by scp
source
# scp /mnt/migrate/service
.dddestination
:/mnt/migrate/
- Remove immediatly the snapshot
source
# lvremove /dev/vg_hostname
/service
-disk-snap
On destination host
- Create the new domU root disk
destination
# lvcreate -L4G -nservice
-disk vg_hostname
- Create the new dom swap disk
destination
# lvcreate -L256M -nservice
-swap vg_hostname
- Initiate the swap disk
destination
# mkswap /dev/vg_hostname
/service
-swap
- Do the byte to byte copy (filesystem is contained in the dd image)
destination
# dd if=/mnt/migrate/service
.dd conv=noerror,sync bs=64k | dd of=/dev/vg_hostname
/service
-disk bs=64k
- Adapt and start the domU
destination
# xm create /etc/xen/service
.cfg
Migration by rsync
On destination host
- Create the service root volume on destination and format it.
destination
# lvcreate -L4G -nservice
-disk vg_hostname
destination
# mkfs.ext3 /dev/vg_hostname
/service
-disk
- Create the service swap volume on destination and format it.
destination
# lvcreate -L256M -nservice
-swap vg_hostname
destination
# mkswap /dev/vg_hostname
/service
-swap
- Mount service root volume destination under, by e.g., /mnt/migrate
destination
# mount /dev/vg_hostname
/service
-disk /mnt/migrate/
On source host
- Stop the domU on source.
source
# xm shutdownservice
- Mount domU volume under, by e.g., /mnt/migrate
source
# mount /dev/vg_hostname
/service
-disk /mnt/migrate/
- Do the copy :
source
# rsync --numeric-ids --verbose --archive --bwlimit=100000 --rsh ssh /mnt/migrate/destination
:/mnt/migrate
On destination host
- Adapt the .cfg of the service with new disk volume path and start the domain.
destination
# xm create /etc/xen/service
.cfg
Useful commands (exemple of maintenance)
On dest
lvcreate -L2G -n dhcp-disk rootvg lvcreate -L512M -n dhcp-swap rootvg lvcreate -L2G -n dns-disk rootvg lvcreate -L512M -n dns-swap rootvg lvcreate -L4G -n ldap-master-disk rootvg lvcreate -L512M -n ldap-master-swap rootvg lvcreate -L4G -n mail-disk rootvg lvcreate -L512M -n mail-swap rootvg lvcreate -L4G -n puppet-disk rootvg lvcreate -L1G -n puppet-swap rootvg lvcreate -L4G -n puppet-master-disk rootvg lvcreate -L1G -n puppet-master-swap rootvg for i in $(cat ~g5kadmin/vm_to_migrate); do echo "--> mkfs for vm $i..."; mkfs.ext3 /dev/rootvg/$i-disk; done for i in $(cat ~g5kadmin/vm_to_migrate); do echo "--> mkswap for vm $i..."; mkswap /dev/rootvg/$i-swap; done for i in $(cat ~g5kadmin/vm_to_migrate); do echo "--> Update kernel and ramdisk xen parameters for vm $i..."; sed -i "s/^\(kernel.*= \).*$/\1\'\/boot\/vmlinuz-`uname -r`\'/g" /etc/xen/$i.cfg; done for i in $(cat ~g5kadmin/vm_to_migrate); do echo "--> Update kernel and ramdisk xen parameters for vm $i..."; sed -i "s/^\(ramdisk.*= \).*$/\1\'\/boot\/initrd.img-`uname -r`\'/g" /etc/xen/$i.cfg; done for i in $(cat ~g5kadmin/vm_to_migrate); do echo "--> Update kernel bridges for vm $i..."; sed -i "s/bridge=eth1/bridge=xenbr0/g" /etc/xen/$i.cfg; done for i in $(cat ~g5kadmin/vm_to_migrate); do echo "--> Update kernel bridges for vm $i..."; sed -i "s/bridge=eth0/bridge=xenbr1/g" /etc/xen/$i.cfg; done for i in $(cat ~g5kadmin/vm_to_migrate); do echo "--> Update lvg name for vm $i..."; sed -i "s/paraquad-srv/rootvg/g" /etc/xen/$i.cfg; done for i in $(cat ~g5kadmin/vm_to_migrate); do mkdir /tmp/$i; mount /dev/rootvg/$i-disk /tmp/$i; done
On source
for i in $(cat ~g5kadmin/vm_to_migrate); do echo "--> migrate xen $i.cfg file to parapluie-srv..."; scp /etc/xen/$i.cfg parapluie-srv:/etc/xen/; done for i in $(cat ~g5kadmin/vm_to_migrate); do xm shutdown $i; done for i in $(cat ~g5kadmin/vm_to_migrate); do mkdir /tmp/$i; mount /dev/paraquad-srv/$i-disk /tmp/$i; done for i in $(cat ~g5kadmin/vm_to_migrate); do echo "--> migrate content of vms to parapluie-srv..."; rsync --numeric-ids --archive --rsh ssh /tmp/$i/ 131.254.203.41:/tmp/$i; done
other commands...
- on source :
for i in $(cat vm2migrate); do VM_NAME=$i; DISK_SIZE=$(lvdisplay --columns | grep "$VM_NAME-disk" | awk '{print $4;}'); SWAP_SIZE=$(lvdisplay --columns | grep "$VM_NAME-swap" | awk '{print $4;}'); echo "$VM_NAME;$DISK_SIZE;$SWAP_SIZE"; done > vm2migrate2 for i in $(cat vm2migrate); do VM_NAME=$(echo $i | cut -d";" -f1); scp /etc/xen/$VM_NAME.cfg adminfront:/etc/xen; done
- on target :
for i in $(cat vm2migrate); do VM_NAME=$(echo $i | cut -d";" -f1); DISK_SIZE=$(echo $i | cut -d";" -f2); SWAP_SIZE=$(echo $i | cut -d";" -f3); echo "--> create $VM_NAME-disk"; lvcreate -n $VM_NAME-disk -L$DISK_SIZE rootvg; echo "--> create $VM_NAME-swap"; lvcreate -n $VM_NAME-swap -L$SWAP_SIZE rootvg; done for i in $(cat vm2migrate); do VM_NAME=$(echo $i | cut -d";" -f1); echo "--> $VM_NAME"; mkfs.ext3 /dev/rootvg/$VM_NAME-disk; mkswap /dev/rootvg/$VM_NAME-swap; done for i in $(cat vm2migrate); do VM_NAME=$(echo $i | cut -d";" -f1); echo "--> $VM_NAME"; mkdir /tmp/vms/$VM_NAME-disk; mount /dev/rootvg/$VM_NAME-disk /tmp/vms/$VM_NAME-disk; done
... rsync...