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] ~]# vir
virsh virt-df virt-inspector2 virt-p2v-server virt-tar-
in
virt-alignment-scan virt-edit virt-install virt-pki-validate virt-tar-out
virt-cat virt-filesystems virt-list-filesystems virt-rescue virt-v2v
virt-clone virt-format virt-list-partitions virt-resize virt-viewer
virt-convert virt-host-validate virt-ls virt-sparsify virt-what
virt-copy-
in
virt-image virt-make-fs virt-sysprep virt-win-reg
virt-copy-out virt-inspector virt-manager virt-tar virt-xml-validate
|
(2) command using parameter format
12 |
virt-df [--options] -d domname virt-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 is a 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 daemon specify live access. In most libguestfs tools these options are --ro or --live respectively. Consult the documentation for further 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
连接到域 oeltest01
Escape character
is
^]
Oracle Linux Server release
5.8
Kernel
2.6
.
18
-
308
.el5 on an x86_64
test01 login: root
Password:
Last login: Wed Sep
11
05
:
21
:
11
on ttyS0
[[email protected] ~]# ll
total
10828
-rw-------
1
root root
1225
Sep
11
03
:
54 anaconda-ks.cfg
drwxr-xr-x
2
root root
4096
Sep
11
04
:
17
Desktop
-rw-r--r--
1
root root
11006264
Sep
16
2013
etc.tar.gz
-rw-r--r--
1
root root
36587
Sep
11
03
:
54
install.log
-rw-r--r--
1 root root
3828
Sep
11
03
:
53
install.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