How can I mount a partition from dd-created image of a block device (e.g. HDD) under Linux?

104,844

Solution 1

Nowadays, there is a better way, no need to use offsets or kpartx anymore:

losetup --partscan --find --show disk.img

mount /dev/loop0p1 /mnt

to free up loop0, use after umount:

losetup -d /dev/loop0

Solution 2

I ran into this problem today and wanted to update the answers just as a reminder for myself. Instead of calculating the offset on your own, you can use a tool that provides you with mountable devices from a dd image: kpartx

http://robert.penz.name/73/kpartx-a-tool-for-mounting-partitions-within-an-image-file/

http://linux.die.net/man/8/kpartx

In the given case, it would need something like

sudo kpartx -a image750.img
sudo mount /dev/mapper/loop1p1 /mount/point -o loop,ro

where loop1p1 stands for the first partition, loop1p2 for the second, etc.

Solution 3

You've got the first part: fdisk -l to find the start offset. Take that number, multiply by 512, and you'll get the offset option to mount. So, for sda1 in your case, 5 * 512 = 2560. Then run the mount:

mount -o loop,offset=2560 -t auto /path/to/image.dd /mount/point

Solution 4

I believe loopmounting is the answer -

sudo mkdir /path/to/dir/
mount -o loop example.img /path/to/dir/

The above should mount it under that directory.

This should unmount it:

umount /path/to/dir

Solution 5

Loopmounting is only part of the answer.

Look at http://wiki.edseek.com/guide:mount_loopback#accessing_specific_partitions_in_the_image for help on specifying the partition. I think mount -o loop,offset=32256 /path/to/image750.img /mnt will work for you. but you really should read the mentioned tutorial.

Share:
104,844

Related videos on Youtube

Deleted
Author by

Deleted

Updated on September 17, 2022

Comments

  • Deleted
    Deleted almost 2 years

    I have an image of the entire disk created using dd. The disk structure follows:

    kent@cow:~$ sudo fdisk -l
    
    Disk /dev/sda: 750.1 GB, 750156374016 bytes
    255 heads, 63 sectors/track, 91201 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0x000b8508
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           5       90872   729929303+  83  Linux
    /dev/sda2           90873       91201     2642692+   5  Extended
    /dev/sda5           90873       91201     2642661   82  Linux swap / Solaris
    

    The image was created using:

    dd if=/dev/sda of=image750.img
    

    How would I, if it is possible, mount /dev/sda1 from the image so that I'm able to read the contents?

    It's not an option to clone the HDD again, I know how to do it if I had only cloned the single partition by itself. I hope it's still possible with the current image.

  • quack quixote
    quack quixote over 14 years
    the offset looks wrong; that corresponds to a partition start of 63 (<i>63 * 512 = 32256</i>). the offset in baumgart's answer looks more correct for this situation. the link is a good reference, but it'd be a better answer if you took the time to summarize the steps or commands needed for this procedure. thanks!
  • Cutter
    Cutter over 9 years
    On my Ubuntu 14.04 installation, losetup doesn't provide a --partscan option.
  • Ciro Santilli Путлер Капут 六四事
    Ciro Santilli Путлер Капут 六四事 almost 8 years
    @Cutter it was added in util-linux 2.21, Ubuntu 16.04. :-)
  • Randy Syring
    Randy Syring about 6 years
    Having used kpartx first, which mounts the partitions like /dev/mapper/loop3p1, I just want to point out that losetup creates the devices like /dev/loop0p1. The answer notes that, but I read over it probably 10 times. :/
  • Warren  P
    Warren P almost 4 years
    This is a good example of link rot. That page is gone.
  • mgutt
    mgutt over 3 years
  • Iceberg
    Iceberg over 2 years
    losetup --partscan --find --show disk.img might give you /dev/loop1, in which case you'll need mount /dev/loop1p1 /mnt.