Virtual Machine Management and Snapshot Generation

Keywords: snapshot xml network vim

Replication and Recovery of Virtual Machines
Duplicating a virtual machine is actually duplicating his hard disk and hardware information.

/var/lib/libvirt/images/xxxx.qcow2  ##Storage Path of Hard Disk
/etc/libvirt/qemu/xxxx.xml  ##Hardware Information File Storage Path 

For example, to replicate a virtual machine named westos on a remote host, we need to replicate its hard disk and hardware information.

scp root@ip:/var/lib/libvirt/images/westos.qcow2   /mnt
scp root@ip: /etc/libvirt/qemu/westos.xml   /mnt  


How do we restore the virtual machine when deleting the replicated virtual machine in the virtual machine manager?

cd  /mnt
virsh create test.xml  ##Start a virtual machine called test from a hardware information file
error: Cannot access strage file ' /var/lib/libvirt/images/xxxx.qcow2 '(as uid :107, gid 107): No such file or directory  ##Error reporting indicates that there is no hardware information file in this directory with its corresponding storage path
mv  /mnt/test.qcow2    /var/lib/libvirt/images/  ##The solution is to move the hard disk information file to the corresponding directory.
virsh create test.xml  ##Start the virtual machine through the hardware information file. The virtual machine is restored to the virtual machine manager. After the virtual machine is turned off by command, the virtual machine disappears in the manager.
virsh  define test.xml ##The virtual machine still exists in the manager after the virtual machine is turned off by command

After copying the virtual machine information file of the remote host, there is no virtual machine in the manager of the virtual machine that can be displayed by driving the duplicated virtual machine hardware information file.

Finding Error Moving Replicated Virtual Machine Hard Disk Information File

The hardware information file of the virtual machine was successfully found in the manager after it was moved and restarted.


Management of Virtual Machine

virt-manager ##Open Virtual Machine Manager
virsh start desktop ## Opening rht-vmctl start desktop that virtual machine cannot be blocked may be blocked
virt-viewer desktop ##The rht-vmctl view desktop that shows that the virtual machine cannot be blocked may be blocked
virsh list ##Display a running virtual machine
vrish list --all ##View all virtual machines
vrish shutdown desktop ##Normal shutdown of virtual machines
vrish destory desktop ##force close

Open the manager of the virtual machine

Open Blocked and Not Blocked


Display Block Display No Block


List running virtual machines

List the states of all virtual machines

shutdown closing virtual machine may be blocked

destroy shuts down the virtual machine and cannot be blocked

Installation of Virtual Machine
(1) Graphical Installation of Virtual Machines

virt-manager ##Enter this command in the real machine to open the virtual machine manager

In the open VM Manager, click on the "TV" logo to select the local download llocal install media cdrom


Choose the Local Mirror Path

Choose the memory size of the virtual machine to install and the number of CPUs

Select the size of memory occupied by the virtual machine


Setting Virtual Machine Name and Selecting Hardware Information for Custom Virtual Machine

Hard Disk Selection virtio

Network Card Selection Virtualization

Select the upper left corner to start installing begin installation, and the interface appears as shown in the figure.


Ann continues to fill in installation information


Enter the following interface to start information selection

Choosing Time Zone in Shanghai, Asia
!
Language Support Selection of English and Simplified Chinese
Select the system interface to display graphical interface after installation

Select custom partitions

Set partition / boot Swap / root without choosing to automatically allocate the remaining memory



Press Start Installation to Add Super User and Password

(2) Editing scripts to install virtual machines (semi-automatic)

Creating virtual machine by executing script automatically filling in the information needed to establish virtual machine

cd /mnt ##Connect to the previous experimental location to enter the directory or not.
vim  vm_create.sh ##The build script contains all the information needed to create the virtual machine
test -z "$1"  && {
                   echo "Error : Please  input VMname following scripts !! " ##When the name of the virtual machine installed after the command is added, there will be no error or there will be an error.
                   exit
                   }
  vrit-install \  ##download
     --name $1 \  ##The name $1 for creating a virtual machine indicates placeholder
     --cdrom /root/rhel7.3/x86_64/isos/rhel_server-7.3-x86_64-dvd.iso \ ##Choose the mirror path
     -- memory 1024 \ ##Fill in memory size 1024
     --vcups 1 \ ##One cpu ##The installed virtual machine has a cpu
     --disk /var/lib/libvirt/images/$1.qcow2,size=6,bus=virtio \  ##Relevant information of physical hard disk. 6G bus virtualization of the information size of the virtual machine hard disk generated under the specified directory
     --network source=br0,model=virtio  &> /dev/null  &  ##Network Service Source Network Model Virtualization Directs Error Output to the Garbage Bin for Background Download            

Create a virtual machine called b, as shown in the execution script. The virtual machine does only a part of the operation and is not usable.

Virtual Machine Snapshot Generation (create a snapshot of the virtual machine that is fully installed)

(1) Basic way to generate snapshots

cd  /var/lib/libvirt/images
ls     
qemu-img create  -f  qcow2  -b /var/lib/libvirt/images/westos.qcow2   /var/lib/libvirt/images/su.qcow2
##This command can create a snapshot hardware information file named su for the virtual machine westos on the premise that there is a hardware information file for the virtual machine

Create snapshots graphically, click on the "TV" icon, select Import Snapshot Hard Disk Information File, and create snapshots

Select the snapshot information path



Select the snapshot memory size created

Set snapshot name to su and select custom snapshot hardware information


Start choosing hardware information the same as the previous virtual machine creation choices


Figure Created Successfully

Qemu-img create-f qcow2-b/var/lib/libvirt/images/westos.qcow2/var/lib/libvirt/images/su.qcow2 copied hard disk path to get hard disk path

(2) Generating snapshots using scripts
Cd/mnt# Create script files to generate snapshots in any path
VIM vm_create_shotsnop # Edit script file
qemu-img create
-f qcow2
- b/var/lib/libvirt/images/$1.qcow2/var/lib/libvirt/images/$2.qcow2 &>/dev/null\#1 Virtual Machine Name $2 Snapshot Name

virt-install \
--name $1\
  --cdrom /root/rhel7.3/x86_64/isos/rhel_server-7.3-x86_64-dvd.iso \ ##Install the system through the mirror path
--memory 1024 \
--vcpus 1 \
--disk /var/lib/libvirt/images/$1.qcow2,bus=virtio \
--network source=br0,model=virtio \
--import  &> /dev/null  &  ##Import snapshot path

Create a snapshot named node1 for a virtual machine named westos with a script

Posted by SuNcO on Wed, 24 Jul 2019 21:34:02 -0700