Linux (Radhat) Basic Learning-Virtual machine management

Source: Internet
Author: User
Tags configuration settings create domain

1. Virtual machines:
虚拟机指通过软件模拟的具有完整硬件系统功能的、运行在一个完全隔离环境中的完整计算机系统。**

Learning is using the Redhat system virtual machine which consists of two parts of the file:
(1). Hard disk File (Qcow2 file): The operating system is logged. All system information is on the hard drive. Qcow2 file
(2). Hardware information file (XML file): Loss of corruption can be generated again. XML file.

2.redhat installation of virtual machines

1. Download the image and put it in the appropriate location (below the image I put in the root directory of the ISO directory)
# #A. Graphical interface Installation
Execute: Virt-manager into the virtual Machine Manager to create a new installation virtual machine.
After the installation of the system environment, the virtual machine will restart, enter the system settings interface, the language, time zone, super User password settings and other operations.

# #B. Script installation
1. Create a file:
XXXX (Best specification command: create_vm.sh)


2. Write content:

#!/bin/bash    ##打开shell,使下面的命令在bash中执行virt-install --cdrom /iso/rhel-server-7.3-x86_64-dvd.iso \     ##从目录中载入镜像文件--ram 1024 --cpus 1 --disk /var/lib/libvirt/images/$1.qcow2,bus=virtio,size=9 \  ##硬盘文件位置,类型,大小--name $1 --network bridge=br0,model=virtio

3. New virtual machine: create_vm.sh Virtual machine Name

(1) Execute new virtual machine command: SH create_vm.sh xyz

(2) Select the first line to install the Linux7.3,

(3) Select the language in the installation process

(4) Configuration settings

(5) Select time Zone (East eight Shanghai)

(6) Select the language of the system (in addition to the default English, here also selected Chinese)

(7) Select the minimalist GUI installation

(8) Select the free partition setting capacity


Eventually there is the root directory, the boot directory under the root directory, the swap directory

Choose to accept Change

(9) Click on the left option to enter, set the Super user password

(10) Wait for the installation to complete.


(11) The installation is complete, restart the virtual machine.

(12) Agree to install the Use agreement


When the settings are complete, click the bottom right corner to complete the installation wizard.
This completes the installation of a virtual machine, followed by the system using settings, language, time zone, and then adding a regular user.
(13) in the virtual Machine Manager we can see the new virtual machine, here, select the virtual machine, the right mouse button can also be switched on and off the operation.

3. Virtual Machine Management Commands
virt-manager      开启虚拟机管理管理器(图形界面)virt list      查看正在运行的虚拟机virt list --all      查看所有的虚拟机virsh start 虚拟机名     开启虚拟机virsh shutdown 虚拟机名   正常关闭虚拟机virsh destroy 虚拟机名    强制关闭虚拟机virt-viewer 虚拟机名    图形化显示虚拟机

Virtual Machine Recovery:

virsh create 虚拟机名.xml   暂时恢复,当退出时,虚拟机又会消失virsh define 虚拟机名.xml   永久恢复
4. Simulating virtual machine recovery

Prepare a virtual machine that is already installed
Move a file to simulate a virtual machine to be recovered (simulate a backup of a good virtual machine)
mv/etc/libvirt/qemu/virtual machine. xml/mnt
mv/var/lib/libvirt/images/virtual machine. qcow2/mnt
Remove the virtual machine from the virtual Machine Manager. (Analog failure)


Recovery process:
CD/MNT switch to the directory that just prevented the file, start the virtual machine with hardware information
Virsh Create virtual machine. XML to temporarily restore the virtual machine,
Virsh define virtual machine. XML Permanent Recovery virtual machine
This process will cause an error:
(1) Error restoring virtual machine temporarily:

error: Failed to create domain from test.xmlerror: Cannot access storage file ‘/var/lib/libvirt/images/test.qcow2‘ (as uid:107, gid:107): No such file or directory

(2) The permanent recovery of the virtual machine will not be error, but can not be started.

workaround-------> Both of these errors are due to the location of the hard disk Qcow2 in the hardware information file XML/var/lib/libvirt/images/, and at this point, the hard disk file Xyz.qcow2 in the/mnt directory, So the error will be. Move the Xyz.qcow2 to the/var/lib/libvirt/images/.
In order to avoid accidental deletion of files, it is best to put the hardware information files back to/etc/libvirt/qemu/
Successful recovery after moving files:

You can see the recovered virtual machine xyz in the virtual Machine Manager:

<< 3 seconds new virtual machine >>

A virtual machine's disk can take snapshots, each VM has a snapshot, and a snapshot is a mirror, and we can see the full virtual machine when we look in the mirror. In the case of virtual machine operations, the mirror (snapshot) operation is actually performed, that is, the virtual machine operates on the snapshot, rather than directly in the disk file, and of course, the disk that generates the snapshot must exist.
For the composition of the virtual machine, we can quickly build a new virtual machine by generating a snapshot directly from the disk. The premise is that there are disk files and hardware information files for the virtual machine

You can set up a new virtual machine in the virtual Machine Manager step by step, and we can write a script to make it automatically create a new virtual machine. The graphical interface of the new virtual machine does not do a demonstration.

Snapshot seconds Build virtual machine

1. Hard disk File Set up snapshot script:

File creation: Vim vm_kuaizhao.sh

Write content:

#!/bin/bashqemu-img create -f qcow2 -b \       ##指定文件格式是qcow2/var/lib/libvirt/images/$1.qcow2 \  ##指定原始磁盘名字/var/lib/libvirt/images/$2.qcow2    ##指定创建的快照的名字virt-install --name $2 \             ##直接将创建的快照名字作虚拟机名字--ram 1024 \                ##分配内存大小--cpus 1 \              ##cpu颗数--disk /var/lib/libvirt/images/$2.qcow2,bus=virtio --network bridge=br0,model=virtio \ ##网络设置--import &              ##将新建的快照导入新建的虚拟机

Save exit.

2. Run the script to create a new virtual machine: SH vm_kuaizhjao.sh xyz XYZ1

<< virtual machines.

Based on the new virtual machine, you can implement resetting the virtual machine. After the virtual machine has been mistakenly operated, we can change the mirror directly (to reconstruct the snapshot). That is, we can delete the original snapshot of the virtual machine, regenerate a snapshot of the same name from the disk file, and import the snapshot to implement resetting the virtual machine.

New file: vm_reset.sh

Write content

#!/bin/bashvirsh destroy $1rm -fr /var/lib/libvirt/images/$1.qcow2qemu-img create -f qcow2 -b /var/lib/libvirt/images/$2.qcow2 /var/lib/libvirt/images/$1.qcow2virsh start $1virt-viewer $1 &

Save exit

Perform file reset virtual machine: SH vm_reset.sh virtual machine name Disk name

Linux (Radhat) Basic Learning-Virtual machine management

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.