Discuss: Mount any VBox-compatible disk image on the host

Discussions related to using VirtualBox on Linux hosts.
regexpp
Posts: 7
Joined: 20. Aug 2010, 20:56
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: lin-win

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by regexpp »

vdfuse-v80 do not work fine for me with VMDK image. I have obtained error:

"ERROR: Invalid MBR found on image with signature 0xC033"

result from ltrace:

VDRead(0x1438500, 510, 0x7fff970f666e, 2, 1 <unfinished ...>
SYS_lseek(4, 0, 0) = 0
SYS_read(4, "3\300", 2) = 2
<... VDRead resumed> ) = 0
fwrite("\nERROR: ", 1, 8, 0x7f13e6606860 <unfinished ...>
SYS_write(2, "\nERROR: ", 8
ERROR: ) = 8
<... fwrite resumed> ) = 8
vfprintf(0x7f13e6606860, "Invalid MBR found on image with "..., 0x7fff970f6510 <unfinished ...>
SYS_write(2, "Invalid MBR found on image with "..., 48Invalid MBR found on image with signature 0xC033) = 48


Problem is inside VDRead. Function is called with correct argument - offset 510, but seek is set to 0 and read() read first two bytes from image, not signature at offset 510 :-(

For VDI images work fine. I have ubuntu 10.04. Tested with ose and nonfree version of VirtualBox.

Thanks for help ;-)
janm
Posts: 2
Joined: 26. Aug 2010, 12:39
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win7

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by janm »

Hello everybody!
I tried to compile vdfuse on Mac OSX Snow Leopard.
MacFuse is running and I can compile the example file systems.
Then I compiled VirtualBox 3.2.8 OSE without error.
Based on the MacFuse examples I altered your vdbuild.sh to

Code: Select all

infile=vdfuse.c
outfile=vdfuse
incdir="/Users/janm/Downloads/VirtualBox-3.2.8_OSE/include"
INSTALL_DIR="/Users/janm/Downloads/VirtualBox-3.2.8_OSE/out/darwin.x86/release/obj/VBoxDD"
CFLAGS="-pipe"

gcc -arch i386 "${infile}" -o "${outfile}" \
        -I"${incdir}" -I"/usr/local/include/fuse" \
        -Wl,-rpath,"${INSTALL_DIR}"  \
        -lfuse_ino64 "${INSTALL_DIR}"/VBoxDD.dylib \
        -Wall ${CFLAGS}
However I get the following error

Code: Select all

Undefined symbols:
  "_VDFlush", referenced from:
      _VD_flush in cc3Tmvur.o
  "_VDCloseAll", referenced from:
      _VD_destroy in cc3Tmvur.o
  "_VDCreate", referenced from:
      _main in cc3Tmvur.o
  "_VDWrite", referenced from:
      _VD_write in cc3Tmvur.o
  "_VDOpen", referenced from:
      _main in cc3Tmvur.o
      _main in cc3Tmvur.o
  "_VDGetSize", referenced from:
      _initialisePartitionTable in cc3Tmvur.o
  "_VDRead", referenced from:
      _initialisePartitionTable in cc3Tmvur.o
      _initialisePartitionTable in cc3Tmvur.o
      _initialisePartitionTable in cc3Tmvur.o
      _VD_read in cc3Tmvur.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Propably I referenced VBoxDD.dylib wrong?
janm
Posts: 2
Joined: 26. Aug 2010, 12:39
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win7

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by janm »

I figured out the following script to build vdfuse on osx

Code: Select all

infile=vdfuse.c
outfile=vdfuse
incdir="/your/path/to/VBox/headers"
INSTALL_DIR="/Applications/VirtualBox.app/Contents/MacOS"
CFLAGS="-pipe"

gcc -arch i386 "${infile}" \
         "${INSTALL_DIR}"/VBoxDD.dylib \
         "${INSTALL_DIR}"/VBoxDDU.dylib \
         "${INSTALL_DIR}"/VBoxVMM.dylib \
         "${INSTALL_DIR}"/VBoxRT.dylib \
         "${INSTALL_DIR}"/VBoxDD2.dylib \
         "${INSTALL_DIR}"/VBoxREM.dylib \
        -o "${outfile}" \
        -I"${incdir}" -I"/usr/local/include/fuse" \
        -Wl,-rpath,"${INSTALL_DIR}"  \
        -lfuse_ino64  \
        -Wall ${CFLAGS}
You actually don't have to build VirtualBox on your machine, just get the headers and go.

However osx does not support mount -o loop, and the fuse loopback file system does not work in this case ...
So I'm looking for an loopback fs now :)
regexpp
Posts: 7
Joined: 20. Aug 2010, 20:56
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: lin-win

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by regexpp »

VirtualBox library for VMDK disk images do not support reading from another position in file, then modulo 512. In attached file
is version of source modification for correct reading of MBR. The same modification is necessary for EBR.

regexpp

regexpp wrote:vdfuse-v80 do not work fine for me with VMDK image. I have obtained error:

"ERROR: Invalid MBR found on image with signature 0xC033"

result from ltrace:

VDRead(0x1438500, 510, 0x7fff970f666e, 2, 1 <unfinished ...>
SYS_lseek(4, 0, 0) = 0
SYS_read(4, "3\300", 2) = 2
<... VDRead resumed> ) = 0
fwrite("\nERROR: ", 1, 8, 0x7f13e6606860 <unfinished ...>
SYS_write(2, "\nERROR: ", 8
ERROR: ) = 8
<... fwrite resumed> ) = 8
vfprintf(0x7f13e6606860, "Invalid MBR found on image with "..., 0x7fff970f6510 <unfinished ...>
SYS_write(2, "Invalid MBR found on image with "..., 48Invalid MBR found on image with signature 0xC033) = 48


Problem is inside VDRead. Function is called with correct argument - offset 510, but seek is set to 0 and read() read first two bytes from image, not signature at offset 510 :-(

For VDI images work fine. I have ubuntu 10.04. Tested with ose and nonfree version of VirtualBox.

Thanks for help ;-)
Attachments
vdfuse-v81.c
(24.94 KiB) Downloaded 144 times
Simage
Posts: 1
Joined: 7. Sep 2010, 18:17
Primary OS: OpenSolaris other
VBox Version: PUEL
Guest OSses: Windows / Linux

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by Simage »

I feel like I'm missing something horribly obvious here. attempting to compile this tool on OpenSolaris svn134 and am getting the following error

Code: Select all

gcc vdfuse.c -o vdfuse -I/export/home/admin/VirtualBox/include `pkg-config --cflags --libs fuse` -Wall -l:/opt/VirtualBox/amd64/VBoxDD.so
vdfuse.c: In function `initialisePartitionTable':
vdfuse.c:392: warning: int format, pointer arg (arg 2)
vdfuse.c:392: warning: int format, pointer arg (arg 3)
vdfuse.c:392: warning: int format, pointer arg (arg 4)
ld: fatal: library -l:/opt/VirtualBox/amd64/VBoxDD.so: not found
ld: fatal: file processing errors. No output written to vdfuse
collect2: ld returned 1 exit status
VBoxDD.so is at the indicated path, and readable by everyone.

also if I attempt compiling on Ubuntu 10.04 it works without any difficulties.

any help is appreciated
zerep
Posts: 1
Joined: 21. Sep 2010, 20:14
Primary OS: Mac OS X Leopard
VBox Version: OSE other
Guest OSses: Linux

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by zerep »

@simage:
I was getting the same error when compiling the source file from this thread on Mac OS X. If you download all of the files listed in this thread and use that as the source in the install script then you may have better luck (worked for me on the Mac anyway):
http://forums.virtualbox.org/viewtopic.php?f=26&t=33355 (specifically vdfuse-v80.c)
Simage wrote:I feel like I'm missing something horribly obvious here. attempting to compile this tool on OpenSolaris svn134 and am getting the following error

Code: Select all

gcc vdfuse.c -o vdfuse -I/export/home/admin/VirtualBox/include `pkg-config --cflags --libs fuse` -Wall -l:/opt/VirtualBox/amd64/VBoxDD.so
vdfuse.c: In function `initialisePartitionTable':
vdfuse.c:392: warning: int format, pointer arg (arg 2)
vdfuse.c:392: warning: int format, pointer arg (arg 3)
vdfuse.c:392: warning: int format, pointer arg (arg 4)
ld: fatal: library -l:/opt/VirtualBox/amd64/VBoxDD.so: not found
ld: fatal: file processing errors. No output written to vdfuse
collect2: ld returned 1 exit status
VBoxDD.so is at the indicated path, and readable by everyone.

also if I attempt compiling on Ubuntu 10.04 it works without any difficulties.

any help is appreciated
sotel
Posts: 2
Joined: 1. Oct 2010, 21:55
Primary OS: Debian Lenny
VBox Version: PUEL
Guest OSses: Linux, BSD, Windows, FreeDOS

vdfuse-v81: compile warnings

Post by sotel »

During the compilation of vdfuse-v81 I got this warnings:

Code: Select all

./vdfuse-v81.c: In function 'initialisePartitionTable':
./vdfuse-v81.c:391: warning: format '%d' expects type 'int', but argument 2 has type 'long unsigned int'
./vdfuse-v81.c:391: warning: format '%d' expects type 'int', but argument 3 has type 'long unsigned int'
./vdfuse-v81.c:391: warning: format '%d' expects type 'int', but argument 5 has type 'long unsigned int'
./vdfuse-v81.c:391: warning: format '%d' expects type 'int', but argument 6 has type 'long unsigned int'
./vdfuse-v81.c:392: warning: format '%d' expects type 'int', but argument 2 has type 'struct MBRblock *'
./vdfuse-v81.c:392: warning: format '%d' expects type 'int', but argument 3 has type 'char (*)[446]'
./vdfuse-v81.c:392: warning: format '%d' expects type 'int', but argument 4 has type 'struct MBRentry (*)[4]'
./vdfuse-v81.c:395: warning: 'MBRsignature' may be used uninitialized in this function
Isn't critical but could open memory leaks.

This is my system/machine:

Code: Select all

uname -a:
Linux Schiermeier 2.6.35-6.slh.1-aptosid-amd64 #1 SMP PREEMPT Mon Sep 27 01:12:00 UTC 2010 x86_64 GNU/Linux
and this my gcc:

Code: Select all

gcc (Debian 4.4.4-17) 4.4.5
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.4-17' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.4-17)
Thanks for your attention!
regexpp
Posts: 7
Joined: 20. Aug 2010, 20:56
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: lin-win

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by regexpp »

Ok, here is version 0.82 with full support for VMDK disks.

Compilation warning is probably solved too.

regexpp
Attachments
vdfuse-v82.c
(24.66 KiB) Downloaded 333 times
edb
Posts: 2
Joined: 10. Nov 2010, 06:45
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: XP (so far)

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by edb »

I am trying to build vdfuse and tried both vdfuse-80 and vdfuse-82.
However, the VBox include files do NOT include either VBoxHDD nor VBoxHDD_new. Instead it appears they have been replaced with vd.h.
The include files were obtained today with svn co http://www.virtualbox.org/svn/vbox/trunk/include as instructed.

If I replace the include for VBoxHDD.h with vd.h, I get a compile error about VDCreate:

Code: Select all

vdfuse-v82.c: In function ‘main’:
vdfuse-v82.c:280: error: incompatible type for argument 2 of ‘VDCreate’
./include/VBox/vd.h:2038: note: expected ‘VDTYPE’ but argument is of type ‘struct VBOXHDD **’
vdfuse-v82.c:280: error: too few arguments to function ‘VDCreate’
It turns out VDCreate requires 3 args, the 2nd one is of VDTYPE. Not caring about CD or floppy, I hard coded
my disk type VDTYPE_HDD.

This built. However, my virtual disk, which does run in VitualBox (created by the Disk2VHD.exe program from Microsoft), could not be mounted, with an error:
ERROR: invalid initialisation of VD interface

At this point, I am out of my depth, and hope someone here has an idea. By the way, am running Ubuntu 10.10
pivcon
Posts: 1
Joined: 21. Nov 2010, 01:06
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: win7

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by pivcon »

Note:

vdfuse-82.c has a bug supporting VHD disks. It is checking for the cookie "connectix" (really "connecti" as it only compares 8 characters) instead of the correct cookie "conectix" based on:
http://technet.microsoft.com/en-us/virt ... 76673.aspx.




The following statement is wrong:

if (strncmp (buf, "connectix", 8 ) == 0) *disktype = "VHD";

It should read:

if (strncmp (buf, "conectix", 8 ) == 0) *disktype = "VHD";


Function with problem:

Code: Select all

int detectDiskType (char **disktype, char *filename) {
   char buf[8];
   int fd = open (filename, O_RDONLY);
   read (fd, buf, sizeof (buf));

   if (strncmp (buf, "connectix", 8 ) == 0)  *disktype = "VHD";
   else if (strncmp (buf, "VMDK", 4) == 0)  *disktype = "VMDK";
   else if (strncmp (buf, "KDMV", 4) == 0)  *disktype = "VMDK";
   else if (strncmp (buf, "<<<",  3) == 0)  *disktype = "VDI";
   else usageAndExit("cannot autodetect disk type of %s", filename);

   vbprintf ("disktype is %s", *disktype);
   close(fd);
   return 0;
}

Function Corrected:

Code: Select all

int detectDiskType (char **disktype, char *filename) {
   char buf[8];
   int fd = open (filename, O_RDONLY);
   read (fd, buf, sizeof (buf));

   if (strncmp (buf, "conectix", 8 ) == 0)  *disktype = "VHD";
   else if (strncmp (buf, "VMDK", 4) == 0)  *disktype = "VMDK";
   else if (strncmp (buf, "KDMV", 4) == 0)  *disktype = "VMDK";
   else if (strncmp (buf, "<<<",  3) == 0)  *disktype = "VDI";
   else usageAndExit("cannot autodetect disk type of %s", filename);

   vbprintf ("disktype is %s", *disktype);
   close(fd);
   return 0;
}

Note that another possible change would be to update the following code snippet which supports differencing disks to see if the user sent in a '-t' type and then not use the detectDiskType and instead use the type specified.

Code: Select all

for (i = 0; i < differencingLen; i++)
   {
     char *diffType;
     char *diffFilename = differencing[i];
     detectDiskType (&diffType, diffFilename);
     DISKopen (diffType, diffFilename);
   }

Thank you for this great tool. I am submitting this here hoping it makes it into vdfuse-83.c so other can benefit and I don't have to remember to patch it again.
spazio
Posts: 6
Joined: 16. Dec 2010, 16:55
Primary OS: Ubuntu 12.04
VBox Version: OSE Debian
Guest OSses: linux

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by spazio »

I tried this http://forums.virtualbox.org/viewtopic. ... di#p149082
on a linux box
Description: Ubuntu 10.04.1 LTS
Release: 10.04
Codename: lucid

with no luck, I get :

# sh vdbuild /usr/src/vboxhost-3.2.10/ vdfuse-v80.c
vdbuild: line 37: pkg-config: command not found
FUSE headers not found. Are they installed?
(Run 'apt-get install libfuse-dev' on Ubuntu / Debian)

And the ibfuse-dev is installed on the box.

I can see that the version of vdfuse-v80.c but is there an updated version? Or is this v83 patch working?
Or anybody has a miracle way to mount a vdi file on a linux host?

Thanks
sotel
Posts: 2
Joined: 1. Oct 2010, 21:55
Primary OS: Debian Lenny
VBox Version: PUEL
Guest OSses: Linux, BSD, Windows, FreeDOS

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by sotel »

spazio wrote:vdbuild: line 37: pkg-config: command not found
Did you have the pkg-config package installed?
wd5gnr
Posts: 16
Joined: 21. Oct 2008, 02:47

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by wd5gnr »

I had not noticed this before, but very cool tool. I picked up the V82 source and since I had just installed 4.0 (very nice, btw) compilation broke. There are two issues. First the VBoxHDD header is now in vb.h. Rather than change the script and the source I just did:

ln -sf vd.h VBoxHDD.h

The second issue is that VDCreate now takes a type parameter telling if the image is a HDD, DVD, etc. I hardcoded it to VDTYPE_HDD. Its only in one place:

if (RT_FAILURE(VDCreate(&vdError, VDTYPE_HDD, &hdDisk)))


I didn't extensively test it, but I did copy a VFAT image an did the following:

sudo ./vdfuse-v82 -w -f FreeDOS.vdi tmp
sudo mount -t vfat -o loop tmp/Partition1 mnt

(Obviously, tmp and mount were created directories).

Seems to work fine.
gordboy

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by gordboy »

If anyone is interested, I made a deb package for 32-bit Ubuntu with the following executables:

/usr/bin/vdfuse-v82a
/usr/bin/vdfuse-control

an icon and desktop file:

/usr/share/icons/vdfuse_icon.png
/usr/share/applications/vdfuse.desktop

a proper udev rules file:

/etc/udev/rules.d/vboxdrv.rules

and the following directories (owned by the principal user, uid/gid 1000)

/mnt/vdi
/mnt/VirtualBox

/usr/local/VirtualBox
/usr/local/VirtualBox/HardDisks
/usr/local/VirtualBox/Machines

The deal is that the user (who is a gnome desktop person, needless to say) can mount, view and unmount VD images with a nice GUI. The images are mounted read-only, but anyone could just edit the script /usr/bin/vdfuse-control to taste.

As for the vdfuse-v82a executable, it incorporates the fixes mentioned by pivcon & wd5gnr above. Use at your own risk.

Anyways the link is here:

http://sourceforge.net/projects/xspect3 ... b/download

PS you must be using virtualbox-4.0 PUEL, as it is a package dependency. Enjoy.
edb
Posts: 2
Joined: 10. Nov 2010, 06:45
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: XP (so far)

Re: Discuss: Mount any VBox-compatible disk image on the host

Post by edb »

@gordboy - thank you very much. This indeed did the trick. I thought I had made the same patches in my copy of vdfuse, but in any case, I can now mount the .VHD file I created with Microsoft's tool. I did have to remove the previous Virtual Box 3 and put in the V4 version, but that was not a pain.
Thanks again,
Ed :D
Post Reply