{"id":3223,"date":"2014-02-04T19:33:28","date_gmt":"2014-02-04T19:33:28","guid":{"rendered":"http:\/\/really.zonky.org\/?p=3223"},"modified":"2014-02-04T19:41:49","modified_gmt":"2014-02-04T19:41:49","slug":"mounting-a-vdi-image-under-linux","status":"publish","type":"post","link":"https:\/\/really.zonky.org\/?p=3223","title":{"rendered":"&#8220;Mounting&#8221; A VDI Image Under Linux"},"content":{"rendered":"<p>So I found myself in the position of wanting to poke around the file system of a virtual Windows machine &#8211; the kind of poking around you would prefer I didn&#8217;t if it were your Windows machine &#8211; and needed to make a VDI disk image available as a block device under Linux so it could be mounted in the normal fashion.<\/p>\n<p>Googling around found some instructions; which didn&#8217;t work properly. Solutions were also available, but I&#8217;m writing up the &#8216;fixed&#8217; instructions here to save myself time in case I need it again.<\/p>\n<p>First step is to become\u00a0<em>root<\/em>; if you need help doing that, this is probably the wrong page for you!<\/p>\n<p>Next step is to install the Debian package\u00a0<em>qemu-utils<\/em> which contains the tool\u00a0<em>qemu-nbd<\/em> which we&#8217;ll need later. We also need to load the network block device module with a parameter :-<\/p>\n<pre>apt-get install qemu-utils\r\nmodprobe nbd max_part=16\r\n<\/pre>\n<p>This parameter is the key here &#8211; for some reason the default on at least some of my Linux machines is not to create additional block devices for any additional partitions that show up.<\/p>\n<p>The next step is to &#8216;attach&#8217; the VDI image (or presumably anything supported by <em>qemu-img<\/em> which covers pretty much everything popular) and tell the Linux kernel that there may be some new partitions to create device files for :-<\/p>\n<pre>\r\nqemu-nbd -n -c \/dev\/nbd0 disk.vdi\r\npartx -a \/dev\/nbd0\r\npartx: \/dev\/nbd0: error adding partitions 1-2\r\n<\/pre>\n<p>(Added the &#8220;-n&#8221; flag after reading about some more problems and a work-around; as I haven&#8217;t tested it, be careful!)<\/p>\n<p>The error from partx indicates that qemu-nbd managed to create the partitions itself, but there are hints that this sometimes doesn&#8217;t happen so I&#8217;ve included the command here &#8220;just in case&#8221;. Once the partition block devices are present, they can be used as any ordinary devices.<\/p>\n<p>Once finished, unmount anything mounted and release the block device with :-<\/p>\n<pre>\r\nqemu-nbd -d \/dev\/nbd0\r\nrmmod nbd\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So I found myself in the position of wanting to poke around the file system of a virtual Windows machine &#8211; the kind of poking around you would prefer I didn&#8217;t if it were your Windows machine &#8211; and needed to make a VDI disk image available as a block device under Linux so it <a href='https:\/\/really.zonky.org\/?p=3223' 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":false,"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,226],"tags":[],"class_list":["post-3223","post","type-post","status-publish","format-standard","hentry","category-it","category-working-notes","category-4-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-PZ","_links":{"self":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/3223","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=3223"}],"version-history":[{"count":2,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/3223\/revisions"}],"predecessor-version":[{"id":3225,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/3223\/revisions\/3225"}],"wp:attachment":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}