Rectangular depiction of a 1950s scene with a man in period clothing, busily working around an old-fashioned truck. The truck's bed is uniquely designed to resemble the surface of a hard disk, and the man is seen placing or arranging large, tangible data blocks onto it, illustrating the concept of data being loaded or mounted onto a hard disk.

Mounting a whole disk with partitions

I reinstalled one of my RPis (moving from 32 to 64 bit).

Before doing the full reinstall, I took a dump (dd) of my disk.

Usually, I create one per partition, but this was the Christmas season, and I was half occupied with feasting and half occupied with entertaining Ila. So, mistakes were made.

I ran dd if=/dev/sdb of=backup.img — but this means I can’t mount the disk directly, as it’s not a partition:

# mount backup.img /tmp/disk
mount: /tmp/disk: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.

I should’ve dd’d /dev/sdb2 instead of the entire disk.

All right, so let’s figure out what can be done… First, let’s look at the content of the image:

# fdisk -l backup.img
Disk backup.img: 111.8 GiB, 120040980480 bytes, 234455040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8297a463

Device          Boot  Start      End  Sectors  Size Id Type
backup.img1 *      8192   532479   524288  256M  c W95 FAT32 (LBA)
backup.img2      532480 34078199 33545720   16G 83 Linux

So, we can probably mount starting from sector 532480.

We can see that the sector size is 512 (which, I think, is the default for most). So, if we multiply 512 * 532480 we get 272629760.

Now we can mount the disk using the following command:

mount -o loop,offset=272629760 backup.img /tmp/disk

And that should do it.

The 2nd partition (the one with data) is now mounted and accessible under /tmp/disk.

If you need the first partition, the same can be done by running 512 * 8192 = 4194304; the following command mounts the boot partition:

mount -o loop,offset=4194304 backup.img /tmp/disk.

Posted by

in

, ,

Comments

Leave a Reply…