#### script installation virtual machine
#!/bin/bash virt-install \ --cdrom /home/kiosk/Desktop/rhel-server-7.3-x86_64-dvd.iso \ --ram 1024 \ --cpus 1 \ --disk /var/lib/libvirt/images/test.qcow2,bus=virtio,size=9 \ ##I don't know. Wait a minute. --name test \ --network bridge=br0,model=virtio & ##Instead of writing the model, install it and read it. Write it accordingly.
## Use this script again to install the virtual opportunity to report errors because of the test virtual machine
## Without looking at the output, & >/dev/null
######## Virtual Machine Management Command
virt-manager ##Boot-up Virtual Machine Manager virsh list ##Display a running virtual machine virsh list --all ##View all virtual machines virsh start desktop ##open virsh shutdown desktop ##Normal shutdown of virtual machines ##Must be in the system virsh destroy desktop ##force close virt-viewer desktop ##Display Virtual Machine virsh undefine test ##Delete virtual machines
Rehabilitation of Simulated Virtual Machines at Home
Prepare an installed virtual machine
mv /etc/libvirt/qemu/test.xml /mnt/ ##Hardware information mv /var/lib/libvirt/images/test.qcow2 /mnt/ ##Hard disk
Delete the installed virtual machine in the virtual machine manager to simulate the recovery process.
cd /mnt virsh create test.xml ##Start the virtual machine with hardware message (once shut down, no more)
The following errors will occur during the operation:
error: Cannot access storage file '/var/lib/libvirt/images/test.qcow2' (as uid:107, gid:107): No such file or directory
Solution:
mv /mnt/test.qcow2 /var/lib/libvirt/images/ virsh define test.xml ##Permanent Restoration Virtual Machine
#### Virtual Machine Snapshot####
qemu-img create -f qcow2 -b test.qcow2 node1
################ How to Create Virtual Machines with Scripts
The script content:
#!/bin/bash qemu-img create -f qcow2 -b \ /var/lib/libvirt/images/$1.qcow2 \ ##$1 is an existing virtual machine /var/lib/libvirt/images/$2.qcow2 ##$2 is snapshot. virt-install \ --name $2 \ --ram 1024 \ --cpus 1 \ --disk /var/lib/libvirt/images/$2.qcow2,bus=virtio \ --network bridge=br0,model=virtio \ --import &
######### Using script reset virtual machine
#!/bin/bash virsh destroy $1 rm -fr /var/lib/libvirt/images/$1.qcow2 ##$1 is a snapshot and $2 is a master. qemu-img create -f qcow2 -b /var/lib/libvirt/images/$2.qcow2 /var/lib/libvirt/images/$1.qcow2 virsh start $1 virt-viewer $1 &