虚拟机管理命令
virsh list 显示当前开启的虚拟机
virsh list --all 显示所有虚拟机
virsh shutdown westos 正常关闭
virsh destroy wextos 强行断电
virsh start westos 开启westos
virt-viewr westos 显示出来
virsh undefine westos 删除调虚拟机的前端管理文件,删除虚拟机信息==/etc/libvirt/qemu/westos.xml==文件
rm -rf /var/lib/libvirt/image/vmname.qcow2 删掉虚拟机硬盘
virsh create vmname.xml 一次开机
virsh define vmname.xml 永久恢复
虚拟机快照
保护某盘,因为虚拟机的更改不可逆,
qemu-img create -f qcow2 -b /var/lib/libvirt/image/gernri.qcow2 /var/lib/libvirt/image/node.qcow2
su -sh node.qcow2 查看大小
第一步:执行 qemu-img create -f qcow2 -b /var/lib/libvirt/image/gernri.qcow2 /var/lib/libvirt/image/node.qcow2
在/var/lib/libvirt/images目录下会得到node.qow2文件
然后打开Virtual Machine Manager
[root@foundation74 images]# virt-manager
点击
然后选择 Import existing disk image
然后找到 /var/lib/libvirt/images目录下的node.qcow2
接下来几步都是Forward直到以下画面名字自己起,选中 Customize configuration before install点击Finsh
然后选择VritIO Disk 1中的Advanced option并选中Virto
接下来NIC:49:03:4d 下的Device model 选中virtio,apply之后点击Begin installation
_完成
用脚本装虚拟机
换行 空格+\
在 /usr/bin 下创建creat_vm.sh
1 #!/bin/bash
2 virt-install \
3 --name $1 \
4 --cdrom /home/kiosk/Desktop/rhel-server-7.3-x86_64-dvd.iso \
5 --vcpu 1 \
6 --memory 1024 \
7 --disk /var/lib/libvirt/images/$1.qcow2,size=8,bus=virtio \
8 --network bridge=br0,model=virtio &> /dev/null &
接着:
[root@foundation74 bin]# chmod +x /usr/bin/creat_vm.sh
[root@foundation74 bin]# creat_vm.sh test
一键命令弄好虚拟机快照:
在 /usr/bin 创建 vm_anapshoot.sh
1 #!/bin/bash
2
3
4 #####create snapshoot file#####
5 qemu-img create -f qcow2 -b /var/lib/libvirt/images/$1.qcow2 \
6 /var/lib/libvirt/images/$2.qcow2 &> /dev/null
7
8 #####import snapshoot to vm#####
9
10 virt-install \
11 --name $2 \
12 --vcpus 1 \
13 --memory 1024 \
14 --disk /var/lib/libvirt/images/$2.qcow2,bus=virtio \
15 --network bridge=br0,model=virtio \
16 --import &> /dev/null &
[root@foundation74 bin]# chmod +x /usr/bin/vm_snapshoot
[root@foundation74 bin]# vm_snapshoot.sh generic node
完成!!!