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

Discussions related to using VirtualBox on Linux hosts.
h2o
Posts: 40
Joined: 9. Feb 2009, 04:46

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

Post by h2o »

[modedit] This is the remains of the howto, which can now be found at http://forums.virtualbox.org/viewtopic.php?f=26&t=33355.[/modedit]

Note that this is a restricted topic. If you want to discussion vdfuse then see the vdfuse discussion.
Last edited by h2o on 28. Jun 2010, 01:47, edited 3 times in total.
dlgroups31
Posts: 1
Joined: 8. Jan 2010, 14:09
Primary OS: Ubuntu 8.10
VBox Version: OSE Debian
Guest OSses: any

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

Post by dlgroups31 »

it shows only for mounting vdi files when linux is running
How to mount vdi files on linux while booting
means that how to boot from vdi files on linux hosts
wireless
Posts: 3
Joined: 10. Apr 2010, 01:44
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: Windows XP

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

Post by wireless »

Will this work for a dynamically expandable file system as well?
lfloyd
Posts: 1
Joined: 15. May 2010, 00:48
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: Ubuntu

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

Post by lfloyd »

My ubuntu.vdi won't boot because of grub error 17. So this thread is useless to a non-bootable linuxbox. I had made a backup, but it is a backup with the grub error. I'm trying to mount it so I can fix it. Need suggestions that don't include reinstalling an OS that I spent weeks working on. This whole problem started just trying to backup the ubuntu installation. Reinstalling a whole OS opens up a whole nother can of worms that could have been prevented if virtualbox had an easy to use backup sysyem compatible with virtualbox.
fixedwheel
Volunteer
Posts: 1699
Joined: 13. Sep 2008, 02:18

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

Post by fixedwheel »

h2o wrote:Note that this is a restricted topic. If you want to discussion vdfuse then see the vdfuse discussion.
my answer here is an exception, some admin please move this to its own or the discussion thread...
lfloyd wrote:My ubuntu.vdi won't boot because of grub error 17. So this thread is useless to a non-bootable linuxbox. I had made a backup, but it is a backup with the grub error. I'm trying to mount it so I can fix it.
:?: how to loopback mount the vdi on the host is what this thread is about
lfloyd wrote:Need suggestions that don't include reinstalling an OS that I spent weeks working on. This whole problem started just trying to backup the ubuntu installation. Reinstalling a whole OS opens up a whole nother can of worms that could have been prevented if virtualbox had an easy to use backup sysyem compatible with virtualbox.
if you need another solution w/o compiling vdfuse.c ... here is what i would do

boot your virtual machine with your ubuntu install CD .iso, select live CD option (not install)
when live CD up and running get a terminal, be root, mount your ubuntu .vdi filesystem (probably /dev/sda1) somewhere and chroot somewhere
then running update-grub could fix your problem
penteki
Posts: 4
Joined: 2. Oct 2009, 23:23
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: Linux, Windows

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

Post by penteki »

Hello, I'm unable to compile vdfuse-v70.c under Ubuntu 10.04 LTS (lucid). It seems like there's no package shipping VBoxHDD.h or VBoxHDD-new.h:
root@most:~# apt-file search VBoxHDD
root@most:~# apt-file search VBoxHDD.h
root@most:~# apt-file search VBoxHDD-new.h
root@most:~#
penteki
Posts: 4
Joined: 2. Oct 2009, 23:23
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: Linux, Windows

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

Post by penteki »

stefan.becker wrote:Have you read Top 1) above?
well, at this point, I didn't... sorry :(
i8degrees
Posts: 1
Joined: 3. Jul 2010, 09:13
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: Debian, FreeBSD, Ubuntu

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

Post by i8degrees »

Awesome! I just used your script to complete the preparation of my customized OS disk for imaging on over to its real home -- a 2GB CF-II card w/ adapter for IDE use. Computating offsets, while good practice, becomes awfully annoying when you are just trying to get a project quickly under wraps ... thank you for providing this script & saving me time! :-)

Virtualbox, whereas it was a tid bit slow due to my aging hardware, greatly simplified the testing process for bootstrapping a couple disk array nodes across RAID10 and glusterfs. Eight virtual disk drives over software RAID, including LVM volumes and all via virtualization on a close-to identical physical hardware platform. Gotta love it...! :-D
jrobiso2
Posts: 6
Joined: 19. Jul 2010, 01:28
Primary OS: openSUSE
VBox Version: OSE other
Guest OSses: openSuSE

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

Post by jrobiso2 »

What's the chance that this procedure will allow me to somehow fix a bad snapshot? The CloneVDI tool tells me that one of my earliest snapshots has a bad block map. If the snap were a normal disk, I'd try to fsck it somehow, but being a snap, it's not the same :-(

My users have lost 6 months of emails from this, so any help fixing this snap (so that CloneVDI can fix/rebuild properly) would be greatly appreciated!
MarcoV
Posts: 1
Joined: 4. Aug 2010, 16:17
Primary OS: MS Windows 7
VBox Version: OSE Debian
Guest OSses: Ubuntu 10.0.4

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

Post by MarcoV »

Hello all, hope everything doing fine, I have a problem with VM using linux host, VM installed great but when I turn on the machine and ubuntu start running an error appers " Unable to allocate memory the virtual machine will be paused, please close aplications to free up memory or close the vm, ID error HostMemoryLow", I´m using Windows 7 on my laptop with 1GB RAM, 2.16GHz, already tried to change the memory options in the VM to up of 512 a less to 256GB as a recomendation on the web but the error always appers, Can somebody help me with this thinkg :?: , Thanks !!!!
sid.mallya
Posts: 1
Joined: 30. Sep 2010, 16:08
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: Windows XP

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

