Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 29, 2016, 03:29:27 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: *NIX: Mounting .vdi Files (Even Dynamic Ones)  (Read 2044 times)

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,841
    • View Profile
    • Donate to Member
*NIX: Mounting .vdi Files (Even Dynamic Ones)
« on: February 11, 2014, 11:20:48 PM »
Wanted to get at a file in a VirtualBox guest OS without starting up the system in question.  The data was stored in a .vdi file (dynamic).  It turns out that one can mount such .vdi files using some qemu tools.

From thkala's answer on serverfault:
Quote
First you make sure that the nbd kernel module is loaded with the max_part option set to a number high enough to accommodate all the partitions in your .vdi image:

# rmmod nbd
# modprobe nbd max_part=16

Then you use qemu-nbd to attach the image:

# qemu-nbd -c /dev/nbd0 test.vdi

You will get a /dev/nbd0 block device, along with several /dev/nbd0p* partition device nodes. You use them as any other disk. Once you are done, you unmount everything, and disconnect the device:

# qemu-nbd -d /dev/nbd0

To determine the relevant partition device node I used cfdisk on /dev/nbd0, but it may be that a simple use of the blkid command may be enough.  partprobe may or may not be necessary after the first qemu-nbd invocation.



I first learned about this approach via How to mount a VirtualBox VDI image, but the specific instructions in the main post didn't quite work (though with modifications suggested in the comments things worked out).

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,841
    • View Profile
    • Donate to Member
Re: *NIX: Mounting .vdi Files (Even Dynamic Ones)
« Reply #1 on: August 18, 2015, 06:15:44 AM »
Found this:

Quote
libguestfs is a set of tools for accessing and modifying virtual machine (VM) disk images. You can use this for viewing and editing files inside guests, scripting changes to VMs, monitoring disk used/free statistics, creating guests, P2V, V2V, performing backups, cloning VMs, building VMs, formatting disks, resizing disks, and much more.

libguestfs can access almost any disk image imaginable. It can do it securely — without needing root and with multiple layers of defence against rogue disk images. It can access disk images on remote machines or on CDs/USB sticks. It can access proprietary systems like VMware and Hyper-V.

All this functionality is available through a scriptable shell called guestfish, or an interactive rescue shell virt-rescue.

via http://libguestfs.org/



Tried it out a bit with some success.

$ virt-filesystems -a vm.vdi
/dev/sda1

$ guestmount -a vm.vdi -m /dev/sda1 --ro tmp

$ guestumount tmp

Might be a keeper :)
« Last Edit: August 18, 2015, 06:35:02 AM by ewemoa »

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 7,650
    • View Profile
    • The Blog of Deozaan
    • Read more about this member.
    • Donate to Member
Re: *NIX: Mounting .vdi Files (Even Dynamic Ones)
« Reply #2 on: August 25, 2015, 12:52:35 AM »
Thanks for the info. Could be really useful.

This is slightly off-topic, but I was surprised to discover recently that since Windows 7 (or so) you can mount virtual disks (VHDs) natively in Windows. Just open Disk Management and use Action -> Attach VHD. (You can even configure Windows to boot from VHDs somehow, but I haven't looked into it enough to learn how to do that.)


ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,841
    • View Profile
    • Donate to Member
Re: *NIX: Mounting .vdi Files (Even Dynamic Ones)
« Reply #3 on: August 25, 2015, 01:02:33 AM »
Convenient indeed.

My impression had been that doing VHD-booting for Windows 7 was limited to certain editions, but perhaps that is mistaken:

  http://www.techrepub...rsions-of-windows-7/

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 7,650
    • View Profile
    • The Blog of Deozaan
    • Read more about this member.
    • Donate to Member
Re: *NIX: Mounting .vdi Files (Even Dynamic Ones)
« Reply #4 on: August 25, 2015, 09:59:54 AM »
This is confusing:

It turns out that the ability to boot from a VHD is actually available in all versions of Windows 7 and that only Windows 7 Ultimate and Windows 7 Enterprise can boot off of a VHD.

But it gets clarified later on:

So it appears that the Native VHD Boot feature is available in all versions of Windows 7, but that only Windows 7 Enterprise and Windows 7 Ultimate can boot from VHD.

I wonder what would happen if I attempt to boot some form of Linux from a VHD...