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.
- Mount your raw disk image as a loopback device:
losetup /dev/loop0 [path to image]
- Run kpartx and:
kpartx -va /dev/loop0
This will add your partitions to /dev/mapper/loop0pX where each X is a different partition
- 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.
- Remove the mapper devices:
kpartx -d /dev/loop0
- 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 (
3 thoughts on “Mounting Individual Parititons in RAW Disk Images”
vdfuse will also allow you to mount raw disk images in userspace (no need for root/sudo) however it requires a patch because it has a bug where it ignores RAW as a commandline option. See bug report + patch here:
Let me correct myself: vdfuse will allow you to split a disk image into partitions which are then available for mounting.
Thanks for the post!
Given how losetup some times has an issue removing the loopback device that could come in handy.