Linux KVM Virtual machine quick Build and disk type

Source: Internet
Author: User
Tags prepare uuid

KVM Command Management

Virsh command: Interface commands for managing each virtual machine
View/Create/stop/close ...
Support Interactive mode
Format:
Virsh control instruction [virtual machine name] [parameters]

[[Email protected] Desktop]# Virsh nodeinfo (view CPU information of Virtual machine server)
CPU Model: x86_64
Cpu:2
CPU Frequency: 1900 MHz
CPU Socket:2
Number of cores per socket: 1
Number of threads per core: 1
NUMA Unit: 1
Memory Size: 1906912 KiB
[[Email protected] Desktop]# virsh list--all (List of virtual machines, including shutdown)
Id Name Status
----------------------------------------------------
1 Rh6_node07 Running
2 rh6_node06 Running
-Rh6_node05 off
-Win2008 off

[[Email protected] Desktop]# Virsh dominfo rh6_node07 (View virtual machine configuration in Virtual server)
Id:1
Name: rh6_node07
Uuid:fbf829d8-5bda-49f0-adeb-ddacac73c5ea
OS Type: HVM
Status: Running
Cpu:1
CPU Time: 1894.7s
Max Memory: 1048576 KiB
Memory used: 1048576 KiB
Persistent:yes
Auto-Start: Disable
Managed Save:no
Security mode: None

——————————————————————————————————————

KVM Soft Shutdown/restart/boot
Virsh Shutdown Virtual machine name
Virsh reboot Virtual machine name
Virsh Start Virtual machine name
KVM Hard shutdown (forced power off)
Virsh Destroy virtual machine name

Set up virtual machine boot
Virsh autostart Virtual machine name
To cancel a virtual machine from booting
Virsh autostart--disable Virtual machine name

The composition of a single KVM virtual machine
Configuration files for virtual machines:
The default is the/etc/libvirt/qemu/virtual machine name
Disk files for virtual machines:
The default is the/var/lib/libvirt/images/virtual machine name. IMG (either prepared by the Administrator in advance, manually specified)

XML Description File Introduction
Log detailed parameters for each virtual machine
Name UUID memory CPU disk ...
File Location: Cat/etc/libvirt/qemu/rh6_node07.xml
<domain type= ' KVM ' >
<name>rh6_node07</name> (name)
<uuid>fbf829d8-5bda-49f0-adeb-ddacac73c5ea</uuid> (UUID value)
<memory unit= ' KiB ' >1048576</memory>
<currentmemory unit= ' KiB ' >1048576</currentMemory> (memory size)
<vcpu placement= ' static ' >1</vcpu> (number of CPUs)
。。。。。。。。


Export/Extract the configuration of a virtual machine
Virsh dumpxml virtual machine name >/root/new.xml
Modify the exported configuration
Vim/root/new.xml
Import/Redefine Configuration
Virsh Define/root/nwe.xml
Cancel definition
Virsh undefine Virtual machine name

Exercise: Change the virtual machine rh6_node06 to RH6_NODE01
[[email protected] ~]# Virsh dumpxml rh6_node06 >/root/nwe.xml (Export virtual machine configuration directed to/root/new.xml)
[[email protected] ~]# vim/root/nwe.xml (change name)
<domain type= ' KVM ' id= ' 2 ' >
<name>rh6_node01</name> (change name)
<uuid>d2e18138-6ec6-45e2-baab-5da0dec1ee97</uuid> (change uuid, not the same)
[[email protected] ~]# Virsh define/root/nwe.xml (Import virtual machine)

Exercise: Change the virtual machine rh6_node06 to RH6_NODE02
[[email protected] ~]# Virsh dumpxml rh6_node06 >/root/nwe.xml (Export virtual machine configuration directed to/root/new.xml)
[[email protected] ~]# vim/root/nwe.xml (change name)
<domain type= ' KVM ' id= ' 2 ' >
<name>rh6_node02</name> (change name)
<uuid>d2e18138-6ec6-45e2-baab-5da0dec1ee97</uuid> (Modify UUID)
</interface>
<interface type= ' network ' >
<mac address= ' 54:52:01:01:06:02 '/> (Modify MAC address)
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type= ' file ' device= ' disk ' >
<driver name= ' qemu ' type= ' qcow2 ' cache= ' None '/>
<source file= '/var/lib/libvirt/images/rh6_node02.img '/> (Modify HDD)
[[email protected] ~]# Virsh define/root/nwe.xml (Import virtual machine)
[Email protected] images]# cd/var/lib/libvirt/images/
[[email protected] images]# ls
Rh6_node05.img rh6_node06.img rh6_node07.img
[[email protected] images]# CP rh6_node06.img rh6_node01.img & (Copy the disk of the virtual machine being copied)
[1] 35752

Export, modify, import triad operations
[Email protected] ~]# Virsh edit rh6_node06
<domain type= ' KVM ' id= ' 2 ' >
<name>rh6_node03</name> (change name)
<uuid>d2e18138-6ec8-45e2-baab-5da0dec1ee97</uuid> (Modify UUID)
</interface>
<interface type= ' network ' >
<mac address= ' 54:52:01:01:06:03 '/> (Modify MAC address)
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type= ' file ' device= ' disk ' >
<driver name= ' qemu ' type= ' qcow2 ' cache= ' None '/>
<source file= '/var/lib/libvirt/images/rh6_node03.img '/> (Modify HDD)
[[email protected] images]# CP rh6_node06.img rh6_node03.img & (Copy the disk of the virtual machine being copied)
[1] 35752

[[email protected] ~]# ls/var/lib/libvirt/network/(Virtual System Manager NIC configuration file)
Default.xml private1.xml private2.xml public1.xml public2.xml


