Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
what does file -s disk.img give? –  NixNinja Oct 11 '10 at 10:41
    
Basically the same thing, but doesn't indicate anything about the ext4 partition. disk.img: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, 1st sector stage2 0x3a883d7, code offset 0x48\012- –  supercheetah Oct 11 '10 at 11:23
add comment

2 Answers

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.

share|improve this answer
    
Also sfdisk -uB -l will print out that info, but using 1024-byte blocks, which can make it easier to compute offsets. –  Riccardo Murri Oct 11 '10 at 12:38
add comment

I found out the problem wasn't related to grub at all. The image had errors in it, and the fix involved running e2fsck.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.