Loop mounting a partition from a full disk image

This post was written by eli on January 22, 2011
Posted Under: Linux

This is documented in a lot of other places, but I’d like to be able to find it quickly, so here it is in my own blog.

Suppose I want to mount the partition which is /dev/sda3 in normal life:

# fdisk -lu linux.img
You must set cylinders.
You can do this from the extra functions menu.

Disk linux.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x00000000

        Device Boot      Start         End      Blocks   Id  System
archlinux.img1   *          63      208844      104391   83  Linux
archlinux.img2          208845      738989      265072+  82  Linux swap / Solaris
archlinux.img3          738990     6072569     2666790   83  Linux
archlinux.img4         6072570     6281414      104422+  83  Linux
# mount -o loop,offset=$((512*738990)) linux.img mnt/

The trick is in the -u flag given to fdisk, which makes it give the number in sectors. It’s really this simple.

Add a Comment

required, use real name
required, will not be published
optional, your blog address