Basic management of KVM Virtualization

Source: Internet
Author: User
Tags unsupported

Basic management of KVM Virtualization
This article mainly introduces the basic management of KVM Virtualization: i. Common Operations of virsh commands II. Clone virtual machines III. disk image format conversion IV. snapshot management v. Disk resizing VI. Adjust cpu and memory to view sub-machine configurations VII. Online increase without restarting virtual machines nic 8. Virtual Machine migration 1. Common Operations on virsh commands 1. Enable and log on to the sub-machine [root @ centos ~] # Virsh start tpp1 [root @ centos ~] # Ssh 192.168.0.10 can also be enabled to access the sub-machine: [root @ centos ~] # Virsh start tpp1 -- console 2. Disable the sub-machine [root @ centos ~] # Virsh shutdown tpp1 // close note: by default, we cannot directly shut down ourselves on the host machine. We need to use the acpid service on the Child machine, this service allows the host machine to call the sub-machine's power-off interface. Therefore, you need to install and start the acpid service on the sub-machine. If the sub-machine does not enable the acpid service, although it is successfully disabled, it is still running. [Root @ centos ~] # Virsh console tpp1 [root @ localhost ~] # Yum install-y acpid [root @ localhost ~] #/Etc/init. d/acpid start and press Ctrl +] to exit the sub-machine [root @ centos ~] # Virsh shutdown tpp1 [root @ centos ~] # Virsh destroy tpp1 // another method is to delete the file directly from the list. 3. The sub-host is automatically started with the host when it is started [root @ centos ~] # Virsh autostart tpp1 // automatically start [root @ centos ~] # Virsh autostart -- disable tpp1 // uninstall auto start 4. List the sub-hosts [root @ centos ~] # Virsh list // only start sub-machines can be listed [root @ centos ~] # Virsh list -- all // list all sub-machines. 5. Delete the sub-machine [root @ centos ~]. # Virsh destroy tpp1 [root @ centos ~] # Virsh undefine tpp1 [root @ centos ~] # Rm-f/data/tpp1.img // if the format is qcow2, delete tpp2.qcow2 6, suspend and recover the sub-machine [root @ centos ~] # Virsh suspend tpp1 // suspend [root @ centos ~] # Virsh resume tpp1 // restore 7. Press ctrl +] to exit the sub-host and return to the host machine. 2. clone a VM [root @ centos ~] # Virt-clone -- original tpp1 -- name tpp2 -- file/data/tpp2.img Description: 1) shut down the machine to be cloned before cloning, otherwise, an ERROR is reported (the ERROR must be paused or the domain of the device to be cloned is disabled .) 2) -- original tpp1: Specify the machine to be cloned 3) -- name tpp2: specify the name of the cloned machine 4) -- file/data/tpp2.img: specifies the storage path (the name can be determined by the disk image format of the sample. qcow2 or. img) [root @ centos ~] # Virsh list -- all // you can see the cloned sub-machine. III. disk image format conversion. 1) view the sub-machine disk image format [root @ centos ~] # Qemu-img info/data/tpp1.imgimage:/data/tpp1.imgfile format: rawvirtual size: 10G (10739318784 bytes) disk size: 1.5G2) convert raw to qcow2 [root @ centos ~] # Qemu-img convert-f raw-O qcow2/data/tpp1.img/data/tpp1.qcow2 Description: It is equivalent to copying a copy and generating a qcow2 file (tpp1.qcow2) 3) view the disk image format of the sub-host again [root @ centos ~] # Qemu-img info/data/tpp1.qcow2image:/data/tpp1.qcow2file format: qcow2virtual size: 10G (10739318784 bytes) disk size: 392Kcluster_size: 655364) edit the sub-machine configuration file [root @ centos ~] # Virsh edit tpp1: <driver name = 'qemu' type = 'raw 'cache = 'none'/> <source file ='/data/tpp1.img '/> changed: <driver name = 'qemu' type = 'qcow2 'cache = 'none'/> <source file ='/data/tpp1.qcow2 '/> Description: edit the configuration file of this sub-machine, use the new format virtual disk image file. Command: virsh edit tpp1 enters the configuration file (/etc/libvirt/qemu/tpp1.xml) of the sub-machine. It is used in the same way as editing the file using vim. Iv. snapshot Management 1. Create a snapshot [root @ centos ~] # Virsh snapshot-create tpp1 // if the following message is displayed, Domain snapshot 1447276326 created is successful. Note: If the disk image format is raw, the following error is reported: unsupported configuration: internal snapshot for disk vda unsupported for storage type raw 2. List snapshots [root @ centos ~] # Virsh snapshot-list tpp1 Name Creation Time status -------------------------------------------------------------- 1447276326 05:12:06 + 0800 shutoff 3. view the snapshot version of the current slave [root @ centos ~] # Virsh snapshot-current tpp1 Description: the snapshot file of the tpp1 sub-machine is in the/var/lib/libvirt/qemu/snapshot/tpp1/directory [root @ centos ~] # Ls/var/lib/libvirt/qemu/snapshot/tpp1/1447276326.xml 4. Restore snapshot 1) First, disable the sub-host [root @ centos ~] # Virsh destroy tpp12) check whether the Sub-host is disabled [root @ centos ~] # Virsh domstate tpp1 off 3) List snapshots [root @ centos ~] # Virsh snapshot-list tpp1 Name Creation Time status ---------------------------------------------------------------- 1447276326 05:12:06 + 0800 shutoff4) restore the snapshot [root @ centos ~] # Virsh snapshot-revert tpp1 1447276326 5. delete a snapshot [root @ centos ~] # Virsh snapshot-delete tpp1 1447276326 Domain snapshot 1447276326 deleted 5. There are two ways to resize a disk, one is to expand the capacity, and the other is to directly increase the disk. The steps for expanding a raw and qcow2 Virtual Disk are the same. 1. Expand capacity 1) view VM information (size: 10 Gb) [root @ centos ~] # Qemu-img info/data/tpp1.qcow2image:/data/tpp1.imgfile format: rawvirtual size: 10G (10739318784 bytes) disk size: 400Kcluster_size: 655362) add 5 GB [root @ centos ~] # Qemu-img resize/data/tpp1.img + 5 GImage resized. [root @ centos ~] # Qemu-img info/data/tpp1.imgimage:/data/tpp1.imgfile format: rawvirtual size: 15G (16108027904 bytes) disk size: 400Kcluster_size: 655363) make it take effect [root @ centos ~] # Virsh destroy tpp1 [root @ centos ~] # Virsh start tpp1 [root @ centos ~] # Virsh console tpp1 // enter the sub-machine [root @ localhost ~] # Fdisk-l // check that the disk partition has been increased to 16 GBDisk/dev/vda: 16.1 GB, 16108027904 bytes16 heads, 63 sectors/track, 31211 cylindersUnits = cylinders of 1008*512 = 516096 bytesSector size (logical/physical): 512 bytes/512 bytesI/O size (minimum/optimal): 512 bytes/512 bytesDisk identifier: 0x0003aadd Device Boot Start End Blocks Id System/dev/vda1 * 3 1018 512000 83 LinuxPartition 1 does not end on cylinder bo Undary./dev/vda2 1018 20808 9973760 8e Linux LVMPartition 2 does not end on cylinder boundary ...... [root @ localhost ~] # Df-h // the disk Mount space does not increase Filesystem Size Used Avail Use % Mounted on/dev/mapper/VolGroup-lv_root 8.5G 766 M 7.3G 10%/tmpfs 246 M 0 246 M 0%/dev/shm/dev/vda1 485 M 33 M 427 M 8%/boot4) partition (the new space has not been divided for use, so continue partitioning) [root @ localhost ~] # Fdisk/dev/vdaWARNING: DOS-compatible mode is deprecated. it's stronugly recommended to switch off the mode (command 'C') and change display units to sectors (command 'U '). command (m for help): p Disk/dev/vda: 16.1 GB, 16108027904 bytes16 heads, 63 sectors/track, 31211 cylindersUnits = cylinders of 1008*512 = 516096 bytesSector size (logical/physical): 512 bytes/512 bytesI/O size (minimum/op Timal): 512 bytes/512 bytesDisk identifier: 0x0003aadd Device Boot Start End Blocks Id System/dev/vda1 * 3 1018 512000 83 LinuxPartition 1 does not end on cylinder boundary. /dev/vda2 1018 20808 9973760 8e Linux LVMPartition 2 does not end on cylinder boundary. command (m for help): nCommand action e extended p primary partition (1-4) pPartition number (1-4): 3 First cylinder (1-31211, default 1 ): 20809 Last cylinder, + cylinders or + size {K, M, G} (20809-31211, default 31211): 31211 Command (m for help): p Disk/dev/vda: 16.1 GB, 16108027904 bytes16 heads, 63 sectors/track, 31211 cylindersUnits = cylinders of 1008*512 = 516096 bytesSector size (logical/physical ): 512 bytes/512 bytesI/O size (minimum/optimal): 512 bytes/512 bytesDisk identifier: 0x0003aadd Device Boot Start End Blocks Id S Ystem/dev/vda1 * 3 1018 512000 83 LinuxPartition 1 does not end on cylinder boundary. /dev/vda2 1018 20808 9973760 8e Linux LVMPartition 2 does not end on cylinder boundary. /dev/vda3 20809 31211 5243112 83 Linux Command (m for help): wThe partition table has been altered! Calling ioctl () to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. the kernel still uses the old table. the new table will be used atthe next reboot or after you run partprobe (8) or kpartx (8) Syncing disks. [root @ localhost ~] # Reboot // restart to take effect 5) Add/dev/vda3 to lvm [root @ localhost ~] # Pvcreate/dev/vda3 // create a Physical volume "/dev/vda3" successfully created [root @ localhost ~] # Pvs // list physical volumes pv vg Fmt Attr PSize PFree/dev/vda2 VolGroup lvm2 a -- 9.51g 0/dev/vda3 lvm2 a -- 5.00g 5.00g [root @ localhost ~] # Vgextend VolGroup/dev/vda3 // Add the physical Volume to the Volume group "VolGroup" successfully extended [root @ localhost ~] # Vgs // view the volume group. You can see 5g free VG # PV # LV # SN Attr VSize VFree VolGroup 2 2 0 wz -- n-14.50g 5.00g [root @ localhost ~] # Lvs // view the logical Volume lv vg Attr LSize Pool Origin Data % Move Log Cpy % Sync Convert lv_root VolGroup-wi-ao ---- 8.54g lv_swap VolGroup-wi-ao ---- 992.00 m [root @ localhost ~] # Lvextend-l + 100% FREE/dev/VolGroup/lv_root // Add the volume group to lv_root Extending logical volume lv_root to 13.54 GiB Logical volume lv_root successfully resized [root @ localhost ~] # Resize2fs/dev/VolGroup/lv_root // refresh resize2fs 1.41.12 (17-May-2010) Filesystem at/dev/VolGroup/lv_root is mounted on /; on-line resizing requiredold desc_blocks = 1, new_desc_blocks = 1 during Ming an on-line resize of/dev/VolGroup/lv_root to 3548160 (4 k) blocks. the filesystem on/dev/VolGroup/lv_root is now 3548160 blocks long. [root @ localhost ~] # Df-h // you can see the increase to 15 GFilesystem Size Used Avail Use % Mounted on/dev/mapper/VolGroup-lv_root 14G 769 M 12G 6%/tmpfs 246 M 0 246 M 0% /dev/shm/dev/vda1 485 M 33 M 427 M 8%/boot the above steps are successful, indicating that the capacity expansion is successful, next we will conduct the second method 2, increase the disk 6, adjust the cpu and memory to view the sub-machine configuration 7, do not restart the virtual machine online add Nic 8, virtual machine migration 1) view the sub-machine status [root @ centos ~] # Virsh list -- all Id name status ---------------------------------------------------- 3 tpp3 running2) disable the sub-machine [root @ centos ~] # Virsh shutdown tpp32) export the file [root @ centos ~] # Cd/etc/libvirt/qemu/[root @ centos qemu] # virsh dumpxml tpp3.xml> tpp1.xml

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.