Cloning a virtual machine
Virt-clone-o cloned Virtual machine-N New virtual machine name-F new Disk save path
[Email protected] opt]# virt-clone-o rh6_node05-n hydra-f/var/lib/libvirt/images/rh6_node03.img
Assigning ' rh6_node03.img ' | GB 01:39

————————————————————————————————————————————————————

Virtual Machine Fast Building technology
Image management for KVM virtual machines
Primarily for virtual machine Disk Management
—————————————————— +
Features/type RAW QCOW2 |
KVM Default Whether |
High I/O efficiency higher |
Space-Occupying size |
Compression Unsupported Support |
Incremental backup does not support support |
Snapshot does not support support |
—————————————————— +
Cow working principle:
Copy on write, copying on write
Directly map the data contents of the original disk, and when the original volume has been modified, write the old data that was changed to the incremental disk
Changes to the incremental disk are not written to the original disk

Managing virtual disks with QEMU-IMG
View disk information: Qemu-img info disk path
Image:rh6_node01.img
File Format:qcow2
Virtual size:50g (53687091200 bytes)
Disk size:323m
cluster_size:65536
Backing file:/var/lib/libvirt/images/.rh6_template.img

Create a new standalone disk: qemu-img create-f disk type (RW/QCW2) disk path hard disk size
[[email protected]oom1pc01 ~]# qemu-img create-f raw/va R/lib/libvirt/test1.img 20G (raw type)
formatting '/var/lib/libvirt/test1.img ', Fmt=raw size=21474836480
[[Email  protected] images]# qemu-img create-f qcow2/var/lib/libvirt/images/test2.qcow2 20G (qcow2 type)
Formatting '/ Var/lib/libvirt/images/test2.qcow2 ', Fmt=qcow2 size=21474836480 encryption=off cluster_size=65536
Create a new stand-alone disk (Delta/ Previous): Qemu-img create-f qcow2-b back end disk path size (size can be omitted)

Exercise: Build a new virtual machine rh6_node05 from a virtual machine rh6_nonde04
To prepare a new disk:
[Email protected] images]# qemu-img create-f qcow2-b/var/lib/libvirt/images/rh6_node05.img/var/lib/libvirt/images/ Rh6_node03.qcow2
Formatting '/var/lib/libvirt/images/rh6_node03.qcow2 ', fmt=qcow2 size=53687091200 backing_file= '/var/lib/libvirt/ Images/rh6_node05.img ' Encryption=off cluster_size=65536
To prepare the new configuration:
[[email protected] images]# Virsh edit rh6_node05 (export, modify, import triad operation)
<domain type= ' KVM ' >
<name>rh6_node03</name> (change name)
<uuid>e1aa2571-22c6-4804-924d-953e8fc7ad2c</uuid> (change uuid)

<driver name= ' qemu ' type= ' qcow2 ' cache= ' None '/> (change disk type Type=qcow2)
<source file= '/var/lib/libvirt/images/rh6_node03.qcow2 '/> (disk path strength)

<mac address= ' 54:52:01:01:05:56 '/> (change MAC address)

Convert disk Format:
Qemu-img Convert-o new type is converted to disk path new disk path

Exercise: Convert a virtual machine disk with an old format disk into a new format
[Email protected] images]# qemu-img convert-o qcow2/var/lib/libvirt/images/rh6_node06.img/var/lib/libvirt/images/ Rh6_node06.qcow2
Adjust the configuration (type, path) of the new disk
[Email protected] images]# Virsh edit rh6_node06
<driver name= ' qemu ' type= ' qcow2 ' cache= ' None '/> (change disk type Type=qcow2)
<source file= '/var/lib/libvirt/images/rh6_node06.qcow2 '/> (disk path strength)
If necessary, you can remove the disk after adjusting the configuration
[[email protected] images]# ls
Rh6_node03.qcow2 rh6_node05.img rh6_node06.img Rh6_node06.qcow2 rh6_node07.img
[Email protected] images]# RM-RF rh6_node06.img

Managing Disk Snapshots: (the disk type must be Qcow2)
Qcow2 Snapshot Management:
Capture too many backups for disk records at different points in time
(Non-stand-alone files)
Restore a virtual machine to a specified snapshot, if necessary
Basic usage:
-C: Create a snapshot
-L: View Snapshot
-A: Revert to the specified snapshot
-D: Delete Snapshot
Qemu-img snapshot-c Snapshot Name disk path
QEMU-IMG snapshot-l Disk Path
Qemu-img snapshot-a Snapshot Name disk path
Qemu-img snapshot-d Snapshot Name disk path

————————————————————————————————————

Preparing the template virtual machine
Command line mode/install virtual machine
Virt-install--name muban1--vcpus 1--raw 1024
--disk Path=/var/lib/libvirt/imagesmuban1.qcow2,
Format=qzow2--network=private1--pxe

Initialize settings
Pre-installed software processing
Package
IP Address
Host Name
Nic parameters (MAC address)
/etc/udve/rules.d/70-persistent-net.rules (empty)
/etc/sysconfig/network-scripts-eth0
Remove Hwaddr UUID

Factory settings
Touch/.unconfigured (Create a file in/directory)

——————————————————————————————————————
Guestmount Tools
Support for offline mounting of virtual machine disks in RAW,QCOW2 format
Can be in the case of virtual machine. Directly modify documents on disk
Easy to customize, repair, and script maintenance of virtual machines

Mount Virtual Disk
Basic format:
Guestmount-a Disk path-I/mount point
Guestmount-a disk path-M virtual machine partition/mount point
[Email protected] ~]# yum-y install Libguestfs-tools

—————————————————————————————————————

Linux KVM Virtual machine quick Build and disk type

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.