Selasa, 3 Januari 2012

Mount qemu harddisk image in linux

1. Check the image format
qemu-img info image.img
image: image.img
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 201M
cluster_size: 65536
2. second step is to convert the image format to RAW format:

qemu-img convert –f qcow2 image.img –O raw image-raw.img

3. get the offset for mount option

fdisk -u -l image-raw.img

Disk image-raw.img: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
image-raw.img1 * 16065 4192964 2088450 83 Linux

Then I have the sector size (512 in my case) and the offset (16065, start sector of my partation), so the offset should be 512*16065= 8225280 (btw, you can calculate with bc: echo ‘512*16065’ | bc)

4. Create mount point mkdir /mnt/image

5. mount the image

mount -t ext4 -o loop,offset=8225280 image-raw.img /mnt/image

file type (-t ext4 ) can be identify from fdisk output above. System -- Linux. alternatively you can run the image under qemu to see the OS. i.e qemu image-raw.img


Tiada ulasan: