From: http://blog.lifebloodnetworks.com/?p=934
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.
- Unmount:
umount /media/partition
- 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 (/dev/loop1
, ect).