scripts-root/libvirt/switch_boot_device.sh

18 lines
441 B
Bash
Executable File

#!/bin/sh
# $1 = domain name
XML_DIR=/etc/libvirt/qemu
[[ -f "$XML_DIR/$1.xml" ]] && XML="$XML_DIR/$1.xml" || exit 1
DEV=`grep -o '<boot dev=[^>]*>' "$XML"|cut -d\' -f2`
SED_CMD=
case $DEV in
'hd')
SED_CMD="s/(<boot dev=')($DEV)('\/>)/\1cdrom\3/";;
'cdrom')
SED_CMD="s/(<boot dev=')($DEV)('\/>)/\1hd\3/";;
esac
virsh destroy $1
sed -E "$SED_CMD" $XML > /tmp/new_xml.xml
virsh define --file /tmp/new_xml.xml
virsh start $1
exit 0