Mounting .vdi file on host

Discussions related to using VirtualBox on Linux hosts.
thorgal
Posts: 8
Joined: 25. Mar 2008, 16:34

Post by thorgal »

interesting piece of info to be found at http://forensicir.blogspot.com/2008/01/ ... tools.html)

in particular, some comments to the method described there are useful, like
To work with a variable sized vdi file, you have to dump it to a dd file first (COPYDD); this will create a fixed size dump that then can be opened on a loop device. The variable sized file does not allow mounting as the fs driver needs to see the expected disk size.
I actually managed to mount my winXP VDI with this trick since it was a dynamic size FS.

Here is the recipe in short :

Code: Select all

1- vditool COPYDD Windows\ XP.vdi dump
2- dd if=dump of=dump2 bs=1M count=1
3- khexedit dump2 
in khexedit, look for text string NTFS. Offset found at 32256.
4- sudo mount -o loop,offset=32256,umask=000 dump /mnt
5- ll /mnt 
total 1180036
-rwxrwxrwx 1 root root          0 2008-03-25 08:34 AUTOEXEC.BAT*
-rwxrwxrwx 1 root root        211 2008-03-25 08:31 boot.ini*
-rwxrwxrwx 1 root root          0 2008-03-25 08:34 CONFIG.SYS*
drwxrwxrwx 1 root root       4096 2008-03-25 08:38 Documents and Settings/
-rwxrwxrwx 1 root root          0 2008-03-25 08:34 IO.SYS*
-rwxrwxrwx 1 root root          0 2008-03-25 08:34 MSDOS.SYS*
drwxrwxrwx 1 root root          0 2008-03-26 12:01 MSOCache/
-rwxrwxrwx 1 root root      47564 2004-08-04 14:00 NTDETECT.COM*
-rwxrwxrwx 1 root root     250032 2004-08-04 14:00 ntldr*
-rwxrwxrwx 1 root root 1207959552 2008-04-06 20:53 pagefile.sys*
drwxrwxrwx 1 root root       8192 2008-03-31 13:45 Program Files/
drwxrwxrwx 1 root root          0 2008-03-25 11:58 RECYCLER/
drwxrwxrwx 1 root root       4096 2008-03-25 08:37 System Volume Information/
drwxrwxrwx 1 root root      77824 2008-03-31 16:26 WINDOWS/
voila!
thorgal
Posts: 8
Joined: 25. Mar 2008, 16:34

Post by thorgal »

by the way,

can you tell grub to boot up from this offset ??? if your VDI is on its own partition and you install the MBR on that partition ? It is a naive question, just wondering.
mrbaseman
Posts: 2
Joined: 15. May 2008, 12:29

possible problem mounting dynamically growing images

Post by mrbaseman »

Nice workaround, thanks! I have sucessfully mounted a vfat partition inside a vdi-image. Does anyone know, what happens when writing on a partition inside a dynamically growing image file, especially, when the image needs to be enlarged? The guest system in VB sees the whole partition, including the empty part. VB is in charge for adjusting the image size. However, if the partition is mounted as described above, I worry that the data is just written at a certain offset from the beginning of the partition, no matter if this position on the disk is inside the vdi image or not?! This might destroy arbitrary data on the host(!) system.
postfix
Posts: 40
Joined: 14. Jan 2008, 13:05

Post by postfix »

ghr wrote: Nice tool, ImDisk !

For MS DOS & Win9X the magic strings are:
- MSDOS5.0 (DOS5, DOS6)
- MSWIN4.1 (WIN95, WIN98SE)

The harddisk starts 3 bytes before those strings.

More partitions ? Just keep on scanning :-)
Here are some information about ImDisk:
http://forums.virtualbox.org/viewtopic. ... ght=imdisk
sehe
Posts: 4
Joined: 20. Aug 2008, 14:55

bash handyness

Post by sehe »

use vditool (http://www.virtualbox.org/download/testcase/vditool) instead

here's some script wittiness to prevent brain function overload:

Code: Select all

#!/bin/bash
VDI=mydisk.vdi
OFFSET=$(./vditool DUMP $VDI|perl -ne 'print 32256+$1 if m/offData=(\d+)/')
sudo mount -o ro,noatime,noexec,loop,offset=$OFFSET $VDI loopmnt/
Have fun
souljahh2050
Posts: 5
Joined: 30. Aug 2008, 20:02

Post by souljahh2050 »

when I try to mount my vhd file i get the following error. What am I doing wrong?


sudo mount -t ntfs-3g -o loop,offset=287fe,umask=000 Virtua* /media/STORAGE/vdisk
NTFS signature is missing.
Failed to mount '/dev/loop6': Invalid argument
The device '/dev/loop6' doesn't have a valid NTFS.
Maybe you selected the wrong device? Or the whole disk instead of a
partition (e.g. /dev/hda, not /dev/hda1)? Or the other way around?
TerryE
Volunteer
Posts: 3572
Joined: 28. May 2008, 08:40
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
Contact:

Post by TerryE »

Don't know, but are you sure that this is a VHD? (as in MSVPC format)

If so, why are you asking about an MSVPC format file on a host in a VirtualBox forum?
Read the Forum Posting Guide
Google your Q site:VirtualBox.org or search for the answer before posting.
sehe
Posts: 4
Joined: 20. Aug 2008, 14:55

Post by sehe »

EDIT: ok I missed the part on 'VHD' :)

not to state the obvious:

you probably use the wrong offset (need to convert hex to decimal?)

what did you use to arrive at the offset?

My script posted earlier should work on any system with vditool and perl (I'm sure sh is ok, but who doesn't use bash?)
Gray Rat
Posts: 6
Joined: 8. Oct 2010, 23:20
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows 2003 Server, Debian

Re: Mounting .vdi file on host

Post by Gray Rat »

There's an absolutely easy and transparent way to mount a static VDI image in Linux.
Just use qemu-nbd utility as stated here (or here), it works like a charm!
If you're using Debian you need to install qemu-utils package, for Ubuntu 10.10 get qemu-kvm.
skyman
Posts: 6
Joined: 4. Jul 2009, 19:12
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: XP SP3

Re: Mounting .vdi file on host

Post by skyman »

hello all

I'm trying to mount .vdi on windows 7 64bit host, and didn't succeed it. I found ImDisk but it didn't work correctly - mounted disks are not visible in dispart and other environment.
May be someone know better way?
Post Reply