Mounting individual "partitions" from a ddrescue'd whole-device image file?

DouglasDD asked:

I ddrescue‘d from a sick drive device into an image file (I had enough free space, but not a spare device to copy onto). It seemed to go quite well, but now I can’t find how to mount just one partition from the entire block device image.

(All the docs that I can find refer to mounting a partition image file, not the whole device.

$ sudo ddrescue --no-split --sparse -v      \
    /dev/disk/by-id/$disk_by_id_2t_g5_boot  \
    g5_boot.img g5_boot.state-log
$ ^--no-split^--max-retries=3^
$ file g5_boot.img
g5_boot.img: data

Thanks in advance!

My answer:

If the disk image actually has a partition table, you can use kpartx to examine and/or mount it.

To view:

kpartx -l g5_boot.img

To mount:

kpartx -a g5_boot.img

If the drive was GPT formatted, you may need to add the -g option.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.