Page 1 of 2

Mount VDI as logical drive on host

Posted: 22. Feb 2008, 15:50
by daverage
Is there a way to mount a VDI as a logical drive in the windows host, same as you would mount an ISO with Daemon tools?

Posted: 29. Feb 2008, 08:59
by postfix
Of course, it's possible and you're right, you need a special tool. My favorite one is ImDisk a virtual disk driver. It brings a GUI interface for mounting standard image files form harddisk, floppy, ISO (CD/DVD). But mounting a VDI-file as a windows drive you must call ImDisk with its option -b offset, and it is best done from commandline using CMD (and after successfull testing as parameter in a LNK-file).

See information and download of ImDisk: http://www.ltr-data.se/opencode.html#ImDisk

Next you need information about the offset given to ImDisk. There is a nice and usefull thread: http://forums.virtualbox.org/viewtopic.php?t=52

It works only on fix sized VDI-files, without having any snapshots!


Using ImDisk from commandline is:

Code: Select all

ImDisk Virtual Disk Driver

imdisk -a -t type -m mountpoint [-n] [-o opt1[,opt2 ...]] [-f|-F file]
       [-s size] [-b offset] [-S sectorsize] [-u unit] [-x sectors/track]
       [-y tracks/cylinder] [-p "format-parameters"]
imdisk -d [-u unit | -m mountpoint]
imdisk -l [-u unit | -m mountpoint]
imdisk -e [-s size] [-o opt1[,opt2 ...]] [-u unit | -m mountpoint]

-a      Attach a virtual disk. This will configure and attach a virtual disk
        with the parameters specified and attach it to the system.

-d      Detach a virtual disk from the system and release all resources.

-e      Edit an existing virtual disk.

        Along with the -s parameter extends the size of an existing virtual
        disk. Note that even if the disk can be extended successfully, the
        existing filesystem on it can only be extended to fill the new size
        without re-formatting if you are running Windows 2000 or later and the
        current filesystem is NTFS.

        Along with the -o parameter changes media characteristics for an
        existing virtual disk. Options that can be changed on existing virtual
        disks are those specifying wether or not the media of the virtual disk
        should be writable and/or removable.

-t type
        Select the backingstore for the virtual disk.

vm      Storage for this type of virtual disk is allocated from virtual memory
        in the system process. If a file is specified with -f that file is
        is loaded into the memory allocated for the disk image.

file    A file specified with -f file becomes the backingstore for this
        virtual disk.

proxy   The actual backingstore for this type of virtual disk is controlled by
        an ImDisk storage server accessed by the driver on this machine by
        sending storage I/O request through a named pipe specified with -f.

-f file or -F file
        Filename to use as backingstore for the file type virtual disk, to
        initialize a vm type virtual disk or name of a named pipe for I/O
        client/server communication for proxy type virtual disks. For proxy
        type virtual disks "file" may be a COM port or a remote server
        address if the -o options includes "ip" or "comm".

        Instead of using -f to specify 'DOS-style' paths, such as
        C:\dir\image.bin or \\server\share\image.bin, you can use -F to
        specify 'NT-style' native paths, such as
        \Device\Harddisk0\Partition1\image.bin. This makes it possible to
        specify files on disks or communication devices that currently have no
        drive letters assigned.

-l      List configured devices. If given with -u or -m, display details about
        that particular device.

-n      When printing ImDisk device names, print only the unit number without
        the \Device\ImDisk prefix.

-s size
        Size of the virtual disk. Size is number of bytes unless suffixed with
        a b, k, m, g, t, K, M, G or T which denotes number of 512-byte blocks,
        thousand bytes, million bytes, billion bytes, trillion bytes,
        kilobytes, megabytes, gigabytes and terabytes respectively. The suffix
        can also be % to indicate percentage of free physical memory which
        could be useful when creating vm type virtual disks. It is optional to
        specify a size unless the file to use for a file type virtual disk does
        not already exist or when a vm type virtual disk is created without
        specifying an initialization image file using the -f or -F. If size is
        specified when creating a file type virtual disk, the size of the file
        used as backingstore for the virtual disk is adjusted to the new size
        specified with this size option.

        The size can be a negative value to indicate the size of free physical
        memory minus this size. If you e.g. type -400M the size of the virtual
        disk will be the amount of free physical memory minus 400 MB.

