Discussion:
Would like to mount vmdk virtual disk on host
JD
2011-06-02 16:44:01 UTC
Permalink
Is there a way to mount a vmdk virtual
disk (ext2 FS) on a linux host?
Some blogs claimed that all you need to
do is find the offset of where the FS starts
within the vmdk file.
Could someone please provide some link
or info on how to proceed?

Thanx,

JD
jdd
2011-06-02 18:56:08 UTC
Permalink
Is there a way to mount a vmdk virtual disk (ext2 FS) on a linux
host?
I have to thank you because I wondered how to do that and searching
for you I found the solution

on the opensuse OBS, I found "vbfuse" (virtual box fuse).

This utility mounts any virtual drive as fuse file system. In this
file system you find the partitions as raw images, so you can mount
them as normal disk

beware, I don't know if you can mount then rw, but writting them may
destroy them...


jdd
--
http://www.dodin.net
http://www.youtube.com/user/jdddodinorg
http://jdd.blip.tv/
JD
2011-06-02 19:06:44 UTC
Permalink
Post by jdd
Is there a way to mount a vmdk virtual disk (ext2 FS) on a linux
host?
I have to thank you because I wondered how to do that and searching
for you I found the solution
on the opensuse OBS, I found "vbfuse" (virtual box fuse).
This utility mounts any virtual drive as fuse file system. In this
file system you find the partitions as raw images, so you can mount
them as normal disk
beware, I don't know if you can mount then rw, but writting them may
destroy them...
jdd
I downloaded the source and tried to build it.
I generated huge number of compilation errors.
It is not clear which version of the VB header
files it needs in order for it to compile.
My OS is Fedora 14.

Also, I found this script on google code site:

http://code.google.com/p/vdimount/downloads/detail?name=vdimount.sh&can=2&q=

which claims to be able to mount a vdi. The caveat is that the vdi has
to be of fixed size.

I do not have a fixed size vdi. Mine is variable size, and would
like to convert it to fixed size so I can use this script.

Cheers,

JD
jdd
2011-06-02 19:21:11 UTC
Permalink
Post by JD
I downloaded the source and tried to build it.
may be try an opensuse rpm? ,I also use variable size disks
Post by JD
I do not have a fixed size vdi. Mine is variable size, and would
like to convert it to fixed size so I can use this script.
don't know.

It should be pretty easy to figure out the vdi structure (may be it's
described in the source code or in help). one have just to figure out
the virtualbox offset to the beginning of the disk. After that a fdisk
-l in the guest gives you the ofset in the disk.

mounting loop ro is harmless

jdd
--
http://www.dodin.net
http://www.youtube.com/user/jdddodinorg
http://jdd.blip.tv/
jdd
2011-06-02 19:22:39 UTC
Permalink
Post by jdd
Post by JD
I downloaded the source and tried to build it.
may be try an opensuse rpm? ,I also use variable size disks
http://software.opensuse.org/search?q=vdfuse&baseproject=ALL&lang=fr&exclude_debug=true

jdd
--
http://www.dodin.net
http://www.youtube.com/user/jdddodinorg
http://jdd.blip.tv/
JD
2011-06-02 20:00:47 UTC
Permalink
Post by jdd
Post by JD
I downloaded the source and tried to build it.
may be try an opensuse rpm? ,I also use variable size disks
Post by JD
I do not have a fixed size vdi. Mine is variable size, and would
like to convert it to fixed size so I can use this script.
don't know.
It should be pretty easy to figure out the vdi structure (may be it's
described in the source code or in help). one have just to figure out
the virtualbox offset to the beginning of the disk. After that a fdisk
-l in the guest gives you the ofset in the disk.
fdisk -l does not give offset of logical drive from start
of the file. The file contains lots of structures meaningful
only to VB, and you have to skip all that before fdisk can
give you meaningful info. So VB presents to the kernel
something that looks just like a hard drive.
Post by jdd
mounting loop ro is harmless
jdd
jdd
2011-06-02 20:07:56 UTC
Permalink
Post by JD
fdisk -l does not give offset of logical drive from start
of the file. The file contains lots of structures meaningful
only to VB
not sure it's true as vb can use raw disks, vdfuse do just what I
said, as you have the vdfuse sources you can guess where is the
offset. either it's constant or there is a pointer to the disk on the
very first bytes of the file. using the vb library is probably
mandatory for variable size disks where data is stored in various
locations


