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
This 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
|
|
GNU Parted 2.1 Using /home/secret/dd-sda.raw Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: (file) Disk /home/secret/dd-sda.raw: 36.4GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 32.3kB 16.1GB 16.1GB primary ext3 boot |
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.
|
|
(parted) unit Unit? [compact]? b (parted) p ... Number Start End Size Type File system Flags 1 32256B 16105098239B 16105065984B primary ext3 boot |
# mount ./dd-sda.raw -t ext3 /mnt -o loop,offset=32256
Bulls-eye!
I wrote a post similar to this. Luckily there is an easier way to mount one of those partitions without having to do all of the math. Check out “The Easy Way” in the following blog post and let me know if it works for you.
http://dustymabe.com/2012/12/15/mounting-a-partition-within-a-disk-image/
Dusty