You can use the kpartx utility to map the
partitions of any block device or file that contains a partition
table and partition images. kpartx reads the
partition table and creates device files for the partitions in
/dev/mapper
. Each device file represents a
disk volume or a disk partition on a device or within an image
file.
The -l option lists any partitions that it finds, for example in an installation image file:
# kpartx -l system.img
loop0p1 : 0 204800 /dev/loop0 2048
loop0p2 : 0 12288000 /dev/loop0 206848
loop0p3 : 0 4096000 /dev/loop0 212494848
loop0p4 : 0 2 /dev/loop0 16590848
This output shows that the drive image contains four partitions,
and the first column are the names of the device files that can
be created in /dev/mapper
.
The -a option creates the device mappings:
#kpartx -a system.img
#ls /dev/mapper
control loop0p1 loop0p2 loop0p3 loop0p4
If a partition contains a file system, you can mount it and view the files that it contains, for example:
#mkdir /mnt/sysimage
#mount /dev/mapper/loop0p1 /mnt/sysimage
#ls /mnt/sysimage
config-2.6.32-220.el6.x86_64 config-2.6.32-300.3.1.el6uek.x86_64 efi grub initramfs-2.6.32-220.el6.x86_64.img initramfs-2.6.32-300.3.1.el6uek.x86_64.img ... #umount /mnt/sysimage
The -d option removes the device mappings:
#kpartx -d system.img
#ls /dev/mapper
control
For more information, see the kpartx(8)
manual page.