# With the command pv it is possible to clone a drive, how do I mount it? [duplicate]

tisaconundrum 09/13/2018. 3 answers, 286 views

I was able to backup a drive using the following command.

pv -EE /dev/sda > disk-image.img

This is all well and good, but now I have no way of seeing the files unless I use this command

pv disk-image.img > /dev/sda

This, of course, writes the data back to the disk which is not what I want to do. My question is what can I do to mount the .img file itself instead of just writing back to a disk?

I've tried mounting using loop but it seems to complain about an invalid NTFS.

$mount -o loop disk-image.img mount: disk-image.img: can't find in /etc/fstab.$ mount -o loop disk-image.img /mnt/disk-image/
NTFS signature is missing.
Failed to mount '/dev/loop32': Invalid argument
The device '/dev/loop32' doesn't seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?

Antonio Petricca 09/14/2018.

You backed up the whole disk including the MBR (512 bytes), and not a simple partition which you can mount, so you have to skip the MBR.

sudo losetup -o 512 /dev/loop0 disk-image.img
sudo mount -t ntfs-3g /dev/loop0 /mnt 

Edit: as suggested by @grawity:

sudo losetup --partscan /dev/loop0 disk-image.img
sudo mount -t ntfs-3g /dev/loop0 /mnt 

telcoM 09/14/2018.

As others have already pointed out,

sudo losetup /dev/loop0 /path/to/disk-image.img

will set up a virtual block device that can be used to access the file, but it does not give you easy access to the partitions.

However, there is another command you can use after that to gain access to all the partitions within the disk image file, without manually calculating partition offsets:

sudo kpartx -a /dev/loop0

This will read the partition table within the disk image, and will create devices like /dev/mapper/loop0p1, /dev/mapper/loop0p2 etc. for all the partitions. You can use those to mount the partitions normally.

(If you don't remember what each partition is, you could use fdisk -l /dev/loop0 to view the partition table within the disk image; just note that many versions of fdisk will display the names of the partition devices a little oddly in this situation.)

Once you've done accessing the disk image, you can undo this set-up by unmounting the partitions you've mounted, and then using two commands:

sudo kpartx -d /dev/loop0   # remove the /dev/mapper/loop0pN partition mappings
sudo losetup -d /dev/loop0  # disconnect the image file from the loop device

The kpartx command was originally developed as a tool for multipathed devices (as used with SAN storage systems), but it is perfectly usable with disk images too.

K7AAY 09/13/2018.

Install p7zip-full if you don't have it already, then take a look with

sudo 7z  /pathtowhereitis/whatever.img