Mounting partitions from disk images

For analysis and repairing it is sometimes required to mount disk images from visualization systems like KVM on a host system. These disk images contain multiple partitions and there own partition table like a real disk - therefore the can not be mounted directly.

fdisk can be used to list the partitions in the disk image and shows the beginning of each partition:

fdisk -l /path/to/disk.img

giving the following output:

Disk disk.img: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00024628

   Device Boot      Start         End      Blocks   Id  System
disk.img1   *          63    16048934     8024436   83  Linux
disk.img2        16048935    16771859      361462+   5  Extended
disk.img5        16048998    16771859      361431   82  Linux swap / Solaris

The partition start sector, multiplied by the sector size in bytes (512 in the example), can be used as the value for the offset parameter for mount to specify which partition to mount.

The following command can be used to mount the first partition, starting at sector 63:

mount -o loop,offset=$((63 * 512)) disk.img /mnt/disk
↑Back to top