首页 > 代码库 > Linux虚拟机脚本

Linux虚拟机脚本

#!/bin/bash
case "$1" in
        start)
        virsh start hello                       / 开启虚拟机holle
        ;;
        poweroff)
        virsh destroy hello                    / 关闭虚拟机holle
        ;;
        reboot)
        virsh destroy hello                    / 关闭虚拟机
        virsh start hello                       / 开启虚拟机
        virt-viewer hello                       / 显示虚拟机
        ;;
        teset)
        echo poweroff hello
        virsh destroy hello &> /dev/null        / 关闭快照
        echo del hello.xml ...
virsh undefine hello &> /dev/null       / 删除快照
        echo create disk ...
        qemu-img create -f qcow2 -b /var/lib/libvirt/images/vm1.qcow2 /var/lib/libvirt/images/hello.qcow2                       / 建立快照
        echo create hello vm ...
        virt-install \                          / 获取权限
        --name hello \                          / 确定名字
        --ram 2000 \                            / 确定内存大小
        --disk /var/lib/libvirt/images/hello.qcow2 \   / 指定硬盘位置
        --import &> /dev/null &                   /  启动图形界面
        echo created hello successful !!!
        ;;
        view)
        virt-viewer hello                       / 显示虚拟机
esac

Linux虚拟机脚本