#!/bin/zsh -e host=$1 die() { echo $@ exit -1 } fstab() { cat /etc/fstab | sed -e 's:#.*::' -e '/^$/d' } [ -n $host ] || die "usage $(basename $0) " echo testing /etc/xen/$host.cfg [ -f /etc/xen/$host.cfg ] || die "/etc/xen/$host.cfg not found" grep initrd.img- /etc/xen/vergil.cfg && die "change to short names" grep vmlinuz- /etc/xen/vergil.cfg && die "change to short names" [ -d /boot/xen-$host ] || die "/boot/xen-$host does not exist" [ -d /mnt/$host ] || die "mountpoint /mnt/$host does not exist" fstab | grep /mnt/$host >/dev/null || die "/mnt/$host not in /etc/fstab" DEV=$(fstab | grep /mnt/$host | awk '{print $1}') [ -e $DEV ] || die "$DEV does not exist" DEV=$(readlink -m $DEV) grep $DEV /proc/mounts && die "$DEV already mounted" [ "$2" = "reboot" ] || die "add reboot to reboot" echo shutting down ... xm shutdown -w $host echo done mount -o ro /mnt/$host cp -v /mnt/$host/boot/vmlinuz-* /boot/xen-$host/vmlinuz cp -v /mnt/$host/boot/initrd.img-* /boot/xen-$host/initrd.img umount /mnt/$host xm create $host.cfg -c