Monday, January 18, 2010

HOWTO mount a qcow disk image with multiple partitions

To mount a qcow disk image directly you first need to convert it to raw:

qemu-img convert -O raw disk0.qcow2 disk0.dd

Take a look at the partitions using disktype or fdisk -l:

disktype disk0.dd

--- disk0.dd
Regular file, size 11.72 GiB (12583960576 bytes)
GRUB boot loader, compat version 3.2, boot drive 0xff
DOS/MBR partition map
Partition 1: 9.312 GiB (9999007744 bytes, 19529312 sectors from 32)
Type 0x83 (Linux)
Ext3 file system
UUID 4BF80E7C-244E-43EE-BEA5-0A3D97188C68 (DCE, v4)
Volume size 9.312 GiB (9999007744 bytes, 2441164 blocks of 4 KiB)
Partition 2: 1.863 GiB (1999962112 bytes, 3906176 sectors from 19529344)
Type 0x82 (Linux swap / Solaris)
Linux swap, version 2, subversion 1, 4 KiB pages, little-endian
Swap size 1.863 GiB (1999953920 bytes, 488270 pages of 4 KiB)

Our first partition is 32 sectors from the beginning, which is an offset of 32 * 512 = 16384 bytes.

Mount it:

mount -t ext3 disk0.dd /mnt/temp/ -o loop,offset=16384

1 comment:

Tristan Grimaux said...

You can use kpartx to mount the disk once its in raw format:

kpartx disk0.dd

and

losetup -a

will show the mappings. You can access the partitions from the listing there.

with losetup --detach /dev/dev you detach the virtual devices attached