首页 > 代码库 > 笔记7(虚拟机管理脚本)

笔记7(虚拟机管理脚本)

#!bin/bash
case "$1" in
start)
echo start $2 ...
virsh start $2 &> /dev/null
;;
poweroff)
echo poweroff $2 ...
virsh destroy $2 &> /dev/null
;;
reboot)
echo reboot $2 ...
virsh destroy $2 &> /dev/null
virsh start $2 &> /dev/null
;;
view)
echo view $2 ...
virt-viewer $2 &> /dev/null
;;
reset)
echo reset $2 ...
virsh destroy $2 &> /dev/null
virsh undefine $2 &> /dev/null
qemu-img create -f qcow2 -b /var/lib/libvirt/images/vm1.qcow2 /var/lib/libvirt/images/$2.qcow2
virt-install \
--name $2 \
--ram 1000 \
--disk /var/lib/libvirt/images/$2.qcow2 \
--import &> /dev/null &
echo created $2 successful !!!
esac

笔记7(虚拟机管理脚本)