Skip to main content

Thread: Script for Mounting Virtualbox VDI in Ubuntu and Debian


i've made script making whole process of mounting virtualbox vdi disks in ubuntu less of pain. script should work in debian os can't garuntee have yet test on ubuntu.

script has lot of bells , whistles let me know if find bug or have other suggestions.

update: vdimount has permanent home! can follow updates , subscribe rss feed via it's new page on filetrip here: http://filetrip.net/pc-downloads/oth...sk-f28663.html

features:
-optional install /usr/bin allow easy command use(ie: type vdimount use it)(if no wish install later use th "rs" option in script)
-autocheck if needed dependencies installed
-give option install , setup needed dependencies if not installed
-mode chooser
-drag'n'drop abilities selecting vdi file(see changelog)
-once selected, partition table vdi displayed
-choose partition in vdi mount
-check if vdi mounted , give details on mount

features i'm working on:
-multiple partition mounting
-multiple vdi mounting
-more informative display
-more informative error checks , displays
-... whatever else think of(or if have idea post below)

download:
vdimount_1.6.sh (4 kb)
filetrip page
http://www.multiupload.com/aj965paosj
http://mir.cr/0hcnbjcq

vdimount_1.5.sh (4 kb)
filetrip page
http://www.multiupload.com/0iahu9j3p8


vdimount_1.0.sh (2 kb)
filetrip page
http://www.multiupload.com/w85zbjuhbt


code:
#!/bin/bash if [ "$(id -u)" != "0" ]; echo 'this script must run root' exit 1 fi settings=~/vdimount.txt canonpath=`readlink -f "$0"` folderpath=`dirname "$canonpath"` if [ -e "/media" ]; 	mountdir=/media/vdi 	else 	mountdir=/mnt/vdi fi binskip=`grep -o "binskip" $settings` if [ "$binskip" != binskip ]; 	if [ "$folderpath" != /usr/bin ]; 		echo "-----------------------------------------------" 		echo "install script command(/usr/bin)? [y/n]" 		read bininstall 		echo "-----------------------------------------------" 		if [ "$bininstall" = y ]; 			echo binskip >> $settings 			cp "$canonpath" /usr/bin/vdimount 			chmod +rx /usr/bin/vdimount 			echo "script installed /usr/bin 'vdimount'" 			echo "restart terminal changes take effect" 			read -p "press key exit..." presss 			exit 1 		fi 	fi 	echo binskip >> $settings fi checknbd=`dpkg-query -w -f='${status}' qemu-kvm` if [ "$checknbd" != "install ok installed" ]; 	echo "missing deppendencies!" 	read -p "install them?[y/n]" installnbd 	if [ $installnbd = y ]; 		apt-get install qemu-kvm 		rmmod nbd 		modprobe nbd max_part=9 		echo "dependencies setup , installed!!" 		read -p "press key continue..." 	else 		echo "script can't run without them!" 		exit 1 	fi fi nbdmount=`ls /dev | grep "nbd"` if [ -z "$nbdmount" ]; 	modprobe nbd max_part=9 fi clear echo "vdi mounter v1.6" echo "-----------------------------------" echo "what do?" echo "1: mount vdi" echo "2: unmount vdi (2-f: force unmount)" echo "3: check vdi mount" echo "rs: clear settings file" read userselect  if [ "$userselect" = 1 ]; 	if mountpoint -q "$mountdir"; 		echo "**********************************************" 		echo "vdi mounted! unmount first before mounting again!" 		exit 1 	fi 		echo "-----------------------------------------------" 		echo "enter vdi location:(full path without quotes)"; 		read vdi 		echo "-----------------------------------------------" 		echo "you have selected: $vdi" 		qemu-nbd -c /dev/nbd0 $vdi 		echo "--vdi mounted--" 		read -p "press key continue" press 		clear 		echo "-----------------------------------------------" 		echo "vdi $vdi" 		sfdisk -lum /dev/nbd0 		echo "-----------------------------------------------" 		echo "enter partition mounted [ex:/dev/nbd0p1]" 		read device 		if [ $device =  ]; 			qemu-nbd -d /dev/nbd0 			echo "****************************"; echo "quitting because of error!"; exit 1 		fi 		if [ ! -e "$mountdir" ]; 			mkdir $mountdir 		fi 		mount $device $mountdir 		clear 		echo "-----------------------------------------------" 		echo "$device" 		echo "of" 		echo "$vdi" 		echo "mounted $mountdir" 		echo "-----------------------------------------------" fi if [ "$userselect" = 2 ]; 	if mountpoint -q "$mountdir"; 		umount $mountdir 		qemu-nbd -d /dev/nbd0 		echo "-----------------------------------------------" 		echo "vdi unmounted" 		exit 1 	else 		echo "**********************************************" 		echo "no vdi mounted!" 		echo "****************************"; echo "quitting because of error!"; exit 1 	fi fi if [ "$userselect" = "2-f" ]; 		umount $mountdir 		qemu-nbd -d /dev/nbd0 		echo "-----------------------------------------------" 		echo "vdi unmounted" 		exit 1 fi if [ "$userselect" = 3 ]; 	if mount | grep -q "/dev/nbd0"; 		echo "-----------------------------------------------" 		echo "a vdi mounted!" 		highlight=`mount | grep "/dev/nbd0"` 		echo "$highlight" 		exit 1 	else 		echo "**********************************************" 		echo "no vdi mounted!" 		echo "****************************"; echo "quitting because of error!"; exit 1 	fi fi if [ "$userselect" = rs ]; 	rm ~/vdimount.txt 	echo "-----------------------------------------------" 	echo "settings file cleared!" fi

changelog
v1.6(jan 13, 2012)
-fixed bug nbd devices weren't created after reboot
-reduces number of created nbd devices 16 9(otherwise disk utility gets full of unused devices)

v1.5(jan 4, 2012)
-removed drag'n'drop support because of fatal glitch(quotes not accepted tool, until can automate removal of quotes path has manually entered)
-fixed several other severe glitches
-added elements clean output
-added commands dependencies configured after install


Forum The Ubuntu Forum Community Ubuntu Specialised Support Virtualisation [ubuntu] Script for Mounting Virtualbox VDI in Ubuntu and Debian


Ubuntu

Comments

Popular posts from this blog

How to set the order of FAQs instead of alphabetical

Thread: Get UK Keyboard working

how do I change the e-mail address for my merchant account