Mount a partition from a raw file dd backup of a whole disk


I backed up a disk on the fly to another host using dd’s output piped to netcat on the host I was backing up, and netcat’s output piped back to dd as input on the receiving end.

Sender: # dd if=/dev/sda | nc -l 1234
Receiver: # nc 192.168.1.2 1234 | dd of=/opt/dd-sda.raw

red white bullseye target with arrowThis worked great, except it turns out I don’t need the whole disk. I just want a few things out of the 1st partition. Oops.

When dealing with real block devices, you assumed you’ll have a direct point of access to each partition in /dev. Partitions on sda show up as /dev/sda1, /dev/sda2, etc. But this is just a plain old file, not a friend to udev.

This problem can also happen when you change the partition table but the disk was in use for some reason and your updates are not reported immediately.

So how do you mount a partition from a raw file of the whole disk?

Not to fear, mount options are here! You can include the offset of the partition as an option to the mount command to get right to any specific partition no matter where it starts.

To find out the offset, I used parted. The offset is listed for each partition just by printing the partition table.

# parted ./dd-sda.raw

But how precise is output in kB? 32.3kB. As it turns out, not enough. 33075? 32300? Nope. Change the output to bytes and reprint.

# mount ./dd-sda.raw -t ext3 /mnt -o loop,offset=32256

Bulls-eye!


Posted on July 20th, by admica in Linux, storage.

One thought on “Mount a partition from a raw file dd backup of a whole disk

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">