Monday, January 02, 2012

Loop-mounting a backup of an entire disk, and accessing its partitions

The following is a short howto on how to mount a full-disk backup (that you took using dd, for example), and access its partitions.
# Assuming that the backup is called diskbackup.bin
$ losetup /dev/loop0 diskbackup.bin
$ kpartx -a /dev/loop0

# Your partitions should now show up on /dev/mapper/
$ ls -lah /dev/mapper/
total 0
drwxr-xr-x  2 root root       80 2012-01-02 08:45 .
drwxr-xr-x 18 root root     3.9K 2012-01-02 08:45 ..
crw-------  1 root root  10, 236 2012-01-02 08:00 control
brw-rw----  1 root disk 253,   0 2012-01-02 08:45 loop0p1