How to mount one partition from an image file that contains multiple partitions on Linux?

Atlas1j picture Atlas1j · Sep 14, 2009 · Viewed 41.4k times · Source

The image file has a partition table, and it contains multiple partitions.

loopback devices might be a possibility.

Related threads:

Answer

Andrew Y picture Andrew Y · Feb 5, 2012

You might do it like this, without much hassle:

# kpartx -v -a logging-test.img 
add map loop0p1 (251:0): 0 497664 linear /dev/loop0 2048
add map loop0p2 (251:1): 0 66605058 linear /dev/loop0 501758
add map loop0p5 (251:2): 0 66605056 251:1 2
# ls /dev/mapper/
control  loop0p1  loop0p2  loop0p5
# mount /dev/mapper/loop0p1 /mnt/test
# mount  | grep test
/dev/mapper/loop0p1 on /mnt/test type ext2 (rw)
#

And to remove the loop device after you finished:

# kpartx -v -d logging-test.img
del devmap : loop0p2
del devmap : loop0p1
loop deleted : /dev/loop0
#