vdfuse:

DESCRIPTION: This Fuse module uses the VirtualBox access library to
open a VirtualBox supported VD image file and mount it as a Fuse file
system. The mount point contains a flat directory containing the
files EntireDisk, Partition1 .. PartitionN. These can then be loop
mounted to access the
underlying file systems

USAGE: vdfuse [options] -f image-file mountpoint
-h help
-r readonly
-t specify type (VDI, VMDK, VHD, or raw; default: auto)
-f VDimage file
-a allow all users to read disk
-w allow all users to read and write to disk
-g run in foreground
-v verbose
-d debug

NOTE: you must add the line "user_allow_other" (without quotes)
to /etc/fuse.conf and set proper permissions on /etc/fuse.conf
for this to work.

jdd
--
http://www.dodin.net
http://www.youtube.com/user/jdddodinorg
http://jdd.blip.tv/
JD
2011-06-02 20:43:38 UTC
Permalink
Post by jdd
Post by JD
fdisk -l does not give offset of logical drive from start
of the file. The file contains lots of structures meaningful
only to VB
not sure it's true as vb can use raw disks, vdfuse do just what I
said, as you have the vdfuse sources you can guess where is the
offset. either it's constant or there is a pointer to the disk on the
very first bytes of the file. using the vb library is probably
mandatory for variable size disks where data is stored in various
locations
DESCRIPTION: This Fuse module uses the VirtualBox access library to
open a VirtualBox supported VD image file and mount it as a Fuse file
system. The mount point contains a flat directory containing the
files EntireDisk, Partition1 .. PartitionN. These can then be loop
mounted to access the
underlying file systems
USAGE: vdfuse [options] -f image-file mountpoint
-h help
-r readonly
-t specify type (VDI, VMDK, VHD, or raw; default: auto)
-f VDimage file
-a allow all users to read disk
-w allow all users to read and write to disk
-g run in foreground
-v verbose
-d debug
NOTE: you must add the line "user_allow_other" (without quotes)
to /etc/fuse.conf and set proper permissions on /etc/fuse.conf
for this to work.
jdd
I downloaded the source rpm as you suggested.
I had to modify the spec file to suit fedora AFA Required packages are
concerned,
and it built just fine.
I am using it now and it seems to be working flawlessly.
Thank you very much for the location of the srpm.
I will browse the source code to learn more about the
structure of the vdi file.

Cheers,

JD
jdd
2011-06-02 20:49:36 UTC
Permalink
Post by JD
I downloaded the source rpm as you suggested.
I had to modify the spec file to suit fedora AFA Required packages are
concerned,
and it built just fine.
this is extremely good. You should inform of this the obs maintainer,
it may be able to add fedora to his build target with your patch!!
this is opensource :-)))

jdd
--
http://www.dodin.net
http://www.youtube.com/user/jdddodinorg
http://jdd.blip.tv/
JD
2011-06-02 21:13:35 UTC
Permalink
Post by jdd
Post by JD
I downloaded the source rpm as you suggested.
I had to modify the spec file to suit fedora AFA Required packages are
concerned,
and it built just fine.
this is extremely good. You should inform of this the obs maintainer,
it may be able to add fedora to his build target with your patch!!
this is opensource :-)))
jdd
I am not sure who the obs maintainer is.
I am subscribed to the fedora users group.
From all the posts and responses I have seen,
I gather they are not very amenable to such
suggestions.
If you wish to submit the changes to the
Fedora/Redhat/Centos/Scientific Linux/ distros,
please feel free to do so.
I attach the modified vdfuse.spec to the messages.

Cheers,

JD
jdd
2011-06-02 20:42:38 UTC
Permalink
what a did as test.

Create the smaller possible vb disk (4Mo) - fixed size.

attach it to an other virtual machine running openSUSE.

on this machine issue fdisk -l. see the new disk is exactly 4,194,304
bytes.

go to the host, see the file is 4,202,496 bytes. The offset is 8,192
bytes...

format the disk from the guest (mkfs.msdos /dev/sdb -I). mount it
mount /dev/sdb /mnt

create a file: touch /mnt/essai

