Install the virtual machine
1. Modify the virtual machine settings with a script:
1 cd /mnt
2 vim vm_create.sh #Edit and install virtual machine and virtual machine setup script
******vm_create.sh******
#!/bin/bash #Magic number (magic number check is used to check whether the file has special fixed format data, when you see the first line of characters, you will understand the file attributes)
virt-install \ #Install the virtual machine
--cdrom /home/kiosk/Desktop/rhel-server-7.0-x86_64-dvd.iso \ #installation location
--ram 1024 \ #memory size
--cpus 1 \ #cpu number
--disk /var/lib/libvirt/images/$1.qcow2,#hard disk location size=9#hard disk size,bus=virtio \ #hard disk type
--name $1 \ #Specify the virtual machine name
--network source=br0,model=virtio #network type
3 chmod +x /mnt/vm_create.sh #Add executable permission
4 sh vm_create.sh westos #Run the script
2. Manually install the virtual machine
********Take a snapshot of a virtual machine********
##1. Make a snapshot with the command
[root@foundation32 ~]# cd /var/lib/libvirt/
[root@foundation32 libvirt]# cd images/
2.ls #View virtual machine master disk
#Make a snapshot; backup westos.qcow2 to new.qcow2
##2. Make snapshots with scripts
[root@foundation64 mnt]# cd /var/lib/libvirt/images/
[root@foundation64 images]# ls
fafa.qcow2 rh124-desktop.xml
new.qcow2 rh124-server-vda.ovl
rh124-desktop-vda.ovl rh124-server-vda.qcow2
rh124-desktop-vda.qcow2 rh124-server-vdb.ovl
rh124-desktop-vdb.ovl rh124-server-vdb.qcow2
rh124-desktop-vdb.qcow2 rh124-server.xml
[root@foundation64 images]# rm -f new.qcow2
[root@foundation64 images]# cd /etc/libvirt/qemu/
[root@foundation64 qemu]# ls
desktop.xml fafa.xml networks new.xml server.xml
[root@foundation64 qemu]# rm -f new.xml
[root@foundation64 qemu]# cd /mnt/
[root@foundation64 mnt]# ls
vm_create.sh
[root@foundation64 mnt]# vim vm_sanpshoot.sh
#!/bin/bash
qemu-img create -f qcow2 -b \ #Make a snapshot
/var/lib/libvirt/images/$1.qcow2 \
/var/lib/libvirt/images/$2.qcow2
virt-install \
The second character after the --name $2 \ # character is the snapshot name
--cpus 1 \ #Number of snapshot CPUs
--ram 1024 \ #RAM
--disk /var/lib/libvirt/images/$2.qcow2,#hard disk location bus=virtio \#hard disk type
--import & #Execute in background
[root@foundation64 mnt]# chmod +x vm_sanpshoot.sh #Add executable permission
[root@foundation64 mnt]# /mnt/vm_sanpshoot.sh fafa new2
# means to run the snapshot program, the master disk is fafa, and the snapshot is new2
Formatting '/var/lib/libvirt/images/new2.qcow2', fmt=qcow2 size=9663676416 backing_file='/var/lib/libvirt/images/fafa.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
[root@foundation64 mnt]# WARNING No operating system detected, VM performance may suffer. Specify an OS with --os-variant for optimal results.Starting install...
Creating domain... | 0 B 00:00
(virt-viewer:10466): GSpice-WARNING **: Warning no automount-inhibiting implementation available
3. Virtual machine management:
1 cd /var/lib/libvirt/images/ #hard disk location
2 mv westos.qcow2 /mnt/
3 cd /etc/libvirt/qemu/ #Location of hard disk information
4 ls
5 mv westos.xml / mnt /
6 cd /mnt/
7 ls
8 mv westos.qcow2 /var/lib/libvirt/images/
9 ls
#The reason why we need to remove the hardware information and hard disk of the westos virtual machine is to delete the icon and then move it back to the original location to restore it directly, so as to avoid wasting time for re-downloading, and friends can also do experiments#
10 virsh create westos.xml #One-time recovery
[root@foundation64 mnt]# virsh create new.xml
Domain new created from new.xml
***It will disappear automatically after shutdown new virtual machine**
11 virsh define new.xml #Permanent recovery
[root@foundation64 mnt]# virsh define new.xmlDomain new defined from new.xml
12 virsh undefined new #delete icon
[root@foundation64 mnt]# virsh undefine newDomain new has been undefined
#It can be restored after deletion, because only the icon is deleted, and the hardware information and hard disk are not deleted
[root@foundation64 mnt]# virsh define new.xml
Domain new defined from new.xml
13 virsh start new #Run the specified vm
[root@foundation64 mnt]# virsh start new
Domain new started
14 virsh destroy new #Forcibly end
[root@foundation64 mnt]# virsh destroy newDomain new destroyed
15 virsh showdown new #Normal shutdown
[root@foundation64 mnt]# virsh start newDomain new started
[root@foundation64 mnt]# virsh shutdown new
Domain new is being shutdown
16 virsh list --all #Display all virtual machine status
[root@foundation64 mnt]# virsh list --all
Id Name State--------------------------------------------------------- -----
2 desktop running
7 fafa running
- new shut off
- server shut off
17 virt-viewer new #Visualization, similar to rht-vmctl view new