Mounting partitions from a dd image
UPDATE: Some users on HN [1] and reddit [2][3][4] pointed out that the fdisk
method is outdated. The same result can be achieved without using offsets with:
DEV=$(sudo losetup --partscan --find --read-only --show x.dd)
mkdir partition_1 partition_2
sudo mount -t ntfs -o ro "${DEV}p1" partition_1
sudo mount -t ntfs -o ro "${DEV}p2" partition_2
The old way - using fdisk
When x.dd
is a disk clone created with one of the dd
commands, first we’ll try to detect partitions:
$ fdisk -l x.dd
Disk x.dd: 94.1 MiB, 98705408 bytes, 192784 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: 0xfc23b344
Device Boot Start End Sectors Size Id Type
x.dd1 63 96389 96327 47M 7 HPFS/NTFS/exFAT
x.dd2 96390 192779 96390 47.1M 7 HPFS/NTFS/exFAT
This means that our x.dd
image has two partitions, both NTFS. The offset of the first partition is 63 units, and the offset of the second partitions is 96,390 units. Each unit is of size 512 bytes.
In order to mount those partitions, we’ll use the mount
command with the offset
option:
mkdir partition_1 partition_2
mount -t ntfs -o ro,offset=$((512*63)) x.dd partition_1
mount -t ntfs -o ro,offset=$((512*96390)) x.dd partition_2