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

Discussions related to using VirtualBox on Linux hosts.

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

Postby regexpp » 20. Aug 2010, 21:12

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 ;-)
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

Postby janm » 26. Aug 2010, 12:43

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   Expand viewCollapse view
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   Expand viewCollapse view
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

Postby janm » 26. Aug 2010, 13:29

I figured out the following script to build vdfuse on osx
Code: Select all   Expand viewCollapse view
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 :)
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

Postby regexpp » 27. Aug 2010, 11:03

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 129 times
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

Postby Simage » 7. Sep 2010, 18:22

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   Expand viewCollapse view
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
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

Postby zerep » 21. Sep 2010, 20:18

@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):
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   Expand viewCollapse view
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

vdfuse-v81: compile warnings

Postby sotel » 2. Oct 2010, 00:03

During the compilation of vdfuse-v81 I got this warnings:
Code: Select all   Expand viewCollapse view
./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   Expand viewCollapse view
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   Expand viewCollapse view
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!
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

Postby regexpp » 29. Oct 2010, 12:09

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 322 times
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

Postby edb » 10. Nov 2010, 07:01

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   Expand viewCollapse view
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
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

Postby pivcon » 21. Nov 2010, 01:21

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/virtualserver/bb676673.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   Expand viewCollapse view
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   Expand viewCollapse view
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   Expand viewCollapse view
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.
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

Postby spazio » 16. Dec 2010, 17:07

I tried this viewtopic.php?f=26&t=33355&p=149082&hilit=mount+vdi#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
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

Postby sotel » 26. Dec 2010, 20:57

spazio wrote:vdbuild: line 37: pkg-config: command not found


Did you have the pkg-config package installed?
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

Postby wd5gnr » 28. Dec 2010, 21:19

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.
wd5gnr
 
Posts: 16
Joined: 21. Oct 2008, 02:47

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

Postby gordboy » 31. Dec 2010, 14:28

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.
gordboy
 

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

Postby edb » 31. Dec 2010, 20:38

@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
edb
 
Posts: 2
Joined: 10. Nov 2010, 06:45
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: XP (so far)

PreviousNext

Return to VirtualBox on Linux Hosts

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 16 guests