Mounting Individual Parititons in RAW Disk Images

Mounting Individual Parititons in RAW Disk Images

Let us say, for the sake of simplicity, that you backup whole disks by using dd in Linux. Now let us assume that you need just a single file out of a backup and do not want to (or can not realistically) restore the whole backup to disk for the single file. You can not mount -o loop because the backup does not contain a single partition. “What to do” you ask? Well I will tell you, wary traveler.

  1. Mount your raw disk image as a loopback device: losetup /dev/loop0 [path to image]
  2. Run kpartx and: kpartx -va /dev/loop0
    This will add your partitions to /dev/mapper/loop0pX where each X is a different partition
  3. You can now mount each partition: mount /dev/mapper/loop0pX /media/partition
    If you want to make sure you do not write anything to your backup simply mount it as read-only: mount -o ro /dev/mapper/loop0pX /media/partition

Once you are finished you will need to do your clean up.

  1. Unmount: umount /media/partition
  2. Remove the mapper devices: kpartx -d /dev/loop0
  3. Remove the loopback device: losetup -d /dev/loop0

These commands may all need to be run as root. If loop0 reports that it is busy just pick another loop device (/dev/loop1, ect).

3 thoughts on “Mounting Individual Parititons in RAW Disk Images

  1. Let me correct myself: vdfuse will allow you to split a disk image into partitions which are then available for mounting.

Leave a Reply

Your email address will not be published. Required fields are marked *