Mount VDI on linux?

Discussions related to using VirtualBox on Linux hosts.
Post Reply
SimonR
Posts: 35
Joined: 12. May 2014, 04:55

Mount VDI on linux?

Post by SimonR »

Hi all, is it possible to take a vdi file and read the contents from a regular linux machine? Ideally, mount it the way I could mount a physical windows disk so it appears as part of the directory tree?

I have a dead VM, and with the trouble this seems to be causing it seems possible it might be simpler to just copy the few relevant files off the disk image and rebuild from scratch. At least it would be nice if that were an option.

TIA
Simon
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Mount VDI on linux?

Post by fth0 »

Search the VirtualBox User Manual for vboximg-mount.
SimonR
Posts: 35
Joined: 12. May 2014, 04:55

Re: Mount VDI on linux?

Post by SimonR »

Thank you! (searching for mount by itself gave far too many hits to be helpful)
SimonR
Posts: 35
Joined: 12. May 2014, 04:55

Re: Mount VDI on linux?

Post by SimonR »

Well, I'm failing on step 4 in the user manual. The first three steps seem to work OK.

I can see the disk:

Code: Select all

$ vboximg-mount --list
-----------------------------------------------------------------
VM:   AccountsMachine
UUID: d8684f37-dacf-462b-a38d-58d11c87e0ef

    Image:   WindowsToUseFromChristinesLogin-disk001.vdi
    UUID:    6149fd1a-cfb7-4666-9067-c8304302b204

And I can see "inside" it to three partitions

Code: Select all

$ vboximg-mount --image 6149fd1a-cfb7-4666-9067-c8304302b204 --list

Virtual disk image:

   Base: /home/simon/VirtualBox VMs/AccountsMachine/WindowsToUseFromChristinesLogin-disk001.vdi
   UUID: 6149fd1a-cfb7-4666-9067-c8304302b204

Partition                                       Boot      Start  Sectors      Size        Offset  Type     
WindowsToUseFromChristinesLogin-disk001.vdi(0)  *          2048  1124352    549.0M       1048576  NTFS     
WindowsToUseFromChristinesLogin-disk001.vdi(1)          1126400  266243395  126.9G     576716800  NTFS     
WindowsToUseFromChristinesLogin-disk001.vdi(2)        267369800  1061560    518.3M  136893337600  Unknown  
I got step 3 to work by a bit of guesswork, this completed without any complaint (this syntax diverges from the user manual, see note below):

Code: Select all

$ vboximg-mount --image 6149fd1a-cfb7-4666-9067-c8304302b204 /home/simon/VirtualBox\ VMs/mnt/
This gives me files in the mnt directory:

Code: Select all

ls -l mnt
total 59837968
-rw-r--r-- 1 nobody nogroup 137438953472 Mar 26 09:21 vhdd
-rw-rw-rw- 1 root   root       575668224 Dec 31  1969 vol0
-rw-rw-rw- 1 root   root    136316618240 Dec 31  1969 vol1
-rw-rw-rw- 1 root   root       543518720 Dec 31  1969 vol2
But attempting to mount the result fails.

Code: Select all

$ sudo mount -t ntfs -o ro /home/simon/VirtualBox\ VMs/mnt/vhdd /home/simon/VirtualBox\ VMs/disk/
ntfs-3g: Failed to access volume '/home/simon/VirtualBox VMs/mnt/vhdd': Permission denied

ntfs-3g 2017.3.23 integrated FUSE 28 - Third Generation NTFS Driver
		Configuration type 7, XATTRS are on, POSIX ACLS are on
But the files should be entirely readable (see directory listing above):
(I have also tried this mount without specifying -t ntfs, that was less helpful and just said "can't"--I paraphrase, of course)
Any suggestions very much appreciated.

Side note: I believe there's an error in the user manual (at least w.r.t. the latest version of virtualbox) https://www.virtualbox.org/manual/UserM ... ximg-mount suggests using -p <part> but the help output from the program itself does not mention this option, and trying to use it simply throws a usage error.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Mount VDI on linux?

Post by fth0 »

Looking at the 1st level mounts, vhdd is the whole virtual disk and therefore not a NTFS partition. What happens if you try to mount vol1 as NTFS?

There are two sections about vboximg-mount in the VirtualBox User Manual BTW, and the 2nd one seems to be more up-to-date.
Last edited by fth0 on 5. Apr 2022, 17:25, edited 1 time in total.
SimonR
Posts: 35
Joined: 12. May 2014, 04:55

Re: Mount VDI on linux?

Post by SimonR »

My apologies, I rewrote this so many times trying to make sure anything important was included, but not waste everyone's time with something far too long, and it looks like this piece of info got lost :(

Anyway, I have tried mounting not only vhdd, but also all three of the vol entries too. They all fail the same way.

What seems to bizarre is that this fails with "permission denied" even though I'm running it as root, *and* all the files are world-readable. That doesn't seem to fit my unix-world view!?
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Mount VDI on linux?

Post by fth0 »

You could analyze it further by using strace, but an easier alternative would be using 7-Zip.
SimonR
Posts: 35
Joined: 12. May 2014, 04:55

Re: Mount VDI on linux?

Post by SimonR »

Isn't 7-zip an archive program? Are you saying that the VDI format is simply an archive? Hmm, I guess what I'm really trying to say is "how do I use 7-zip" in this process? Sounds intriguing, for sure. TIA!
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Mount VDI on linux?

Post by mpack »

SimonR wrote:Are you saying that the VDI format is simply an archive?
No, but the concepts are close enough that archiving tools can easily be modified to inspect virtual disk formats.

The principle difference is that the filesystem used inside a virtual disk is defined by the guest OS you install, it is not defined by the VDI (or VMDK or whatever) standard. However if an archiving tool has support for FAT, NTFS and EXTx then it will be able to access the contents of most unencrypted virtual disk images.

A secondary difference is that virtual disks are usually designed for random access, so they are not usually compressed (there's a compressed variant of VMDK that is intended only for use in an OVA).
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Mount VDI on linux?

Post by fth0 »

SimonR wrote:"how do I use 7-zip" in this process?
Google is your friend, search for "7-zip VDI".
SimonR
Posts: 35
Joined: 12. May 2014, 04:55

Re: Mount VDI on linux?

Post by SimonR »

OK, thanks.
Post Reply