关于QCOW2镜像操作的一些资料

将qcow2镜像文件挂载到linux文件系统中

原文链接:

简化版:

qemu-nbd -c /dev/nbd0 xxxx.qcow2 
ll /dev/nbd0*
brw-rw---- 1 root disk 43, 0 Nov  1 20:51 /dev/nbd0
brw-rw---- 1 root disk 43, 1 Nov  1 20:51 /dev/nbd0p1
brw-rw---- 1 root disk 43, 2 Nov  1 20:51 /dev/nbd0p2
mount /dev/nbd0p1 /mnt/

格式化QCOW2镜像

原文链接:

http://libguestfs.org/virt-frmat.1.html

virt-format -a disk.qcow

可选的参数:
–filesystem=[ext3|ntfs|vfat|…]

扩容QCOW2镜像

http://blogs.perl.org/users/rurban/2013/11/how-to-resize-a-ntfs-qemu-qcow2-image-the-easy-way.html

$ sudo su
$ ls /var/lib/libvirt/images/*.qcow2
$ qemu-img resize /var/lib/libvirt/images/windows_x64.qcow2 +5GB
$ modprobe nbd max_part=63
$ qemu-nbd -c /dev/nbd0 /var/lib/libvirt/images/windows_x64.qcow2
$ # fdisk -l /dev/nbd0 # or better
$ kpartx /dev/nbd0 # to check the partitions and sizes
$ ntfsresize --info /dev/nbd0 # to check if the volumes are not dirty
$ gparted /dev/nbd0 # enhance the partition size to max
$ killall qemu-nbd

Start the vm and let windows do the chkdsk /f (in win8 automatically)
In winxp you might need to do ntfsresize -x /dev/nbd0p2 manually