Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

loopback devices might be a possibility.

Related threads:

  • http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-01/7183.html
  • http://lists.gnu.org/archive/html/grub-devel/2005-01/msg00077.html
  • ftp://ftp.hq.nasa.gov/pub/ig/ccd/enhanced_loopback/
like image 710
Atlas1j Avatar asked Sep 14 '09 02:09

Atlas1j


People also ask

How do I mount all partitions in Ubuntu?

After a successful logon, open your file manager, and from the left pane, find the partition you wish to mount (under Devices) and click on it. It should be automatically mounted and its contents will show up in the main pane.


2 Answers

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 # 
like image 186
Andrew Y Avatar answered Sep 18 '22 22:09

Andrew Y


If you have util-linux v2.21 or higher, you can now do this with losetup. Use the -P (--partscan) option to read the partition table and create device nodes for each partition:

# losetup --show -f -P test.img /dev/loop0  # ls /dev/loop0* /dev/loop0 /dev/loop0p1 /dev/loop0p2  # mount /dev/loop0p1 /mnt/tmp 
like image 29
Andrew Oakley Avatar answered Sep 20 '22 22:09

Andrew Oakley