mount >
Pradeep’s blog ∞
2007-06-06
How do you mount a disk image with multiple partitions? If an image contains a single partition, we can simply use a command like the following.
mount -o loop image_file /mnt
This will not work if the image_file is a complete disk image containing multiple partitions. I found a neat trick here that explains how to do it. The idea is to get the partition offset and then mount it as follows.
mount -o loop,offset=some_number image_file /mnt
The offset can be found by running fdisk -ul image_file. Detailed information is available here. Enjoy!
2. Mounting the disk image ∞
From Creating and using disk images mini-HOWTO
The clean way ∞
First, we need to determine the offset of the partition. This is quite easy: just type fdisk -ul <device>. The option -ul means list the partitions on the device and assume a unit size of 512 byte. This looks something like this:
fdisk -ul /dev/sda
Disk /dev/sda: 256 MB, 256376832 bytes 8 heads, 62 sectors/track, 1009 cylinders, total 500736 sectors Units = sectors of 1 * 512 = 512 bytes Device Boot Start End Blocks Id System /dev/sda1 * 62 19839 9889 4 FAT16 <32M /dev/sda2 19840 231135 105648 83 Linux /dev/sda3 231136 442431 105648 83 Linux /dev/sda4 442432 471199 14384 83 Linux
Now all we need to do is a little math to get the offset: we need to multiply the start block by 512. E.g. if we wanted to mount the first partition we’d have an offset of 62 * 512 = 31744. The second partition has an offset of 19840 * 512 = 10158080.
Now that we have the offset we can mount the partition:
mount -o loop,offset=10158080 image.bootable /mnt
This would mount the second partition on /mnt. Linux recognizes it as ext3 if it is formatted as ext3 and the kernel supports ext3, so no need for a -t ext3 option to mount.
The dirty way ∞
There is also a hard way to find the formatted partitions if you can’t calculate the offsets for some reason:
for <span class="footnote_referrer" ><a><sup id="footnote_plugin_tooltip_61530_1" class="footnote_plugin_tooltip_text" onclick="footnote_moveToAnchor_61530('footnote_plugin_reference_61530_1');" >[ 1 ]</sup ></a><span id="footnote_plugin_tooltip_text_61530_1" class="footnote_tooltip" >i=0 ; $i < 10000 ; i=$i + 1</span ></span><script type="text/javascript"> jQuery('#footnote_plugin_tooltip_61530_1').tooltip({ tip: '#footnote_plugin_tooltip_text_61530_1', tipClass: 'footnote_tooltip', effect: 'fade', predelay: 0, fadeInSpeed: 200, delay: 400, fadeOutSpeed: 200, position: 'top center', relative: true, offset: [1, 0], });</script> ; do mount -o loop,offset=$<span class="footnote_referrer" ><a><sup id="footnote_plugin_tooltip_61530_2" class="footnote_plugin_tooltip_text" onclick="footnote_moveToAnchor_61530('footnote_plugin_reference_61530_2');" >[ 2 ]</sup ></a><span id="footnote_plugin_tooltip_text_61530_2" class="footnote_tooltip" >$i * 512</span ></span><script type="text/javascript"> jQuery('#footnote_plugin_tooltip_61530_2').tooltip({ tip: '#footnote_plugin_tooltip_text_61530_2', tipClass: 'footnote_tooltip', effect: 'fade', predelay: 0, fadeInSpeed: 200, delay: 400, fadeOutSpeed: 200, position: 'top center', relative: true, offset: [1, 0], });</script> image.bootable /mnt && break done
If there is a partition within the first 10000 blocks, it gets mounted eventually :-) Just type mount to get the offset…

ported, and also partially-cached a related (dead-link) article