-b offset
        Specifies an offset in an image file where the virtual disk begins. All
        offsets of I/O operations on the virtual disk will be relative to this
        offset. This parameter is particularily useful when mounting a specific
        partition in an image file that contains an image of a complete hard
        disk, not just one partition. This parameter has no effect when
        creating a blank vm type virtual disk. When creating a vm type virtual
        disk with a pre-load image file specified with -f or -F paramters, the
        -b parameter specifies an offset in the image file where the image to
        be loaded into the vm type virtual disk begins.

-S sectorsize
        Sectorsize to use for the virtual disk device. Default value is 512
        bytes except for CD-ROM/DVD-ROM style devices where 2048 bytes is used
        by default.

-x sectors/track
        See the description of the -y option below.

-y tracks/cylinder
        The -x and -y options can be used to specify a synthetic geometry.
        This is useful for constructing bootable images for later download to
        physical devices. Default values depends on the device-type specified
        with the -o option. If the 'fd' option is specified the default values
        are based on the virtual disk size, e.g. a 1440K image gets 2
        tracks/cylinder and 18 sectors/track.

-p "format-parameters"
        If -p is specified the 'format' command is invoked to create a
        filesystem when the new virtual disk has been created.
        "format-parameters" must be a parameter string enclosed within
        double-quotes. The string is added to the command line that starts
        'format'. You usually specify something like "/fs:ntfs /q /y", that
        is, create an NTFS filesystem with quick formatting and without user
        interaction.

-o option
        Set or reset options.

ro      Creates a read-only virtual disk. For vm type virtual disks, this
        option can only be used if the -f option is also specified.

rw      Specifies that the virtual disk should be read/writable. This is the
        default setting. It can be used with the -e parameter to set an
        existing read-only virtual disk writable.

rem     Specifies that the device should be created with removable media
        characteristics. This changes the device properties returned by the
        driver to the system. For example, this changes how some filesystems
        cache write operations.

fix     Specifies that the media characteristics of the virtual disk should be
        fixed media, as opposed to removable media specified with the rem
        option. Fixed media is the default setting. The fix option can be used
        with the -e parameter to set an existing removable virtual disk as
        fixed.

        Note that virtual floppy or CD/DVD-ROM drives are always read-only and
        removable devices and that can not be changed.

cd      Creates a virtual CD-ROM/DVD-ROM. This is the default if the file
        name specified with the -f option ends with either .iso or .bin
        extensions.

fd      Creates a virtual floppy disk. This is the default if the size of the
        virtual disk is any of 160K, 180K, 320K, 360K, 640K, 720K, 820K, 1200K,
        1440K, 1680K, 1722K, 2880K, 123264K or 234752K.

hd      Creates a virtual fixed disk partition. This is the default unless
        file extension or size match the criterias for defaulting to the cd or
        fd options.

ip      Can only be used with proxy-type virtual disks. With this option, the
        user-mode service component is initialized to connect to an ImDisk
        storage server using TCP/IP. With this option, the -f switch specifies
        the remote host optionally followed by a colon and a port number to
        connect to.

comm    Can only be used with proxy-type virtual disks. With this option, the
        user-mode service component is initialized to connect to an ImDisk
        storage server through a COM port. With this option, the -f switch
        specifies the COM port to connect to, optionally followed by a colon,
        a space, and then a device settings string with the same syntax as the
        MODE command.

-u unit
        Along with -a, request a specific unit number for the ImDisk device
        instead of automatic allocation. Along with -d or -l specifies the
        unit number of the virtual disk to remove or query.

-m mountpoint
        Specifies a drive letter or mount point for the new virtual disk, the
        virtual disk to query or the virtual disk to remove. When creating a
        new virtual disk you can specify #: as mountpoint in which case the
        first unused drive letter is automatically used.

Posted: 28. Mar 2008, 15:09
by nxx
postfix wrote:Of course, it's possible and you're right, you need a special tool. My favorite one is ImDisk a virtual disk driver. It brings a GUI interface for mounting standard image files form harddisk, floppy, ISO (CD/DVD). But mounting a VDI-file as a windows drive you must call ImDisk with its option -b offset, and it is best done from commandline using CMD (and after successfull testing as parameter in a LNK-file).

See information and download of ImDisk: http://www.ltr-data.se/opencode.html#ImDisk
is there any such utility for Linux ?

Posted: 2. Apr 2008, 16:59
by karyonix
nxx wrote:is there any such utility for Linux ?
Yes.
It is called losetup.

Posted: 3. Jun 2008, 15:22
by rasvee
postfix,

so you mean that i can only mount with the original VDI. the snapshots then cannot be used.

oh... boy...
thanks

Posted: 5. Aug 2008, 03:12
by postfix
I found one more nice article mounting a VDI file.
-> http://muralipiyer.blogspot.com/2008/02 ... entic.html

