The method below works to mount a primary partition from the disk image, but fails trying to mount a logical partition under an extended partition. Is there a way around this? I have 3 logical partitions under the extended partition and none of these will mount using the steps below.

Get the partition layout of the image

$ sudo fdisk -lu sda.img
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
  Device Boot      Start         End      Blocks   Id  System
sda.img1   *          56     6400000     3199972+   c  W95 FAT32 (LBA)

Calculate the offset from the start of the image to the partition start

Sector size * Start = (in the case) 56 * 512 = 28672

Mount it on /dev/loop0 using the offset

sudo losetup -o 28672 /dev/loop0 sda.img

Now the partition resides on /dev/loop0. You can fsck it, mount it etc

sudo fsck -fv /dev/loop0
sudo mount /dev/loop0 /mnt


sudo umount /mnt
sudo losetup -d /dev/loop0
  • 1
    What do you mean? It works just fine for logical partitions. Instead of mucking with offsets, you can also just run sudo partx -a /dev/loop0 to get all of the partitions to show up normally. – psusi Jul 17 '14 at 1:44

Here's a script I use to mount partitions from image files. See the comments at the start of the script for usage information.


# mount_image, a program that mounts a specific partition from a RAW
# disk image file, such as a full-disk dd copy or a file used by QEMU.
# Note that compressed and other space-saving formats (qcaw2, etc.)
# will NOT work!

# Use:
# mount_image image_file partition_number mount_point
# For instance,
# mount_image image.raw 2 /mnt/shared
# mounts partition 2 from image.raw at /mnt/shared.

# This program relies on my GPT fdisk (gdisk) program to help identify
# partitions. I could have used regular fdisk, but this would have
# limited the program to working with MBR-formatted disks. With gdisk,
# both MBR- and GPT-formatted disks will work.

gdisk -l $1 > /tmp/mount_image.tmp
let StartSector=`egrep "^   $2|^  $2" /tmp/mount_image.tmp | fmt -u -s | sed -e 's/^[ \t]*//' | head -1 | cut -d " " -f 2`

let StartByte=($StartSector*512)

echo "Mounting partition $2, which begins at sector $StartSector"

mount -o loop,offset=$StartByte $1 $3

rm /tmp/mount_image.tmp

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.