Post by sid.mallya »

Hey .. In the tutorial I could execute all command but the last mount one .. What is the exact equivalent for "./vdfuse-v<version> -f image.vdi /mnt/vdi" ?

I have a vmdk file.
norberto
Posts: 1
Joined: 22. Mar 2011, 20:19
Primary OS: Ubuntu other
VBox Version: OSE other
Guest OSses: GNU/Linux many flavours

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

Post by norberto »

Code: Select all

#!/bin/sh
###
#
# Project:      Automounting VirtualBox VDI raw images in GNU/Linux
#
# File name:    vdimount.sh
# Description:  This script automount any mountable filesystem inside
#               any primary partition of a VirtualBox VDI raw image on
#		GNU/Linux. HDD unit is accesible through a loop device
#               like /dev/loop[X]
#   
# author:       Norberto Fernandez (c) 2011.
# version:      0.1.1
#   
# see The GNU Public License (GPL)
# 
# This program is free software; you can redistribute it and/or modify 
# it under the terms of the GNU General Public License as published by 
# the Free Software Foundation; either version 3 of the License, or 
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful, but 
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
# for more details.
# 
# You should have received a copy of the GNU General Public License along 
# with this program; if not, write to the Free Software Foundation, Inc., 
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
###
#
# Usage: ./vdimount.sh <path-to-vdi-image> <mount-point> [partition-number]
#
###

vdifile=$1
mountpoint=$2

partition=1
if [ "$3" != "" ]; then
	partition=$3
fi

image_type=`od -j0x004C -N4 -i $vdifile | awk '{print $2}'`

if [ $image_type = 2 ]; then

	offset_data=`od -j0x0158 -N4 -tu4 $vdifile | awk '{print $2}'`
	disk_size=`od -j0x0170 -N8 -tu8 $vdifile | awk '{print $2}'`

	file_size=`ls -la $vdifile | awk '{print $5}'`
	header_size=`echo "scale=0;$file_size-$disk_size" | bc -l`

	if [ $offset_data = $header_size ]; then

		echo "VDI Image is Static and File Size match OK"
		echo "VDI Bytes Offset to HDD raw image is $offset_data"

		loop_device=`sudo losetup -f`
		sudo losetup $loop_device -o $offset_data $vdifile
		part_info=`sudo parted $loop_device unit s print | grep ^.$partition | sed 's/\([0-9]\+\)s/\1/g' | awk '{print $1,$2,$3,$4,$5,$6,$7}'`

		part_type=`echo $part_info | awk '{print $5}'`

		if [ $part_type = 'primary' ]; then

			filesystem=`echo $part_info | awk '{print $6}'`
			part_sect_off=`echo $part_info | awk '{print $2}'`
			part_offset=`echo "scale=0;$part_sect_off*512" | bc -l`

			if [ $part_offset != 0 ]; then

				total_offset=`echo "scale=0;$offset_data+$part_offset" | bc -l`

				echo "HDD Bytes Offset to Partition $partition is $part_offset"
				echo "VDI Bytes Offset to Partition $partition is $total_offset"

				echo "Partition $partition: Primary with Filesystem $filesystem,"
				echo "will be mounted on $loop_device loop device."

				sudo mount -t $filesystem -o offset=$part_offset $loop_device $mountpoint
			
				if [ $? = 0 ]; then
					echo "Partition $partition from VDI $vdifile was succesfully mounted on $mountpoint"
					exit 0
				fi
			fi
		fi
		sudo losetup -d $loop_device
	fi
fi
echo "Partition $partition from VDI $vdifile can't be mounted"
exit 1

przemoc
Posts: 32
Joined: 4. Sep 2008, 16:02
Primary OS: MS Windows other
VBox Version: PUEL
Guest OSses: Linux, Windows, DragonFlyBSD, FreeBSD, NetBSD, OpenBSD
Location: Poland

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

Post by przemoc »

So another version of "boosted" recipe I posted on my wiki 2.5 years ago is floating on the net? This time with losetup (TBH don't remember all previous incarnations, so cannot tell whether losetup was used before).
And again, w/o any origin information pointing to http://wiki.przemoc.net/tips/linux#moun ... size_image. Yet information about alleged author and license takes 1/3 of the script. ;)

Just saying. :)
Desktop: NUC11PHKi7C [Core i7-1165G7 @ 2.80GHz, DDR4-3200 32GB RAM, GeForce RTX 2060, M.2 NVMe SSD 2TB] | 32UN880-B
Laptop: ThinkPad T430 (2344-56G) [Core i7 3520M @ 2.9GHz, DDR3-1600 8GB RAM, NVS 5400M, SATA3 SSD 512GB]
NeBlackCat
Posts: 154
Joined: 3. Aug 2008, 13:37

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

Post by NeBlackCat »

Anyone know if it's possible to copy the vdfuse program from an OSE installation to a PUEL one, and use it to mount VHDs?

I'm assuming the libs (not many from a look at what readelf dumps out) it needs are present in both versions.

I'm actually trying it now, but so far it doesn't want to run ("./vdfuse: 1: Syntax error: end of file unexpected"), so I'm wondering if there's some (probably completely obvious) reason why this is a no-go from the outset.
Locked