{"id":5528,"date":"2019-04-10T19:45:56","date_gmt":"2019-04-10T19:45:56","guid":{"rendered":"https:\/\/really.zonky.org\/?p=5528"},"modified":"2019-04-10T19:46:01","modified_gmt":"2019-04-10T19:46:01","slug":"mounting-virtualbox-disks-under-linux","status":"publish","type":"post","link":"https:\/\/really.zonky.org\/?p=5528","title":{"rendered":"Mounting VirtualBox Disks under Linux"},"content":{"rendered":"\n<p>So earlier today, I had a need to mount a disk image from a virtual machine on the host, and discovered a &#8220;new&#8221; method before remembering I&#8217;d made notes on this in the past. So I&#8217;m recording the details in the probably vain hope that I&#8217;ll remember this post in the future.<\/p>\n\n\n\n<p>The first thing to do is to add an option to include partition support in the relevant kernel module, which I&#8217;ve done by adding a line to <em>\/etc\/modprobe.d\/etc-modules-parameters.conf<\/em> :-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>options nbd max_part=63<\/code><\/pre>\n\n\n\n<p>The next step is to load the module: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># modprobe nbd<\/code><\/pre>\n\n\n\n<p>The next is to use a Qemu tool to connect a disk image to a network block device :-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># qemu-nbd -r -c \/dev\/nbd0 \/home\/mike\/lib\/virtual-machine-disks\/W10.vdi\n# ls \/dev\/nbd0*\n\/dev\/nbd0  \/dev\/nbd0p1  \/dev\/nbd0p2  \/dev\/nbd0p3<\/code><\/pre>\n\n\n\n<p>And next mount the relevant partition :-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># mount -o ro \/dev\/nbd0p2 \/mnt<\/code><\/pre>\n\n\n\n<p>All done! Except for un-mounting it and finally disconnecting the network block device :-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># umount \/mnt\n# ls \/dev\/nbd0*\n\/dev\/nbd0  \/dev\/nbd0p1  \/dev\/nbd0p2  \/dev\/nbd0p3\n# qemu-nbd -d \/dev\/nbd0\n\/dev\/nbd0 disconnected\n# ls \/dev\/nbd0*        \n\/dev\/nbd0<\/code><\/pre>\n\n\n\n<p>The trickiest part is the <em>qemu-nbd<\/em> command (so not very tricky at all). <\/p>\n\n\n\n<p>The &#8220;-r&#8221; option specifies that the disk image should be connected read-only, which  seems to be sensible when you&#8217;re working with a disk image that &#8220;belongs&#8221; to another machine. Obviously if you <em>need<\/em> to write to the disk image then you should drop the &#8220;-r&#8221; (but consider cloning or taking a snapshot). <\/p>\n\n\n\n<p>The &#8220;-c&#8221; option connects the disk image to a specific device and the &#8220;-d&#8221; option disconnects the specific device.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"683\" height=\"1024\" src=\"https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2011-05-08-Old-Metal-2.jpg?resize=683%2C1024&#038;ssl=1\" alt=\"\" class=\"wp-image-4907\" srcset=\"https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2011-05-08-Old-Metal-2.jpg?w=683&amp;ssl=1 683w, https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2011-05-08-Old-Metal-2.jpg?resize=200%2C300&amp;ssl=1 200w\" sizes=\"auto, (max-width: 683px) 100vw, 683px\" \/><figcaption>Old Metal 2<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>So earlier today, I had a need to mount a disk image from a virtual machine on the host, and discovered a &#8220;new&#8221; method before remembering I&#8217;d made notes on this in the past. So I&#8217;m recording the details in the probably vain hope that I&#8217;ll remember this post in the future. The first thing <a href='https:\/\/really.zonky.org\/?p=5528' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false,"_share_on_mastodon":"0"},"categories":[4,209,226],"tags":[1854,1851,1852,1853,1310],"class_list":["post-5528","post","type-post","status-publish","format-standard","hentry","category-it","category-linux-it","category-working-notes","tag-disk-image","tag-nbd","tag-network-block-device","tag-qemu","tag-virtualbox","category-4-id","category-209-id","category-226-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1f2KI-1ra","_links":{"self":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/5528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5528"}],"version-history":[{"count":1,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/5528\/revisions"}],"predecessor-version":[{"id":5530,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/5528\/revisions\/5530"}],"wp:attachment":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}