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 used dd to backup a 80GB drive

dd if=/dev/sdb of=~/sdb.img

Now I need to access some files on that drive, but I don't want to copy the ".img" back over the drive.

mount ~/sdb.img /mnt/sdb doesn't work either. It returns :

mount: you must specify the filesystem type

I tried to find the filesystem type with file -s

fox@shoebox $ file -s sdb.img
sdb.img: x86 boot sector; partition 1: ID=0x12, starthead 1, startsector 63, 10233342 sectors; partition 2: ID=0xc, active, starthead 0, startsector 10233405, 72517410 sectors; partition 3: ID=0xc, starthead 0, startsector 82750815, 73545570 sectors, code offset 0xc0

Is it possible to mount sdb.img, or must I use dd to restore the drive?

share|improve this question
add comment

1 Answer

up vote 20 down vote accepted

When you use dd on /dev/sdb instead of /dev/sdb1 or /dev/sdb2, you copy all the partitions from the said drive into one file.

You must mount each partition separately.


To mount a partition from a file, you must first find out where in the file that partition resides.

Using your output from file -s sdb.img we find the startsectors for each partition:

sdb.img: x86 boot sector; partition 1: ID=0x12, starthead 1, startsector 63, 10233342 sectors; partition 2: ID=0xc, active, starthead 0, startsector 10233405, 72517410 sectors; partition 3: ID=0xc, starthead 0, startsector 82750815, 73545570 sectors, code offset 0xc0

Partition     Startsector
1                   63
2                   10233405
3                   82750815

To mount a single partition, where X is the startsector of that partition, run:

mount ~/sdb.img /mnt/sdb -o offset=$((X*512))

So to mount the second partition, you will have to run:

mount ~/sdb.img /mnt/sdb2 -o offset=$((10233405*512))

sidenote: make sure that /mnt/sdb2 exists before you run this.

Have fun!


update: In the answer, I assumed that the sector size for you image was 512, please see this question on how to calculate that.

share|improve this answer
    
worked great thanks –  fox Oct 3 '10 at 19:45
    
You can also get the startsectors in a tabular format using file -l sdb.img as posted in the answer of your question: unix.stackexchange.com/questions/2668/… –  student Aug 19 '12 at 10:33
    
@student: Only a correction for future readers: That would be fdisk -l not file -l. –  Sukminder Apr 27 '13 at 22:29
    
Further clarification - you can get the number of 512 byte sectors by adding the -u option to that command - so fdisk -u -l sdb.img –  Aaron Mason Apr 10 at 6:54
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.