on the host (the disk was on the "machine folder)

mkdir mnt-test
mount -o loop,offset=8192 test2.vdi mnt-test/

ls mnt-test/
essai

notice you can't fail with loop because the loop driver wont mount an
incorrect drive (try with 8191 or 8193)

thus if you create a drive the exact same size as you original, you
must have the same offset and can calculate it with the same way.
don't know if this works with a variable size disk, may be if there
are no snapshots

jdd
--
http://www.dodin.net
http://www.youtube.com/user/jdddodinorg
http://jdd.blip.tv/
JD
2011-06-02 21:09:37 UTC
Permalink
Post by jdd
what a did as test.
Create the smaller possible vb disk (4Mo) - fixed size.
attach it to an other virtual machine running openSUSE.
on this machine issue fdisk -l. see the new disk is exactly 4,194,304
bytes.
go to the host, see the file is 4,202,496 bytes. The offset is 8,192
bytes...
format the disk from the guest (mkfs.msdos /dev/sdb -I). mount it
mount /dev/sdb /mnt
create a file: touch /mnt/essai
on the host (the disk was on the "machine folder)
mkdir mnt-test
mount -o loop,offset=8192 test2.vdi mnt-test/
ls mnt-test/
essai
notice you can't fail with loop because the loop driver wont mount an
incorrect drive (try with 8191 or 8193)
thus if you create a drive the exact same size as you original, you
must have the same offset and can calculate it with the same way.
don't know if this works with a variable size disk, may be if there
are no snapshots
jdd
That's great info. Thanx a lot.

The caveat I now have with vdfuse is that
I am unable to umount the mount point on
which I mounted the vmdk/vdi disk.

# umount -f /mnt/l0
umount2: Device or resource busy
umount: /mnt/l0: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
umount2: Device or resource busy

# lsof | egrep '/mnt/l0|loop0'
lsof: WARNING: can't stat() fuse.vdfuse file system /mnt/l0
Output information may be incomplete.
loop0 9624 kroot cwd DIR 8,2 4096 2 /
loop0 9624 kroot rtd DIR 8,2 4096 2 /
loop0 9624 kroot txt unknown /proc/9624/exe

# mount
.
.
.
.
Knoppix-6.4.4.vmdk on /mnt/l0 type fuse.vdfuse
(rw,nosuid,nodev,allow_other,user=jd)

So, there is a process, loop (which must be the vdfuse process???)
which is holding an open fd to the mount point, and so I am unable
to unmount it.

I tried to kill -9 9624 several times, to no avail.

And look at this:
# ls -l /proc/9624/exe
/bin/ls: cannot read symbolic link /proc/9624/exe: No such file or directory
lrwxrwxrwx 1 kroot root 0 Jun 2 13:26 /proc/9624/exe

This must be a bug!!
jdd
2011-06-02 22:13:55 UTC
Permalink
Post by JD
The caveat I now have with vdfuse is that
I am unable to umount the mount point on
which I mounted the vmdk/vdi disk.
I could do it with umount

but I had two mounts (the partition and the fuse), so of course first
umount the partition, then fuse.

but I already had such problem. If you are sure you don't have any
open file in the drive, simply "vi /etc/mtab" and remove the offending
line.

it's somewhere rude, bu it works :-))

reported your patch on openSUSE bugtracking system
https://bugzilla.novell.com/show_bug.cgi?id=697812

jdd
--
http://www.dodin.net
http://www.youtube.com/user/jdddodinorg
http://jdd.blip.tv/
JD
2011-06-02 22:30:00 UTC
Permalink
Post by jdd
Post by JD
The caveat I now have with vdfuse is that
I am unable to umount the mount point on
which I mounted the vmdk/vdi disk.
I could do it with umount
but I had two mounts (the partition and the fuse), so of course first
umount the partition, then fuse.
but I already had such problem. If you are sure you don't have any
open file in the drive, simply "vi /etc/mtab" and remove the offending
line.
it's somewhere rude, bu it works :-))
reported your patch on openSUSE bugtracking system
https://bugzilla.novell.com/show_bug.cgi?id=697812
jdd
Sorry! That did not help. It remains open by the process [loop0]
I will just reboot.

Cheers,

JD

Continue reading on narkive:
Search results for 'Would like to mount vmdk virtual disk on host' (Questions and Answers)
4
replies
what is .vmdk extension file ????????????
started 2012-09-12 00:10:51 UTC
software
Loading...