kvm--virtual machine Disk File Read summary

Source: Internet
Author: User
Tags disk usage

The KVM virtual machine disk mount is not a smooth ride. Xen virtualization defaults to the raw format of the disk, can be mounted directly, KVM if the use of raw can also be mounted directly, and the Xen disk mount the same way.

This article originates from: http://koumm.blog.51cto.com

1.KVM virtualization compared to Xen virtualization, there are many tools and methods, this article enumerates the following ideas:

(1) The RAW format of the disk can be mounted directly, you can convert the QCOW2 disk into raw format and mount

Conversion Example:qemu-imgconvert-fraw-oqcow2/data/raw.img/data/qcow2.img

Raw format disk mount content can refer to Xen virtual machine disk File mount for Xen Virtualization Combat Series (11)

(2) Mount the qcows format disk by compiling the Install QEMU-NBD tool

QEMU-NBD tool is not installed by default, need to compile the installation, the content to be tested, if you really need to also refer to the idea of 1 to solve.
(3) Create a KVM virtual machine profile by creating a KVM Environment Mount virtual disk boot virtual machine

This content can be referenced in KVM Virtualization learning Notes (vii) of KVM virtual machine clones

(4) directly modify and read Qcow2 virtual disk files via Libguestfs-tools tool

This article mainly tests the Libguestfs-tools tool for testing.

Example of using the 2.libguestfs-tools tool

(1) Confirm that the installation of the Libguestfs-tools tool is not installed and can be installed by Yum.

After the installation is complete, many commands starting with virt-will be installed, and the following will be a general introduction to using these commands.

12345678 [[email protected] ~]# virvirsh                  virt-df                virt-inspector2        virt-p2v-server        virt-tar-invirt-alignment-scan    virt-edit              virt-install           virt-pki-validate      virt-tar-outvirt-cat               virt-filesystems       virt-list-filesystems  virt-rescue            virt-v2vvirt-clone             virt-format            virt-list-partitions   virt-resize            virt-viewervirt-convert           virt-host-validate     virt-ls                virt-sparsify          virt-whatvirt-copy-invirt-image             virt-make-fs           virt-sysprep           virt-win-regvirt-copy-out          virt-inspector         virt-manager           virt-tar               virt-xml-validate

(2) command using parameter format

12 virt-df  [--options] -d domnamevirt-df [--options] -a disk.img [-a disk.img ...]

Usually two ways:-D is the domain name method,-A is the direct access to the disk file mode.

3.virt-cat command

View the/etc/passwd file inside the virtual machine directly, similar to the Cat command.

1 [[email protected] ~]# virt-cat -d oeltest01 /etc/passwd

4.virt-edit command

Edit the files inside the virtual machine directly, similar to the VI command.

Note: The virtual machine must be in a shutdown state, otherwise the following prompt will appear:

12345 libguestfs: error: error: domain isa live virtual machine.Writing to the disks of a running virtual machine can cause disk corruption.Either use read-only access, or if the guest is running the guestfsd daemonspecify live access.  In most libguestfs tools these options are --ro or--live respectively.  Consult the documentation forfurther information.

1 [[email protected] ~]# virt-edit -d oeltest01 /etc/rc.local

Can be edited by the VI command.

5.VIRT-DF command

View disk usage directly inside the virtual machine, similar to the Df-h command.

1 [[email protected] ~]# virt-df  -h oeltest01

The Virt-filesystems command is similar to the above:

123 [[email protected] ~]# virt-filesystems -d oeltest01/dev/sda1/dev/vg/root
6.virt-copy-out command

Copy the disk files from the virtual machine directly onto the local disk, similar to the CP command.

(1) Copy the passwd file from the oeltest01 virtual machine to the local/root directory

1 [[email protected] ~]# virt-copy-out -d oeltest01 /etc/passwd /root/

(2) Copy the/etc/from the oeltest01 virtual machine to the local/root directory

1 [[email protected] ~]# virt-copy-out -d oeltest01 /etc /root/

This command is useful, or you can specify the virtual machine disk file directly for the command.

#查看虚拟机所有磁盘文件

By directly reading the contents of the disk file.

1 [[email protected] ~]# virt-copy-out -a /data/test01.qcow2 -a /data/test01_add01.qcow2 /etc/sysconfig/network-scripts/ifcfg-eth0 /root/

7.virt-copy-in command

Copy the local disk files on the virtualized platform directly onto the virtual machine disk, similar to the CP command.

Copy local/root/etc.tar.gz files to the virtual machine/root directory

1 [[email protected] ~]# virt-copy-in-d oeltest01 /root/etc.tar.gz /root/

Note: Virtualization must be powered off and can be turned on for verification.

123456789101112131415161718192021 [[email protected] ~]# virsh start oeltest01域 oeltest01 已开始[[email protected] ~]#[[email protected] ~]#[[email protected] ~]# virsh console oeltest01连接到域 oeltest01Escape character is^]Oracle Linux Server release 5.8Kernel 2.6.18-308.el5 on an x86_64test01 login: rootPassword:Last login: Wed Sep 1105:21:11on ttyS0[[email protected] ~]# lltotal 10828-rw------- 1root root     1225Sep 1103:54 anaconda-ks.cfgdrwxr-xr-x 2root root     4096Sep 1104:17Desktop-rw-r--r-- 1root root 11006264Sep 162013etc.tar.gz-rw-r--r-- 1root root    36587Sep 1103:54install.log-rw-r--r-- 1 root root     3828Sep 1103:53install.log.syslog[[email protected] ~]#[[email protected] ~]#

The text reads the contents of the virtual machine disk file to this, there are many command commands that can be tested.

kvm--virtual machine Disk File Read summary

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.