How to mount partitions from a disk image
Nov 02
You can use the dd command to create images of disk drives, removable usb disks and so on.
If the disk you are making the image of has multiple partitions you cannot simply type “mount -o loop <image> <mount point>” to mount the resulting disk image file.
First you need to find the partitions offsets with the sfdisk command:
# sfdisk -l -uB image.iso Disk image.iso: cannot get geometry Disk image.iso: 973 cylinders, 255 heads, 63 sectors/track Warning: The partition table looks like it was made for C/H/S=*/4/32 (instead of 973/255/63). For this listing I'll assume that geometry. Units = blocks of 1024 bytes, counting from 0 Device Boot Start End #blocks Id System image.iso1 * 16 31231 31216 e W95 FAT16 (LBA) image.iso2 32256 7265599 7233344 83 Linux image.iso3 0 - 0 0 Empty image.iso4 0 - 0 0 Empty
With this information you can calculate the starting offset of each partition by multiplying the start block by the block units in bytes (1024 bytes in this case):
# echo $(( 32256 * 1024 )) 33030144 # echo $(( 16 * 1024 )) 16384
Mounting is easy now, you specify the file system type and the partition offset. To mount the first partition on the example file above:
# mount -o loop,offset=16384 -t vfat image.iso /mnt/
To mount the second partition:
# mount -o loop,offset=33030144 -t ext2 image.iso /mnt/
Here you go! Hope it helps!
RSS