How to Mount One Partition from an Image File That Contains Multiple Partitions on Linux

How to mount one partition from an image file that contains multiple partitions on Linux?

Let's say $IMAGE is set to the path to your image file.
You could write a small script by using

fdisk -u sectors -l $IMAGE

to get a list of partitions inside the image. And then use a sequence of

mount -o ro,loop,offset=$OFFSET -t auto $IMAGE /media/$DEST

Where offset is calculated means the info from fdisk (start sector * size of a sector in bytes) and $DEST a unique name for each of the partitions.

That's not directly the solution but I hope a pretty good indication on how to realize it. If you make the job once, you've some small nice beginning for some forensic toolkit!​​​​​​​​​​​​​​​​​​​​​

How to mount one partition from an image file that contains multiple partitions on Linux?

Let's say $IMAGE is set to the path to your image file.
You could write a small script by using

fdisk -u sectors -l $IMAGE

to get a list of partitions inside the image. And then use a sequence of

mount -o ro,loop,offset=$OFFSET -t auto $IMAGE /media/$DEST

Where offset is calculated means the info from fdisk (start sector * size of a sector in bytes) and $DEST a unique name for each of the partitions.

That's not directly the solution but I hope a pretty good indication on how to realize it. If you make the job once, you've some small nice beginning for some forensic toolkit!​​​​​​​​​​​​​​​​​​​​​

mounting multiple partitions from a disk image file

Consider a different approach that doesn't need to take some offset calculations. Let's first create a sample file with DOS partition table:

truncate -s 20M file.img
printf "%s\n" o n p 1 '' +10M n p 2 '' '' p w | fdisk ./file.img

then you can:

loopf="$(sudo losetup -f)"      # ie. /dev/loop0 for example
sudo losetup "$loopf" ./file.img
sudo partprobe "$loopf"

then I'll get:

$ ls /dev/loop0*
/dev/loop0 /dev/loop0p1 /dev/loop0p2

and you can use p1 and p2 as normal partitions, as you would normally:

for i in "$loopf"p*; do
sudo mount "$i" "somwheere/$(basename "$i")"
done

after you're done, umount all directories and disconnect loop device with:

sudo losetup -d "$loopf"

Is there a way to mount a dd based file as a disk for cstore pool

You havent created a partition table on the virtual disk.

Do the DD as above, then run the output of that through gparted or fdisk and creat a partition table

then do an losteup losetup -f diskImage4

then read the partitions partx -a /dev/loop0 (or whatever the loop device is created as

Then do a lsblk

loop0 and loop0p1 should be visible



Related Topics



Leave a reply



Submit