Finding the offset for ext4 partition

ext4loop-devicemount

I've created an image of my hd with dd, but grub was installed on it, and I'm trying to figure out how to mount the image file, but mount doesn't recognise it as an ext4 partition because of the grub header.

I know it's there because when I run file -k disk.img, I get the following:

disk.img: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, 1st sector stage2 0x3a883d7, code offset 0x48\012- Linux rev 1.0 ext4 filesystem data, UUID=6d1e45d1-8fac-4995-839b-fa5691a898ad (needs journal recovery) (errors) (extents) (large files) DOS executable (COM), boot code

Anyone have any thoughts as to how I could find the beginning of the partition so that I can tell mount (well, losetup really) where the offset is to load the partition?

Best Answer

Parted should be able to read disk image from file and interpret the partition table. So use

parted -s disk.img unit s print

For my (testing) disk image it gives:

# parted -s /root/sdd.img unit s print
Model:  (file)
Disk /root/sdd.img: 16384s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start  End     Size   Type     File system  Flags
 1      5s     7812s   7808s  primary               type=83
 2      7872s  16383s  8512s  primary               type=83

You can see which sector each partition starts (and ends) at.

Related Question