2012-10-15

Mounting a disk image

Dumping a full disk is a quick way to perform a backup:

# dd if=/dev/sdb of=filename.dsk

But once you have such a dump, you can't directly mount it, you must use kpartx:

# kpartx -av filename.dsk
add map loop0p1 (252:0): 0 7830408 linear /dev/loop0 1144

You can see the partitions with fdisk

# fdisk -l /dev/loop0

Disk /dev/loop0: 4009 MB, 4009754624 bytes
128 heads, 22 sectors/track, 2781 cylinders, total 7831552 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 identifier: 0xc3072e18

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1   *        1144     7831551     3915204    b  W95 FAT32


Now you can mount the partitions that are inside the disk image.

# mount /dev/mapper/loop0p1 /mnt
# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda5             31G   12G   18G  41% /
udev                 3.9G  8.0K  3.9G   1% /dev
tmpfs                1.6G  960K  1.6G   1% /run
none                 5.0M     0  5.0M   0% /run/lock
none                 3.9G  200K  3.9G   1% /run/shm
/dev/sdb5             20G  1.4G   18G   8% /home
/dev/mapper/loop0p1  3.8G  1.1G  2.7G  29% /mnt


Once you've done, you can umount it with

# umount /mnt
# kpartx -dv filename.dsk
del devmap : loop0p1
loop deleted : /dev/loop0


Note:
Ubuntu doesn't have kpartx installed by default:

# sudo apt-get install kpartx


No comments:

Post a Comment