Posted: 9. Nov 2008, 20:43
by Znupi
That's awesome! Why doesn't VirtualBox provide this type of functionality by default? It's much better than sharing through samba.

Posted: 9. Nov 2008, 23:27
by mpack
postfix wrote:I found one more nice article mounting a VDI file.
Please note the last comment in the article. Writing inside a VDI using just a data offset is NOT possible with dynamically expanding VDIs, which I would guess are the majority type these days. If you try it your dynamic VDI will be royally screwed.

Re: Mount VDI as logical drive on host

Posted: 8. May 2009, 00:04
by caminati
I made a stand-alone portable package to automate all this stuff. It takes a vdi file, a mountpoint and the number (1-4) of primary partition to mount, and mounts it.
If it's not formatted, it all the same gives you a loop device upon which you will find raw partition, and a separate loop device pointing at the whole hard disk.
It fully works only on static VDIs (you decide that upon creation); however there is some apparent amount of reading success with dynamic VDIs as well, for sure you can ls their partitions.

It's gpl for linux.
See my page:
http://www.mat.uniroma1.it/~caminati/mount_vdi.html

Re: Mount VDI as logical drive on host

Posted: 8. May 2009, 17:07
by mpack
caminati wrote:It fully works only on static VDIs (you decide that upon creation); however there is some apparent amount of reading success with dynamic VDIs as well, for sure you can ls their partitions.
As I said before, a non-VDI-aware application cannot reliably access the contents of a dynamic VDI using just a data offset. It must be smart enough to understand the dynamic relocation of VDI blocks. Yes, it may appear to work if a few important data structures (such as the partition map) happen by luck to be in the right place. But, it is highly unlikely that everything will be in the right place. If you insist on using a dumb tool, and if your VDI then gets corrupted and you lose all your data, then don't say you were not warned.

Obviously, if the volume is treated as write protected then the VDI cannot be corrupted, but your host is unlikely to be happy with it. And by "unhappy" I mean that a host or host-application crash would be no surprise to me.

Re: Mount VDI as logical drive on host

Posted: 15. Jun 2009, 01:45
by bianxi
mpack wrote:Obviously, if the volume is treated as write protected then the VDI cannot be corrupted, but your host is unlikely to be happy with it. And by "unhappy" I mean that a host or host-application crash would be no surprise to me.
Host crash should not happen, if I'm not wrong, corrupted USB disk won't make Windows/Linux OS crash. Anyway, can virtual box have a USB device driver to mount VDI as virutal USB disk?

Re: Mount VDI as logical drive on host

Posted: 15. Jun 2009, 02:16
by bianxi
I tried imdisk, does not work with my dynamic vdi. I used vmware-mount to mount vmware disk image from host many years, this kind of application should be available for virtualbox.

Re: Mount VDI as logical drive on host

Posted: 15. Jun 2009, 09:35
by ppgrainbow
daverage wrote:Is there a way to mount a VDI as a logical drive in the windows host, same as you would mount an ISO with Daemon tools?
There is neither a easy way to view nor mount VDI hard disk images without using a tool that will require unsigned drivers to load on 64-bit Windows Vista or Windows Server 2008 hosts. The other day I tried to mount a VDI file that contained Windows XP Home Edition, IMTools wouldn't read the contents of the hard disk image at all.

As for VHD files, mounting these files under Windows XP or Vista host are not easy, but WinImage can look at the contents of the hard disk image if the drive is formatted as a FAT, FAT32, NTFS or ext2. Both ext2 and NTFS are read-only.

If I wanted to edit the contents of my Windows XP Home Edition FAT32 formatted hard disk image, I always use WinImage.

Re: Mount VDI as logical drive on host

Posted: 26. Feb 2010, 22:37
by john.doe
Note that WinMount3 can mount both vmdk and vdi images without any problems =). No need to install unsigned drivers or anything.

Re: Mount VDI as logical drive on host

Posted: 16. Mar 2012, 13:09
by johnbot
john.doe wrote:Note that WinMount3 can mount both vmdk and vdi images without any problems =)
This is true. With Version 3.5 you can mount a variable size VDI for writing which on a brief test worked well. Alas it gives you a warning that "to modify this vdi file will cause the upper layer snapshot does not available!" - Whatever that means, I did not try with snapshots, only with a straight single VDI.
And there is a LIMITATION: Although the VDI appears with a drive letter in explorer it does not show up as a drive in the management console, thus you cannot run a defrag on it (which would be nice because then you would not have any files locked by windows).