{"id":1283,"date":"2013-10-15T23:33:16","date_gmt":"2013-10-15T21:33:16","guid":{"rendered":"http:\/\/michlstechblog.info\/blog\/?p=1283"},"modified":"2023-06-27T12:32:25","modified_gmt":"2023-06-27T10:32:25","slug":"linux-multiple-ways-to-mount-a-partition-in-a-disk-image-file","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/linux-multiple-ways-to-mount-a-partition-in-a-disk-image-file\/","title":{"rendered":"Linux: Multiple ways to mount a partition in a disk image file"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_1283 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_1283')){$('.twoclick_social_bookmarks_post_1283').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Linux%3A%20Multiple%20ways%20to%20mount%20a%20partition%20in%20a%20disk%20image%20file\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Athere%20are%20several%20ways%20to%20mount%20a%20partition%20which%20is%20within%20a%20diskimage%20file%20created%20for%20example%20with%20dd.%0D%0A%0D%0AThe%20first%20and%20hard%20way%C2%A0%20is%20to%20determine%20the%20offset%20of%20the%20partition%20start%20sector%20and%20mounting%20the%20disk%20by%20specifing%20the%20offset%20as%20parameter%20for%20the%20loop%20device.%0D%0A%0D%0AYou%20can%20use%20the%C2%A0%20file%20or%20fdisk%20command%20to%20examine%20the%20file.%0D%0Aroot%40ubdev%3A%2Fmnt%2FRaspberryPI%20%23%20file%202012-07-15-wheezy-ra%20...\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/linux-multiple-ways-to-mount-a-partition-in-a-disk-image-file\\\/\",\"post_id\":1283,\"post_title_referrer_track\":\"Linux%3A+Multiple+ways+to+mount+a+partition+in+a+disk+image+file\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>there are several ways to mount a partition which is within a diskimage file created for example with dd.<\/p>\n<p>The <strong>first<\/strong> and hard <strong>way<\/strong>\u00a0 is to determine the offset of the partition start sector and mounting the disk by specifing the offset as parameter for the loop device.<\/p>\n<p>You can use the\u00a0 <code>file<\/code> or <code>fdisk<\/code> command to examine the file.<br \/>\n<code>root@ubdev:\/mnt\/RaspberryPI # file 2012-07-15-wheezy-raspbian.img<br \/>\n2012-07-15-wheezy-raspbian.img: x86 boot sector; partition 1: ID=0xc, starthead 130, startsector 8192, 114688 sectors; partition 2: ID=0x83, starthead 165, startsector 122880, 3665920 sectors, code offset 0xb8<\/code><br \/>\nor<\/p>\n<pre><code><code>root@ubdev:\/mnt\/RaspberryPI <\/code># fdisk 2012-07-15-wheezy-raspbian.img<\/code>\r\n\r\n<code>Command (m for help): p<\/code>\r\n\r\n<code>Disk 2012-07-15-wheezy-raspbian.img: 1939 MB, 1939865600 bytes\r\n255 heads, 63 sectors\/track, 235 cylinders, total 3788800 sectors\r\nUnits = sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisk identifier: 0x000714e9<\/code>\r\n\r\n<code>Device Boot\u00a0\u00a0\u00a0\u00a0\u00a0                          Start\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End\u00a0\u00a0\u00a0\u00a0\u00a0 Blocks\u00a0\u00a0 Id\u00a0 System<\/code>\r\n<code>2012-07-15-wheezy-raspbian.img1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 8192\u00a0\u00a0\u00a0\u00a0\u00a0 122879\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 57344\u00a0\u00a0\u00a0 c\u00a0 W95 FAT32 (LBA)<\/code>\r\n<code>2012-07-15-wheezy-raspbian.img2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 122880\u00a0\u00a0\u00a0\u00a0 3788799\u00a0\u00a0\u00a0\u00a0 1832960\u00a0\u00a0 83\u00a0 Linux<\/code><\/pre>\n<p>For example the startsector of partition 2 is <code>122880<\/code>,\u00a0 this multiplied with the 512 bytes per sector is the byte offset of the partition. 122880*512=62914560.<br \/>\n<!--more--><br \/>\n<code>mount -o loop,offset=62914560 2012-07-15-wheezy-raspbian.img \/root\/mnt\/loop\/<\/code><\/p>\n<p><code>ls -l \/root\/mnt\/loop\/<\/code><\/p>\n<p><code>total 92<br \/>\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jul 15\u00a0 2012 bin<br \/>\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jul 15\u00a0 2012 boot<br \/>\ndrwxr-xr-x\u00a0 5 root root\u00a0 4096 Jul 15\u00a0 2012 dev<br \/>\ndrwxr-xr-x 87 root root\u00a0 4096 Jul 16\u00a0 2012 etc<br \/>\ndrwxr-xr-x\u00a0 3 root root\u00a0 4096 Jul 15\u00a0 2012 home<br \/>\ndrwxr-xr-x 14 root root\u00a0 4096 Jul 15\u00a0 2012 lib<br \/>\ndrwx------\u00a0 2 root root 16384 Jul 15\u00a0 2012 lost+found<br \/>\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jul 15\u00a0 2012 media<br \/>\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jun\u00a0 2\u00a0 2012 mnt<br \/>\ndrwxr-xr-x\u00a0 3 root root\u00a0 4096 Jul 15\u00a0 2012 opt<br \/>\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jun\u00a0 2\u00a0 2012 proc<br \/>\ndrwx------\u00a0 2 root root\u00a0 4096 Jul 16\u00a0 2012 root<br \/>\ndrwxr-xr-x\u00a0 6 root root\u00a0 4096 Jul 15\u00a0 2012 run<br \/>\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jul 15\u00a0 2012 sbin<br \/>\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jun 20\u00a0 2012 selinux<br \/>\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jul 15\u00a0 2012 srv<br \/>\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Apr 14\u00a0 2012 sys<br \/>\ndrwxrwxrwt\u00a0 2 root root\u00a0 4096 Jun\u00a0 2\u00a0 2012 tmp<br \/>\ndrwxr-xr-x 10 root root\u00a0 4096 Jul 15\u00a0 2012 usr<br \/>\ndrwxr-xr-x 11 root root\u00a0 4096 Jul 15\u00a0 2012 var<\/code><\/p>\n<p>\n<!--Ads1--><br \/>\n<br \/>\nThe <strong>2nd way<\/strong>, if your kernel and the <a href=\"ftp:\/\/ftp.kernel.org\/pub\/linux\/utils\/util-linux\">util-linux<\/a> package supports it,\u00a0 is to let the loop driver recognize the offset. <\/p>\n<p>First step unload the loop modul<br \/>\n<code>modprobe -r loop<\/code><br \/>\nand load it again with the parameter <code>max_part=15<\/code><\/p>\n<p><code>modprobe loop max_part=15<\/code><\/p>\n<p>Note: If your kernel has a builtin loop module add the parameter <code>loop.max_part=15<\/code> to your kernel command line(<code>\/boot\/grub\/grub.cfg<\/code>):<\/p>\n<p><code>linux\u00a0\u00a0 \/boot\/vmlinuz-3.8.0-31-generic root=UUID=b91540e1-fd13-466f-a16a-a0fea82595ea ro\u00a0\u00a0 splash quiet $vt_handoff loop.max_part=15<\/code><\/p>\n<p>mount the whole disk<\/p>\n<p><code><code><code>root@ubdev:\/mnt\/RaspberryPI <\/code>#<\/code> losetup --find --partscan --show 2012-07-15-wheezy-raspbian.img<\/code><br \/>\nand it will create a loop device for each partition like <code>\/dev\/loop0p1<\/code>, which you can mount.<\/p>\n<p>The <strong>3rd way<\/strong> is to let the RAID admin utility <code>mdadm<\/code> let do this for you. Mount the whole diskfile<\/p>\n<p><code><code><code>root@ubdev:\/mnt\/RaspberryPI <\/code>#<\/code> losetup -f 2012-07-15-wheezy-raspbian.img<\/code><\/p>\n<p><code><code><code>root@ubdev:\/mnt\/RaspberryPI <\/code># <\/code>losetup -a<br \/>\n\/dev\/loop0: [0015]:281474976991968 (\/mnt\/VMs\/RaspberryPI\/qemu\/2012-07-15-wheezy-raspbian.img)<\/code><\/p>\n<p>and scan the loop device with mdadm<br \/>\n<code><code><code>root@ubdev:\/mnt\/RaspberryPI <\/code>#<\/code> mdadm --build --force testMount --level linear --raid-devices 1 \/dev\/loop0<br \/>\nmdadm: array \/dev\/md\/testMount built and started.<\/code><\/p>\n<p>mdadm creates a device for each partition<\/p>\n<p><code>root@ubdev:\/mnt\/VMs\/RaspberryPI\/qemu# ls -l \/dev\/md\/*<br \/>\nlrwxrwxrwx 1 root root\u00a0 8 Okt 16 14:16 \/dev\/md\/testMount -&gt; ..\/md127<br \/>\nlrwxrwxrwx 1 root root 10 Okt 16 14:16 \/dev\/md\/testMount1 -&gt; ..\/md127p1<br \/>\nlrwxrwxrwx 1 root root 10 Okt 16 14:16 \/dev\/md\/testMount2 -&gt; ..\/md127p2<\/code><\/p>\n<p>And you could mount these devices:<\/p>\n<pre><code>root@ubdev:\/mnt\/VMs\/RaspberryPI\/qemu# mount \/dev\/md\/testMount2 \/root\/mnt\/p2\/\r\nroot@ubdev:\/mnt\/VMs\/RaspberryPI\/qemu# ls -l \/root\/mnt\/p2\/\r\ntotal 92\r\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jul 15\u00a0 2012 bin\r\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jul 15\u00a0 2012 boot\r\ndrwxr-xr-x\u00a0 5 root root\u00a0 4096 Jul 15\u00a0 2012 dev\r\ndrwxr-xr-x 87 root root\u00a0 4096 Jul 16\u00a0 2012 etc\r\ndrwxr-xr-x\u00a0 3 root root\u00a0 4096 Jul 15\u00a0 2012 home\r\ndrwxr-xr-x 14 root root\u00a0 4096 Jul 15\u00a0 2012 lib\r\ndrwx------\u00a0 2 root root 16384 Jul 15\u00a0 2012 lost+found\r\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jul 15\u00a0 2012 media\r\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jun\u00a0 2\u00a0 2012 mnt\r\ndrwxr-xr-x\u00a0 3 root root\u00a0 4096 Jul 15\u00a0 2012 opt\r\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jun\u00a0 2\u00a0 2012 proc\r\ndrwx------\u00a0 2 root root\u00a0 4096 Jul 16\u00a0 2012 root\r\ndrwxr-xr-x\u00a0 6 root root\u00a0 4096 Jul 15\u00a0 2012 run\r\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jul 15\u00a0 2012 sbin\r\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jun 20\u00a0 2012 selinux\r\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Jul 15\u00a0 2012 srv\r\ndrwxr-xr-x\u00a0 2 root root\u00a0 4096 Apr 14\u00a0 2012 sys\r\ndrwxrwxrwt\u00a0 2 root root\u00a0 4096 Jun\u00a0 2\u00a0 2012 tmp\r\ndrwxr-xr-x 10 root root\u00a0 4096 Jul 15\u00a0 2012 usr\r\ndrwxr-xr-x 11 root root\u00a0 4096 Jul 15\u00a0 2012 var<\/code><\/pre>\n<p>The <strong>4th way<\/strong> is <code>kpartx<\/code> from , but I havn&#8217;t tested it.<\/p>\n<p>Enjoy<br \/>\nMichael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, there are several ways to mount a partition which is within a diskimage file created for example with dd. The first and hard way\u00a0 is to determine the offset of the partition start sector and mounting the disk by specifing the offset as parameter for the loop device. You can use the\u00a0 file or &hellip; <a href=\"https:\/\/michlstechblog.info\/blog\/linux-multiple-ways-to-mount-a-partition-in-a-disk-image-file\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Linux: Multiple ways to mount a partition in a disk image file<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[327,326,249,224,169,328,52],"class_list":["post-1283","post","type-post","status-publish","format-standard","hentry","category-linux","tag-dd","tag-disk-image","tag-file","tag-linux-2","tag-mount","tag-offset","tag-partition"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=1283"}],"version-history":[{"count":16,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1283\/revisions"}],"predecessor-version":[{"id":9330,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1283\/revisions\/9330"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=1283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=1283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=1283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}