Two months ago, I wrote an article "how to mount an image file". At that time, I didn't write the qcow2 mounting method into it. I just wrote a blog post about qcow2, let's talk about the client image in the Mount qcow2 format. Qcow2 is currently the recommended guest image file format for qemu (qemu-KVM). It is widely used in KVM and xen virtualization.
You can use the tool qemu-NBD that comes with qemu to mount a client. The procedure is as follows:
(Qemu-NBD will also get the qemu-NBD tool after the normal qemu is compiled and installed. It seems to be in the "qemu-common" RPM package in fedora .)
1. Check the system's kernel support for the NBD module (NBD: network block device) and load the module NBD., As follows:
View code bash
12345678910111213141516 |
[[email protected] kvm_demo]# grep NBD /boot/config-3.5.0CONFIG_BLK_DEV_NBD=m[[email protected] kvm_demo]# modinfo nbdfilename: /lib/modules/3.5.0/kernel/drivers/block/nbd.kolicense: GPLdescription: Network Block Devicesrcversion: 56F31584CC2EB73E6F1DA69depends:intree: Yvermagic: 3.5.0 SMP mod_unload modversionsparm: nbds_max:number of network block devices to initialize (default: 16) (int)parm: max_part:number of partitions per device (default: 0) (int)parm: debugflags:flags for controlling debug output (int)[[email protected] kvm_demo]# modprobe nbd max_part=16[[email protected] kvm_demo]# lsmod | grep nbdnbd 7593 0 |
If the current kernel has not compiled the NBD module, you need to re-compile the module (or compile the entire kernel). When compiling the kernel, select "Device Drivers-> Block devices-> network block Device Support" when "make menuconfig" is used to configure the kernel ".
2. Map the qcow2 image to a network block device (NBD)The command is as follows:
View code bash
12345 |
[[Email protected] kvm_demo] # qemu-NBD-C/dev/nbd0 rhel6u3. qcow2 [[email protected] kvm_demo] # ll/dev/nbd0 * # Check BRW-RW ---- 1 root disk 43, 0 Nov 1/dev/nbd0brw-rw ---- 1 root disk 43, 1 Nov 1/dev/nbd0p1brw-rw ---- 1 root disk 43, 2 Nov 1/dev/nbd0p2 |
The qemu-NBD tool is qemu disk Network block device server. You can run the "qemu-NBD-help" command to view the help information.
3. Just use the partition of the network block device that you just mapped as that of a common block device. The command line is as follows:
View code bash
1234567 |
[[Email protected] kvm_demo] # Mount/dev/nbd0p1/mnt/[[email protected] kvm_demo] # cd/mnt/[[email protected] MNT] # lsbin cgroup etc lib lost + found MISC net proc sbin srv tmp varboot Dev home lib64 media MNT opt root SELinux sys USR [[email protected] MNT] # cd root/[[email protected] root] # Touch nbd-test.txt # create a file here to test it, if you use this qcow2 image as the guest, you can also see the modified file. |
4. After using the qcow2 image, uninstall the mounted NBD device and remove the association between the qcow2 image and the NBD device.
View code bash
123 |
[[email protected] kvm_demo]# umount /mnt/[[email protected] kvm_demo]# qemu-nbd -d /dev/nbd0/dev/nbd0 disconnected |
If your qcow2 file contains LVM partitions, refer to the second half of my blog article below (about LVM partition mounting ):
Http://smilejay.com/2012/08/mount-an-image-file/
For more information about NBD in Linux, see the following webpage:
Http://nbd.sourceforge.net/
Source: http://zhumeng8337797.blog.163.com/blog/static/100768914201341755913109/
[Reprint] how to mount an image file in qcow2 format (how to mount a qcow2 image)