Linux-based virtual machine control

1. Install a virtual machine

    Method 1:
Enter virt-manager on the real machine to pop up an interface

Select forward in the lower right corner

Select the downloaded rhel-server-7.0-x86_64-dvd.iso installation source in Broese..., select it and press forward


Select the appropriate memory, continue to press forward

Continue to press forward

Here is the name of the virtual machine, you can start it at will.


Up and down keys to select the first

Time zone selected as Shanghai 

Select Standard Partiton, then press the + sign

Choose appropriate memory space for /boot , swap , /

(The last column of / is empty means that all remaining memory space is reserved for / )

The purpose of selecting the GUI is to display the image in the virtual machine

The current interface is like this

The next step is to start the download. After downloading, press reboot.

The first option at the top is to enter the power-on password of the root superuser of the virtual machine, and the second is to create a normal user.

When choosing this, you must tick No, otherwise you will be charged.


Enter username and passwrd to enter the virtual machine

A virtual machine is installed.


    Method Two:

On a real machine:
su - root
cd /mnt/

vim vm_create.sh

       #!/bin/bash magic number, translator
      virt-install \ virtual machine build
      --cdrom /home/kiosk/Desktop/rhel-server-7.0-x86_64-dvd.iso \ installation source
                   (enter ls in another shell /home/kiosk/Desktop find downloaded)
       --ram 1024 \ memory
        --cpus 1 \  
                                                                      (size) (type)
        --disk /var/lib/libvirt/images/$1.qcow2,size=9,bus= virtio \
                  (path, open a virtual machine that has been built, turn on the light bulb, virtlo disk 1 )
         --name $1 \ virtual machine name
        --network source=br0,model=virtio &

                  (Network Resource Construction) (Model of Virtual Machine)

chmod +x  /mnt/vm_create.sh

/mnt/vm_create.sh westos (the name of the virtual machine) 


& will not occupy the terminal
$0 the script itself  
$1 the first string of characters after the script
$2$3$4$5$6$7$8$9 and so on      
$# the number   
of scripts $* all the characters in the script

 


Using the command method can install a virtual machine faster.

2. Virtual machine snapshot (backup)

Method 1 (manual):
 qemu-img create -f qcow2 -b jane.qcow2 test.qcow2
 virt-manager
 cd /var/lib/libvirt/images/
 ls (test.qcow2 appears)

 

This time select the fourth option, which means to use an existing virtual machine. Press forward.

Select the downloaded rhel-server-7.0-x86_64-dvd.iso installation source in Broese..., select it and press forward

Choose the right memory space

Give the backup virtual machine an arbitrary name

Up and down keys to select the first

Time zone selected as Shanghai 

Select Standard Partiton, then press the + sign

Choose appropriate memory space for /boot , swap , /

(The last column of / is empty means that all remaining memory space is reserved for / )

The purpose of selecting the GUI is to display the image in the virtual machine

The current interface is like this

The next step is to start the download. After downloading, press reboot.

The first option at the top is to enter the power-on password of the root superuser of the virtual machine, and the second is to create a normal user.

When choosing this, you must tick No, otherwise you will be charged.


Enter username and passwrd to enter the virtual machine


That's it, a snapshot of a virtual machine is complete.


 Method 2 (command):
 
  1. Make a snapshot
  2. Put the snapshot into the virtual machine
  3. Start the generated virtual machine
  4. Display the opened virtual machine

     cd /mnt/
     ls The .xml form of the good virtual machine exists
     vim vm_sanpshoot.sh  

#!/bin/bash
qemu-img create -f qcow2 -b \ command
/var/lib/libvirt/images/$1.qcow2 \ ok
vm /var/lib/libvirt/images/$2.qcow2 snapshot

virt-install \ virtual machine creation
--name $2 \ name
--cpus 1 \ memory
--ram 1024 \ memory
--disk /var/lib/libvirt/images/$2.qcow2,bus=virtio \    
(path, open a built Good virtual machine, turn on the light bulb, virtlo disk 1)
--network source=br0,model=virtio \ network
--import & Click the last of the four options that will appear on the TV, the existing image
executes the input command:
    /mnt /vm_sanpshoot.sh jane haha ​​(photo taken)
                      (good virtual machine)

 



3. Transfer the virtual machine

Method 1:

cd /etc/libvirt/qemu/
ls (virtual machine with good jane.xml)

scp jane.xml [email protected]:/mnt/



Method 2:

virsh list --all #View the names of all installed virtual machines
virsh start desktop #Open desktop
virt-viewer desktop #Display desktop
virsh shutdown desktop #Close desktop normally
virsh destroy desktop #Forcibly close desktop
virsh create test. qcow2 #One-time recovery
virsh define test.qcow2 #Permanent recovery
virsh undefine test #Permanent deletion

The specific operation steps are as follows: (in the real machine)
Experiment:
cd /var/lib/libvirt/images
ls
mv test.qcow2 / mnt  
ls  
cd /etc/libvirt/qemu
ls
mv test.xml /mnt #Move the hardware information of the virtual machine to /mnt
cd /mnt
ls #Check whether the virtual machine is moved to /mnt
mv test.qcow2 /var/lib// libvirt/images
ls
detection:
virt-manage #Open the graph and delete the test manually
virsh create test.qcow2 #One-time recovery (test will disappear after disconnecting and reconnecting)
virsh define test.qcow2 #Permanent recovery (disconnecting and reconnecting test still exists)
virsh undefine test #Permanent deletion



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324879588&siteId=291194637