Mount a block device image

How to mount a block device image

Task: An image of a block divice has been created with dd for data recovery purposes. Mount the filesystem from the image and access files.

Review image partition information

Confirm that the image size matches the size of the source block device. If the size is incorrect review the block device options or try another program such as ddrescue to read a failing block device. In this case the image is the byte size reported by the block device and the partition information appears valid for the image.

$ ls -l adrian-connor.img
-rw-r--r-- 1 root root 80000000000 Oct 10 20:26 adrian-connor.img

$ fdisk -lu adrian-connor.img
Disk adrian-connor.img: 74.51 GiB, 80000000000 bytes, 156250000 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: 0xf52bcf0e

Device             Boot Start       End   Sectors  Size Id Type
adrian-connor.img1         63 156232124 156232062 74.5G  7 HPFS/NTFS/exFAT

Mount the image

losetup can be used to expose the block image as a device with partitions included. However, it is also possible to skip this step and mount the partition using the partition offset. In this case it starts at 63 sectors * 512 bytes offset into the device. Since this is a block device image as opposed to a block loop that exposes partition information we will tell mount to offset into the image at the partiion start.

# mount -o loop,ro,offset=$((512 * 63)) -t ntfs adrian-connor.img /mnt/d1
# mount |grep d1
/media/aun/af376427-5802-4e1e-aafb-d0893ce855ae/adrian-connor.img on /mnt/d1 type fuseblk (ro,relatime,user_id=0,group_id=0,allow_other,blksize=4096)
# df /mnt/d1
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/loop8      78116028 20436396  57679632  27% /mnt/d1

Read data from image as needed

Now the disk is mounted under /mnt/d1 as read only. Recover files as needed. When finished umount /mnt/d1 as root.


Recent posts

Alter system calls with LD_PRELOAD

Mount a block device image

DevOps notes

Linux kernel module basics

zpool reimport


Archives

2021 (5)
2019 (2)
2018 (7)