vboxlive - running live CDs in VBox disk-less vms

This script can be used to run Linux live CDs in (the same or different) virtual machines under VirtualBox. You’re welcome to report bugs in this thread if you find any. To make it easier to install, I put several of my vm scripts - including VBoxExtensionPack (Update VirtualBox-4.0 Extension Pack.), vm-create (vm-create : create kvm virtual machines), vm-bridge(vm-bridge : convert virtual machines from NAT to bridge or bridge to NAT) and the popup libray optionally used by these scripts to display error messages in QT/GTK style (dialog boxes in bash scripts) in the package [b]vmscripts[/b] in my repo - available for openSUSE 11.3, 11.4, Fedora 14, 15 and Mandriva 2010. I haven’t updated the vm-create script, intended to install kvm virtual machines from anywhere to anywhere, for a while. But I probably because I use this script.

vboxlive is neither very long nor very complicated. It is mostly used to quickly take a look at other distros live CDs. I’m not planning to add more features. Of course, once you have created a virtual machine to run a live CD (although you don’t have to create a specific one), you can edit it in VirtulaBox GUI, add a virtual disk and use it later to install the distro. You can also use the same default virtual machine (which is called ‘LiveCD’) to boot all your live images (obviously not simultaneously). Disk-less virtual machines use NO space on your harddisk. You need to have the iso file though (either on a local or external hard disk, or on a nfs mounted filsesystem).

#! /bin/bash
#: Title       : vboxlive
#: Date Created: Fri Sep 16 10:20:13 PDT 2011
#: Last Edit   : Mon Sep 19 12:59:35 PDT 2011
#: Author      : please_try_again (Agnelo de la Crotche)
#: Version     : 1.0
#: Description : runs Linux Live CD 'on the fly' in diskless virtual machines
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# you might need to change these values 
ram=1024          # Memory to allocate to the virtual machine (in MB)
vram=128          # video memory to allcoate (in MB)
arch=32                   # default architecture (32 or 64)
isoDir=/srv/iso           # directory where your iso images are stored 
#
# you shouldn't need  to change these values 
audio=pulse               # none|null|oss|alsa|pulse
audioctl=hda              # ac97|hda|sb16
defaultMachine="LiveCD"   # name of the default virtual machine to run live CDs.
guestAddDir=(/usr/share/virtualbox /opt/VirtualBox/additions)
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# use the popup library if found
which popup &>/dev/null && source $(which popup)

# use popup functions if available
function Error { declare -F | grep -q error || exec echo "Error: $*" ; error "$*" ;}
function Warn  { declare -F | grep -q warn  && warn  "$*" || echo "Warning: $*" ;}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

machineDir=$(vboxmanage list systemproperties | sed -n 's/Default machine folder: *//p')
Ostypes=( $(vboxmanage list ostypes | sed -n '/Linux 2.6/,/Other Linux/s/ID: //p' | sed 's| (.*||;/Other/d;/Linux 2.6/d;/_64/d' | tr -d " " | sort -u))

[ -d  "$machineDir" ] || exec echo "ERROR: Default machine folder $machineDir not found. Script aborted."

function syntax {
    cat << EOFSYNTAX
usage:
   $(basename $0) [ options ]

options:
    -d --default      use default virtual machine instead of creating one
    -l --list         list available iso images
    -v --vms          list virtual machines
    -r --remove <vm>  remove vm
    -o --os  <OS>     os (Linux distro)
    -i --iso <file>   Live CD iso image
    -a --arch <32|64> architecture (32 or 64 bit). Default is 32bit.

EOFSYNTAX
exit
}

function chkarg() {
    [ "${1:0:1}" == "-" ] && exec echo "$2 requires an argument"
}

function getOsType() {
declare -l os=${1:-$Os}
declare -l o

for O in ${Ostypes
[li]} ; do[/li]    o=$O
    [ "${os##$o}" == "$os" ] || ostype=$O
done

if [ "x$ostype" == "x" ] ; then
    case $os in
        mepis*)   ostype=Debian ;;
        mageia*)  ostype=Mandriva ;;
        centos*)  ostype=RedHat ;; 
        *mint*)   ostype=Ubuntu ;;
        pcbsd*)   ostype=FreeBSD ;;
        *)        ostype=Linux26 ;;
    esac 
fi

[ "$arch" == "64" ] && ostype=${ostype}_64 
echo $ostype 
}

function removevm() {
    vboxmanage showvminfo $1 &>/dev/null && vm=$1 || { vboxmanage showvminfo ${1}-LiveCD &>/dev/null &&  vm=${1}-LiveCD ;}
    [ "$vm" ] && exec vboxmanage unregistervm $vm --delete || Error "Vm $vm doesn't exist"
}

function guestAdditions {
for d in ${guestAddDir
[li]} ; do[/li]    ga=$d/VBoxGuestAdditions.iso
    [ -f $ga ] && break
done
[ -f $ga ] && echo $ga
}

[ $# -eq 0 ] && syntax

args=`getopt -q -u -o hdlvr:o:i:a: -l help,default,list,vms,remove:,os:,iso:,arch: -- "$@"`
set -- $args

for i; do
    case "$i" in
    -d|--default) vmName=$defaultMachine ; shift ;;
    -h|--help) syntax ;;
    -l|--list)  ls -lH /srv/iso/ | awk '/iso$/ { printf "%-35s %s %s
", $9, $10, $11}' ; exit ;;
    -v|--vms)   exec vboxmanage list vms ;;
    -r|--remove)  a=$1 ; shift ; chkarg $1 $a;  removevm $1 ;;
    -o|--os)  a=$1 ; shift ; chkarg $1 $a;  Os="$1" ; shift  ;;
    -i|--iso)  a=$1 ; shift ; chkarg $1 $a;  iso="$1" ; shift  ;;
    -a|--arch) a=$1 ; shift ; chkarg $1 $a;  arch="$1" ; shift  ;;
    esac
done

if [ "$iso" ] ; then
    if [ "$(dirname $iso)" == "." ] ; then
        iso=$(basename $iso)
        [ -f $(pwd)/$iso ] && iso=$(pwd)/$iso || iso=$isoDir/$iso
    fi
    [ -f "$iso" ] || Error "iso image $iso not found"
fi

if [ "$Os" ] ; then
    vmName=${vmName:-${Os}-${defaultMachine}}
    Os=$(basename $Os .iso)

    [ "$vmName" != "$defaultMachine" ] && vboxmanage showvminfo $vmName &>/dev/null && ISO=$(vboxmanage showvminfo "$vmName" | sed -n 's/IDE Controller (1, 0).*: \(.*.iso\).*/\1/p')

    if [ ! -f "$iso" ] ; then
        if [ -f "$ISO" ] ; then
            iso=$ISO
        else
            [ -d "$isoDir" ] || Error "Default Machine Folder $isoDir not found." 
            iso="$isoDir/${Os}.iso"
            [ -f "$iso" ] || iso="$isoDir/${vmName}.iso"
            [ -f "$iso" ] || Error "You should specify an iso image"
        fi
    else
        [ -f "$ISO" -a "$ISO" == "$iso" ] && vboxmanage startvm $vmName
    fi 
else
    vmName=$defaultMachine
fi

[ -f "$iso" ] || Error "You should specify either an OS or an iso image"

gad=$(guestAdditions)

vboxmanage showvminfo $vmName &>/dev/null || {
[ -f $machineDir/$vmName/$vmName.vbox ] && vboxmanage registervm $machineDir/$vmName/$vmName.vbox || vboxmanage createvm --name "$vmName" --ostype $(getOsType $Os) --register 
}

vboxmanage modifyvm $vmName \
--memory $ram \
--vram $vram \
--boot1 dvd \
--boot2 floppy \
--ioapic on \
--pae off \
--rtcuseutc on \
--accelerate3d on \
--mouse usbtablet \
--usb on \
--audio $audio \
--audiocontroller $audioctl \
--ostype $(getOsType $Os)

vboxmanage showvminfo $vmName | grep -q "IDE Controller" || VBoxManage storagectl $vmName --name "IDE Controller" --add ide
vboxmanage showvminfo $vmName | grep -q "SATA Controller" || VBoxManage storagectl $vmName --name "SATA Controller" --add sata 
vboxmanage showvminfo $vmName | grep -q "$iso" || VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium $iso
vboxmanage showvminfo $vmName | grep -q "$gad" || [ "$gad" ] && VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 1 --device 1 --type dvddrive --medium $gad
vboxmanage showvminfo $vmName | grep -q "$iso" && vboxmanage startvm $vmName

As the description and usage of this script turned out looking like a How to, I posted it in the How to and FAQ subforum: Running Linux Live CDs in disk-less-virtual-machines-under-virtualbox

Thanks so much for your hard work please_try_again. I shall give it a try and let you know how well its works.

Thank You,

Fixed a small bug in vms listing: ls -lH output appears to be different in openSUSE and Mandriva. I added a function listvm, that uses find … -ls to get a more consistent output.

#! /bin/bash
#: Title       : vboxlive
#: Date Created: Fri Sep 16 10:20:13 PDT 2011
#: Last Edit   : Tue Sep 20 00:44:42 PDT 2011
#: Author      : please_try_again (Agnelo de la Crotche)
#: Version     : 1.0.1
#: Description : runs Linux Live CD 'on the fly' in diskless virtual machines
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# you might need to change these values 
ram=1024					 # Memory to allocate to the virtual machine (in MB)
vram=128					 # video memory to allcoate (in MB)
arch=32                      # default architecture (32 or 64)
isoDir=/srv/iso              # directory where your iso images are stored 
#
# you shouldn't need  to change these values 
audio=pulse                  # none|null|oss|alsa|pulse
audioctl=hda                 # ac97|hda|sb16
defaultMachine="LiveCD"      # name of the default virtual machine to run live CDs.
guestAddDir=(/usr/share/virtualbox /opt/VirtualBox/additions)
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# use the popup library if found
which popup &>/dev/null && source $(which popup)

# use popup functions if available
function Error { declare -F | grep -q error || exec echo "Error: $*" ; error "$*" ;}
function Warn  { declare -F | grep -q warn  && warn  "$*" || echo "Warning: $*" ;}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

machineDir=$(vboxmanage list systemproperties | sed -n 's/Default machine folder: *//p')
Ostypes=( $(vboxmanage list ostypes | sed -n '/Linux 2.6/,/Other Linux/s/ID: //p' | sed 's| (.*||;/Other/d;/Linux 2.6/d;/_64/d' | tr -d " " | sort -u))

[ -d  "$machineDir" ] || exec echo "ERROR: Default machine folder $machineDir not found. Script aborted."

function syntax {
	cat << EOFSYNTAX
usage:
   $(basename $0) [ options ]

options:
    -d --default      use default virtual machine instead of creating one
    -l --list         list available iso images
    -v --vms          list virtual machines
    -r --remove <vm>  remove vm
    -o --os  <OS>     os (Linux distro)
    -i --iso <file>   Live CD iso image
    -a --arch <32|64> architecture (32 or 64 bit). Default is 32bit.

EOFSYNTAX
exit
}

function chkarg() {
	[ "${1:0:1}" == "-" ] && exec echo "$2 requires an argument"
}

function getOsType() {
declare -l os=${1:-$Os}
declare -l o

for O in ${Ostypes[li]} ; do
[/li]	o=$O
	[ "${os##$o}" == "$os" ] || ostype=$O
done

if [ "x$ostype" == "x" ] ; then
	case $os in
		mepis*)   ostype=Debian ;;
		mageia*)  ostype=Mandriva ;;
		centos*)  ostype=RedHat ;; 
		*mint*)   ostype=Ubuntu ;;
		pcbsd*)   ostype=FreeBSD ;;
		*)        ostype=Linux26 ;;
	esac 
fi

[ "$arch" == "64" ] && ostype=${ostype}_64 
echo $ostype 
}

function removevm() {
	vboxmanage showvminfo $1 &>/dev/null && vm=$1 || { vboxmanage showvminfo ${1}-LiveCD &>/dev/null &&  vm=${1}-LiveCD ;}
	[ "$vm" ] && exec vboxmanage unregistervm $vm --delete || Error "Vm $vm doesn't exist"
}

function listvm() {
	[ -d "$isoDir" ] && find -H $isoDir -name "*.iso" -ls | awk '{ gsub(/.*\//, "", $11) ; printf "%-35s %s %s
", $11, $12, $13}' || Error "Default Machine Folder $isoDir not found." 
	exit
}

function guestAdditions {
for d in ${guestAddDir[li]} ; do
[/li]	ga=$d/VBoxGuestAdditions.iso
	[ -f $ga ] && break
done
[ -f $ga ] && echo $ga
}

[ $# -eq 0 ] && syntax

args=`getopt -q -u -o hdlvr:o:i:a: -l help,default,list,vms,remove:,os:,iso:,arch: -- "$@"`
set -- $args

for i; do
	case "$i" in
	-d|--default) vmName=$defaultMachine ; shift ;;
	-h|--help) syntax ;;
	-l|--list) listvm ;;
	-v|--vms)   exec vboxmanage list vms ;;
	-r|--remove)  a=$1 ; shift ; chkarg $1 $a;  removevm $1 ;;
	-o|--os)  a=$1 ; shift ; chkarg $1 $a;  Os="$1" ; shift  ;;
	-i|--iso)  a=$1 ; shift ; chkarg $1 $a;  iso="$1" ; shift  ;;
	-a|--arch) a=$1 ; shift ; chkarg $1 $a;  arch="$1" ; shift  ;;
	esac
done

if [ "$iso" ] ; then
	if [ "$(dirname $iso)" == "." ] ; then
		iso=$(basename $iso)
		[ -f $(pwd)/$iso ] && iso=$(pwd)/$iso || iso=$isoDir/$iso
	fi
	[ -f "$iso" ] || Error "iso image $iso not found"
fi

if [ "$Os" ] ; then
	vmName=${vmName:-${Os}-${defaultMachine}}
	Os=$(basename $Os .iso)

	[ "$vmName" != "$defaultMachine" ] && vboxmanage showvminfo $vmName &>/dev/null && ISO=$(vboxmanage showvminfo "$vmName" | sed -n 's/IDE Controller (1, 0).*: \(.*.iso\).*/\1/p')

	if [ ! -f "$iso" ] ; then
		if [ -f "$ISO" ] ; then
			iso=$ISO
		else
			[ -d "$isoDir" ] || Error "Default Machine Folder $isoDir not found." 
			iso="$isoDir/${Os}.iso"
			[ -f "$iso" ] || iso="$isoDir/${vmName}.iso"
			[ -f "$iso" ] || Error "You should specify an iso image"
		fi
	else
		[ -f "$ISO" -a "$ISO" == "$iso" ] && vboxmanage startvm $vmName
	fi 
else
	vmName=$defaultMachine
fi

[ -f "$iso" ] || Error "You should specify either an OS or an iso image"

gad=$(guestAdditions)

vboxmanage showvminfo $vmName &>/dev/null || {
[ -f $machineDir/$vmName/$vmName.vbox ] && vboxmanage registervm $machineDir/$vmName/$vmName.vbox || vboxmanage createvm --name "$vmName" --ostype $(getOsType $Os) --register 
}

vboxmanage modifyvm $vmName \
--memory $ram \
--vram $vram \
--boot1 dvd \
--boot2 floppy \
--ioapic on \
--pae off \
--rtcuseutc on \
--accelerate3d on \
--mouse usbtablet \
--usb on \
--audio $audio \
--audiocontroller $audioctl \
--ostype $(getOsType $Os)

vboxmanage showvminfo $vmName | grep -q "IDE Controller" || VBoxManage storagectl $vmName --name "IDE Controller" --add ide
vboxmanage showvminfo $vmName | grep -q "SATA Controller" || VBoxManage storagectl $vmName --name "SATA Controller" --add sata 
vboxmanage showvminfo $vmName | grep -q "$iso" || VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium $iso
vboxmanage showvminfo $vmName | grep -q "$gad" || [ "$gad" ] && VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 1 --device 1 --type dvddrive --medium $gad
vboxmanage showvminfo $vmName | grep -q "$iso" && vboxmanage startvm $vmName

So please_try_again, I got your vboxlive working and it is pretty neat I must say. I did struggle with getting it to startup at first. In the first version, you still had a hard coded isoDir entry somewhere, but I think it got fixed in your second version. I do not have your library loaded, but one box still popped up when I was trying to find the right command line syntax. I did struggle with setting the guestAddDir= values and I wonder why two values are grouped together? Finally, I decided to add a menu so I could select which iso file I wanted to use. I think this is a really cool setup. We need to discuss your external script and if that might should be built-in and consider I understand why you use it. So that you might see what an uninformed knucklehead might do with your bash script, here is how I hacked it up, but it works well for me now…

#! /bin/bash
#: Title       : vboxlive
#: Date Created: Fri Sep 16 10:20:13 PDT 2011
#: Last Edit   : Mon Sep 19 12:59:35 PDT 2011
#: Author      : please_try_again (Agnelo de la Crotche)
#: Version     : 1.0
#: Description : runs Linux Live CD 'on the fly' in diskless virtual machines
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# you might need to change these values 
ram=4096          # Memory to allocate to the virtual machine (in MB)
vram=128          # video memory to allcoate (in MB)
arch=64                   # default architecture (32 or 64)
isoDir=~/Downloads        # directory where your iso images are stored 
#
# you shouldn't need  to change these values 
audio=pulse               # none|null|oss|alsa|pulse
audioctl=hda              # ac97|hda|sb16
defaultMachine="LiveCD"   # name of the default virtual machine to run live CDs.
guestAddDir=('/home/public/VirtualBox VMs/' '/home/james/.VirtualBox/')
#
# Added Coding to display ISO files
#
TITLE="VboxLive - Version 1.00 - by please_try_again" 

if [ "$1" == "" ] ; then
  gui=true
else
  gui=false
fi

while $gui ; do
  tput clear
  echo "$TITLE" 
  echo
  echo "Using ISO Folder Named: $isoDir"
  echo

# Determine if the  isoDir folder Exists

  if [[ -d "$isoDir" ]] ; then
    counter=0
    declare -a distros
    cd $isoDir

# Find and display all files that end with .iso

    for i in *.iso ; do 
      if [ -f $i ] ; then
    let counter=counter+1
    distros[$counter]=$i 
    echo "$counter) ${distros[$counter]}"
      fi
    done

    if [[ $counter -eq 0 ]]; then
      echo
      echo "No ISO Distro Files were found!"
      echo
      gui=false
    fi

    echo
    echo -n "Please Select the ISO Distro you wish to use (q=Quit): "
    read CHOICE

# Determine if input is an integer number and in range

    if [[ $CHOICE =~ ^[0-9]+$ ]] ; then
      if [[ $CHOICE -le $counter ]] && [[ $CHOICE -gt 0 ]]; then
    gui=false
      fi
    else
      if [[ $CHOICE == [Qq] ]] ; then
    exit 0
      fi
    fi
  else
    echo
    echo "Folder $isoDir does not exist"
    echo
    gui=false
  fi
done

if [ "${distros[$CHOICE]}" != "" ] ; then
  $0 -i "${distros[$CHOICE]}"
fi

#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# use the popup library if found
which popup &>/dev/null && source $(which popup)

# use popup functions if available
function Error { declare -F | grep -q error || exec echo "Error: $*" ; error "$*" ;}
function Warn  { declare -F | grep -q warn  && warn  "$*" || echo "Warning: $*" ;}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

machineDir=$(vboxmanage list systemproperties | sed -n 's/Default machine folder: *//p')
Ostypes=( $(vboxmanage list ostypes | sed -n '/Linux 2.6/,/Other Linux/s/ID: //p' | sed 's| (.*||;/Other/d;/Linux 2.6/d;/_64/d' | tr -d " " | sort -u))

[ -d  "$machineDir" ] || exec echo "ERROR: Default machine folder $machineDir not found. Script aborted."

function syntax {
    cat << EOFSYNTAX
usage:
   $(basename $0) [ options ]

options:
    -d --default      use default virtual machine instead of creating one
    -l --list         list available iso images
    -v --vms          list virtual machines
    -r --remove <vm>  remove vm
    -o --os  <OS>     os (Linux distro)
    -i --iso <file>   Live CD iso image
    -a --arch <32|64> architecture (32 or 64 bit). Default is 32bit.

EOFSYNTAX
exit
}

function chkarg() {
    [ "${1:0:1}" == "-" ] && exec echo "$2 requires an argument"
}

function getOsType() {
declare -l os=${1:-$Os}
declare -l o

for O in ${Ostypes
[li]} ; do[/li]    o=$O
    [ "${os##$o}" == "$os" ] || ostype=$O
done

if [ "x$ostype" == "x" ] ; then
    case $os in
        mepis*)   ostype=Debian ;;
        mageia*)  ostype=Mandriva ;;
        centos*)  ostype=RedHat ;; 
        *mint*)   ostype=Ubuntu ;;
        pcbsd*)   ostype=FreeBSD ;;
        *)        ostype=Linux26 ;;
    esac 
fi

[ "$arch" == "64" ] && ostype=${ostype}_64 
echo $ostype 
}

function removevm() {
    vboxmanage showvminfo $1 &>/dev/null && vm=$1 || { vboxmanage showvminfo ${1}-LiveCD &>/dev/null &&  vm=${1}-LiveCD ;}
    [ "$vm" ] && exec vboxmanage unregistervm $vm --delete || Error "Vm $vm doesn't exist"
}

function listvm() {
    [ -d "$isoDir" ] && find -H $isoDir -name "*.iso" -ls | awk '{ gsub(/.*\//, "", $11) ; printf "%-35s %s %s
", $11, $12, $13}' || Error "Default Machine Folder $isoDir not found." 
    exit
}

function guestAdditions {
for d in ${guestAddDir
[li]} ; do[/li]    ga=$d/VBoxGuestAdditions.iso
    [ -f $ga ] && break
done
[ -f $ga ] && echo $ga
}

[ $# -eq 0 ] && syntax

args=`getopt -q -u -o hdlvr:o:i:a: -l help,default,list,vms,remove:,os:,iso:,arch: -- "$@"`
set -- $args

for i; do
    case "$i" in
    -d|--default) vmName=$defaultMachine ; shift ;;
    -h|--help) syntax ;;
    -l|--list) listvm ;;
    -v|--vms)   exec vboxmanage list vms ;;
    -r|--remove)  a=$1 ; shift ; chkarg $1 $a;  removevm $1 ;;
    -o|--os)  a=$1 ; shift ; chkarg $1 $a;  Os="$1" ; shift  ;;
    -i|--iso)  a=$1 ; shift ; chkarg $1 $a;  iso="$1" ; shift  ;;
    -a|--arch) a=$1 ; shift ; chkarg $1 $a;  arch="$1" ; shift  ;;
    esac
done

if [ "$iso" ] ; then
    if [ "$(dirname $iso)" == "." ] ; then
        iso=$(basename $iso)
        [ -f $(pwd)/$iso ] && iso=$(pwd)/$iso || iso=$isoDir/$iso
    fi
    [ -f "$iso" ] || Error "iso image $iso not found"
fi

if [ "$Os" ] ; then
    vmName=${vmName:-${Os}-${defaultMachine}}
    Os=$(basename $Os .iso)

    [ "$vmName" != "$defaultMachine" ] && vboxmanage showvminfo $vmName &>/dev/null && ISO=$(vboxmanage showvminfo "$vmName" | sed -n 's/IDE Controller (1, 0).*: \(.*.iso\).*/\1/p')

    if [ ! -f "$iso" ] ; then
        if [ -f "$ISO" ] ; then
            iso=$ISO
        else
            [ -d "$isoDir" ] || Error "Default Machine Folder $isoDir not found." 
            iso="$isoDir/${Os}.iso"
            [ -f "$iso" ] || iso="$isoDir/${vmName}.iso"
            [ -f "$iso" ] || Error "You should specify an iso image"
        fi
    else
        [ -f "$ISO" -a "$ISO" == "$iso" ] && vboxmanage startvm $vmName
    fi 
else
    vmName=$defaultMachine
fi

[ -f "$iso" ] || Error "You should specify either an OS or an iso image"

gad=$(guestAdditions)

vboxmanage showvminfo $vmName &>/dev/null || {
[ -f $machineDir/$vmName/$vmName.vbox ] && vboxmanage registervm $machineDir/$vmName/$vmName.vbox || vboxmanage createvm --name "$vmName" --ostype $(getOsType $Os) --register 
}

vboxmanage modifyvm $vmName \
--memory $ram \
--vram $vram \
--boot1 dvd \
--boot2 floppy \
--ioapic on \
--pae off \
--rtcuseutc on \
--accelerate3d on \
--mouse usbtablet \
--usb on \
--audio $audio \
--audiocontroller $audioctl \
--ostype $(getOsType $Os)

vboxmanage showvminfo $vmName | grep -q "IDE Controller" || VBoxManage storagectl $vmName --name "IDE Controller" --add ide
vboxmanage showvminfo $vmName | grep -q "SATA Controller" || VBoxManage storagectl $vmName --name "SATA Controller" --add sata 
vboxmanage showvminfo $vmName | grep -q "$iso" || VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium $iso
vboxmanage showvminfo $vmName | grep -q "$gad" || [ "$gad" ] && VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 1 --device 1 --type dvddrive --medium $gad
vboxmanage showvminfo $vmName | grep -q "$iso" && vboxmanage startvm $vmName

exit 0

# End Of Script

This is a winner concept for anyone that has loaded VirtualBox !!!

Thank You,

Hi James,

Did you read the HowTo: Running Linux live CDs in disk-less virtual machines under VirtualBox? I posted it there, because it looks like a How to and people don’t actually need to read or understand the script to use it and might install it from my repo if they wish. But it explained all the options in detail (I hope).

That’s right. I found the bug while testing the script under Mandriva (host, not guest!) and fixed it.

I guess it’s not possible. If you saw a box or something, then you must have popup somewhere in your path. Otherwise you would have seen an error message in your terminal, but not in a box.

I can explain that. But notice that, although I don’t usually write many comments in my scripts (definitely not enough), this variable was placed below this comment:

# you shouldn't need  to change these values 

And you shouldn’t in fact. The guest additions (not to be confused with Extensions!) are available on the host, as they normally belong to the VirtualBox package. It is an iso file which has to be mounted in the guest. In order to do that, it has to be attached to a (virtual) CD/DVD drive. That’s why the disk-less virtual machine created by the script has 2 dvd drives, one for the live CD iso image and the second for the guest additions, and the script already attaches the iso file to the second dvd drive. But it needs to know where this file is located on the host and that explains the value of guestAddDir, which is an array of directories. The reason I put these two directories is that I’m not only writing scripts for openSUSE (even if I post them only here). On most distros, including openSUSE, VBoxGuestAdditions.iso is in /usr/share/virtualbox (which is therefore the first in the array). But I found it in /opt/VirtualBox/additions under ArchLinux. If users were to run this script on another Linux host system that put the guests additions in another directory, they would just need to add this directory in the guestAddDir array. If the host system where you’re running VirtualBox is either openSUSE, Mandriva, Fedora, Ubuntu, ArchLinux and probably many others, you should not modify this array … but there are always exceptions.

Notice (as explained in the How To) that the guest additions are not needed at all on some guest systems, including openSUSE 12.1, that already include the VirtualBox drivers (so you can have a decent resolution or use full screen). On such systems, having VBoxGuestAdditions.iso attached or even mounted (it might get mounted automatically) is useless. Some people might even find it an annoyance. But you can’t know until you boot the guest system. So I decided to attach the guest additions because it’s simpler that way. I don’t think that a case differentiation of the guest system would be worth the code - not to mention that different releases of the same OS or different kernels of the same release might include the VBox drivers or not.

As for the menu, feel free to add any menu you like or find useful … but menus are not for me (even in restaurants - I’m unable to read them). As you might have noticed, my scripts are command line utilities, that I’m trying to make POSIX compliant - although I might be wrong about what this really means. I’m writing scripts to save me time and avoid user interfaces and be able to execute them from other scripts. I have a function to list iso files (vboxlive -l). It doesn’t just list iso files but also symlinks and the files they point to. Using symlinks is the preferred method (See why in the How to). Though using iso files is possible too an they can be anywhere - not just in the iso folder, although it makes more sense.

Hmmm … how the script handles iso files might be not obvious at a first glance:

if  "$iso" ] ; then
	if  "$(dirname $iso)" == "." ] ; then
		iso=$(basename $iso)
		 -f $(pwd)/$iso ] && iso=$(pwd)/$iso || iso=$isoDir/$iso
	fi
	 -f "$iso" ] || Error "iso image $iso not found"
fi

And if you don’t use the -i , the script has to determine the iso file to use. It reads its name & location from the virtual machine if it already exists (it might) … but if you give both options -o and -i, it will use the given iso file rather than the one stored in the virtual machine, so that you can boot your Ubuntu or Fedora or whatever other virtual machine with different iso images without changing the os type or creating a new virtual machine … That’s what I intended to do, at least. If it doesn’t work that way, it would be a bug.

I think the script is too clever (or at least tries to be) to benefit from menus. It really doesn’t just take a file from somewhere and open it. The name is important because it gives the os type which is used by VirtualBox to take default settings - although I bet these settings will be the same for all Linuxes. I do not recommend using iso files but creating symlinks instead and using them with the option -o (How To part II). It is faster, easier and more efficient. But it’s possible to use iso files directly as arguments because … everything has to be possible. Otherwise it won’t be fun.

It’s possible to enhance the script with a couple useful features, such as the ability to download iso images. I would simply save the urls in variables with the name of the different distros and use bash indirect expansion. It’s the most efficient.
Example:

ubuntu="ftp://ftp.osuosl.org/../pub/ubuntu-releases/oneiric/ubuntu-11.10-beta1-desktop-i386.iso"
opensuse="ftp://ftp.osuosl.org/pub/opensuse/distribution/12.1-Milestone5/iso/openSUSE-GNOME-LiveCD-Build0250-i686.iso"
wget ${!ubuntu}
wget ${!opensuse}

There are some examples in the file /etc/vm-create.cfg used by vm-create - a more complicated but also more featureful script I use for kvm.

I see what you thought guestAddDir was for. This is NOT the path of your virtual machines. You don’t have to specify that one and in fact it wouldn’t work. It is read from the VirtualBox configuration and stored in the variable machineDir.

machineDir=$(vboxmanage list systemproperties | sed -n 's/Default machine folder: *//p')

With the values you put in guestAddDir, you won’t be able to install the VBox drivers on guests that might require them. The only reason which could make you change this variable would be if you were using as host (not guest) a Linux distro I haven’t tested (it’s possible but …)

If you want to select an iso file out of a list, what about this:

iso=$isoDir/`choose radio $(find -H $isoDir -name "*.iso" -exec basename "{}" ";" | tr "
" "," | sed 's/,$//')`
 -f  $iso ] && .... do something

Install the package ‘dialog’ if you don’t have it and try this code after changing and exporting the variable DIALOG successively to the values DIALOG, KDIALOG and ZENITY. I don’t know why the list is incomplete with zenity (mine is quite long), but it’s probably a bug or a limitation in zenity.

See the kind of cool stuff you can do with the popup library? :wink:

So, I do now understand about the settings for guestAddDir=(/usr/share/virtualbox /opt/VirtualBox/additions) and put them back to the default. I have added in your extensive help to the bash script, but kept the same ISO listing section at the start I had before. You can find the much larger bash script on SuSE Paste and can download using wget.

wget -nc http://paste.opensuse.org/view/download/97626865 -O ~/bin/vboxlive

Once downloaded, you need to mark it executable and so run the following terminal command:

chmod +x ~/bin/vboxlive

In the bash script the line that says isoDir MUST be modified to the correct location where you keep your downloaded ISO files.

isoDir=/srv/iso        # directory where your iso images are stored 

On my computer, I use the folder isoDIR=~/Downloads and you may want to do the same. In KDE, you can edit this file with the following menu Run Command:

kwrite ~/bin/vboxlive

In GNOME you can use the following command to edit the vboxlive bash script.

gedit ~/bin/vboxlive

Again all credit for this very fine and super bash script goes to please_try_again. You must have installed VirtualBox before using this application.

Thank You,

Here’s a new version (2.0 ‘beta’) with several new features:

[ul]
[li]download iso images from a mirror site (if requested). [/li][li]ability to choose supported guests from a list.[/li][li]only display but don’t execute commands, including URL of iso image (when download enabled).[/li][li]display file open menu if the iso image specified at the command line doesn’t exist.[/li][li]add support for morel Linux distros, as well as openindiana and dragondlybsd.[/li][/ul]

An open file menu will be displayed if the iso image provided as an argument to the option -i doesn’t exist or simply if this option is used without argument. So if you prefer to open an iso image and boot it into a vm, you could just use:

vboxlive -i

I’ll post a detailled description later. Here’s the code:

#! /bin/bash
#: Title       : vboxlive
#: Date Created: Fri Sep 16 10:20:13 PDT 2011
#: Last Edit   : Wed Oct  5 22:06:05 PDT 2011
#: Author      : please_try_again (Agnelo de la Crotche)
#: Version     : 2.0beta
#: Description : runs Linux Live CD 'on the fly' in diskless virtual machines
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# source system and user configuration files
cfgfiles=(/etc/vboxlive.cfg ~/.vboxliverc)
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# use the popup library if found
which popup &>/dev/null && source $(which popup)

# use popup functions if available
function Error  { declare -F | grep -q 'error$' || exec echo "Error: $*" ; error "$*" ;}
function Warn   { declare -F | grep -q 'warn$'  && warn  "$*" || echo "Warning: $*" ;}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

machineDir=$(vboxmanage list systemproperties | sed -n 's/Default machine folder: *//p')
Ostypes=( $(vboxmanage list ostypes | sed -n '/Linux 2.6/,/Other Linux/s/ID: //p' | sed 's| (.*||;/Other/d;/Linux 2.6/d;/_64/d' | tr -d " " | sort -u))

[ -d  "$machineDir" ] || exec echo "ERROR: Default machine folder $machineDir not found. Script aborted."

function syntax {
	cat << EOFSYNTAX
usage:
   $(basename $0) [ options ]

options:
    -d --default      Use default virtual machine instead of creating one
    -D --download     Download iso image
    -l --list         List available iso images
    -g --guests       List downloadable iso images 
    -v --vms          List virtual machines
    -r --remove <vm>  Remove vm
    -R --release      OS version of guest to use
    -o --os <OS>      Os (Linux distro)
    -i --iso <file>   Live CD iso image
    -t --try          Only print commands but don't do anything.
    -m --menu         Select guest OS from menu. 
    -a --arch <32|64> Architecture (32 or 64 bit). Default is 32bit.

EOFSYNTAX
exit
}

function chkarg() {
	[ "${1:0:1}" == "-" ] && exec echo "$2 requires an argument"
}

function getOsType() {
declare -l os=${1:-$Os}
declare -l o

for O in ${Ostypes[li]} ; do[/li]	o=$O
	[ "${os##$o}" == "$os" ] || ostype=$O
done

if [ "x$ostype" == "x" ] ; then
	case $os in
		archbang*)ostype=ArchLinux ;;
		mepis*)   ostype=Debian ;;
		mageia*)  ostype=Mandriva ;;
		centos*)  ostype=RedHat ;; 
		*mint*)   ostype=Ubuntu ;;
		pcbsd*)   ostype=FreeBSD ;;
		openindiana*) ostype=OpenSolaris ;;
		dragonflybsd*) ostype=FreeBSD ;;
		*)        ostype=Linux26 ;;
	esac 
fi

[ "$arch" == "64" ] && ostype=${ostype}_64 
echo $ostype 
}

function removevm() {
	vboxmanage showvminfo $1 &>/dev/null && vm=$1 || { vboxmanage showvminfo ${1}-LiveCD &>/dev/null &&  vm=${1}-LiveCD ;}
	[ "$vm" ] && exec vboxmanage unregistervm $vm --delete || Error "Vm $vm doesn't exist"
}

function listvm() {
	[ -d "$isoDir" ] && find -H $isoDir -name "*.iso" -ls | awk '{ gsub(/.*\//, "", $11) ; printf "%-35s %s %s
", $11, $12, $13}' || Error "Default Machine Folder $isoDir not found." 
	exit
}

function guestAdditions {
for d in ${guestAddDir[li]} ; do[/li]	ga=$d/VBoxGuestAdditions.iso
	[ -f $ga ] && break
done
[ -f $ga ] && echo $ga
}

function getarch {
	case $1 in
	64)
		case $2 in
			debian*|dflybsd*|freebsd*|gentoo*|netbsd*|openbsd*|ubuntu*) echo amd64 ;;
			knoppix*) echo EN ;;
			mepis*|mint*|pclinux*) echo 64 ;;
			openindiana*) echo x86 ;;
			puppylinux*) echo lupu ;;	
			kanotix*) echo kanotix64 ;;
			*) echo x86_64 ;;
		esac
	;;
	32)
		case $2 in
			mageia*|mandriva*) echo i586 ;;
			debian*|centos*|ubuntu*|dragonflybsd*) echo i386 ;;
			gentoo*|openindiana*) echo x86 ;;
			knoppix) echo EN ;;
			mepis*|mint*) echo 32 ;;
			puppylinux*) echo lupu ;;	
			kanotix*) echo "kanotix-" ;;
			pclinux) echo $VER ;;
			*) echo i686 ;;
		esac
	;;
	esac
}

function downloadIso {
	[ -w $isoDir ] || Error "You don't write access to $isoDir."
	declare -l os=$Os
	ARCH=$(getarch $arch $os)
	VER=${os}_ver ; VER=${!VER} ; VER=${ver:-$VER}
	url=${os}_iso ; url=${!url} ; url=${url//ARCH/$ARCH} ; url=${url//VER/$VER}
	exp=${os}_exp ; exp=${!exp} ; exp=${exp:-$ARCH}
	
	[ "${url##*.}" == "iso" ] && URL=$url || URLS=($(links -dump $url 2>/dev/null | sed -n 's|\(\.iso\.*b*z*2*\).*|\1|p' | awk '/'$ARCH'/&&/'$exp'/{ print $NF }' | sort -u))
	if [ ${#URLS[li]} -gt 1 ] ; then[/li]		i=$(echo ${URLS[li]} | tr " " ",")[/li]		declare -F | grep -q ' choose$' && IMG=$(choose radio $i) || {
			N=0
			retry=""
			while [ $(( $N * 1 )) -lt 1 -o $(( $N * 1 )) -gt ${#URLS[li]} ] ; do[/li]    			echo ${URLS[li]}	| tr " " "[/li]" | awk '{ printf "[%s]  %s
", NR, $0 } ; END { E="'"$retry"'" ; printf "
%sPlease give a number between 1 and %s: ", E, NR}' 
				read  N
				[ "$N" ] || N=0
				retry="Invalid value. " 
    		done
			let N--
			IMG=${URLS[$N]}
		}
	elif [ ${#URLS[li]} -eq 1 ] ; then[/li]		IMG=${URLS[0]}
	elif [ "$URL" ] ; then
		IMG=$(basename $URL 2> /dev/null)
	else
		Error "Could not find an iso image to download."	
	fi 
	[ "$IMG" == " " ] || URL=${URL:-${url}/$IMG}
	[ "$URL" ] || Error "Could not find an iso image to download."	

	if [ "$TFLAG" ]; then
		echo "URL: $URL"
	else
		cd $isoDir
		wget $URL
		img=$(basename $IMG .bz2)
		[ "$img" == "$IMG" ] || bunzip2 $IMG && IMG=$img
		ln -sfn $IMG ${os}.iso
	fi
}

[ $# -eq 0 ] && syntax

# source system & user config files
for cfg in ${cfgfiles[li]} ; do[/li]	[ -f $cfg ] && source $cfg && CFG=YES 
done
[ "$CFG" ] && distros=($(set | sed -n 's/_iso=.*//p')) || Error "No configuration file found."

[ "${isoDir%%/}" == "$isoDir" ] && isoDir="${isoDir}/"

# parse arguments

[ "${@: -1}" == "-i" ] && OFLAG=1
args=`getopt -q -u -o hdDlvgtmr:R:o:i:a: -l help,default,download,list,vms,guests,try,menu,remove:,release:,os:,iso:,arch: -- "$@"`
set -- $args

for i; do
	case "$i" in
	-d|--default) vmName=$defaultMachine ; shift ;;
	-D|--download) DFLAG=yes ; shift ;;
	-h|--help) syntax ;;
	-l|--list)  ls -lH $isoDir | awk '/iso$/ { printf "%-35s %s %s
", $9, $10, $11}' ; exit ;;
	-v|--vms)   exec vboxmanage list vms ;;
	-g|--guests) exec echo ${distros[li]} ;;[/li]	-t|--try)  TFLAG=yes ; shift ;;
        -m|--menu)  MFLAG=yes ; shift ;;
	-r|--remove)  a=$1 ; shift ; chkarg $1 $a;  removevm $1 ;;
	-R|--release)  a=$1 ; shift ; chkarg $1 $a; ver="$1" ; shift ;;
	-o|--os)  a=$1 ; shift ; chkarg $1 $a;  Os="$1" ; shift  ;;
	-i|--iso)  a=$1 ; shift ; [ "${1:0:1}" == "-" -o "$*" == "" ] && OFLAG=1 || iso="$1" ; shift ;;
	-a|--arch) a=$1 ; shift ; chkarg $1 $a;  arch="$1" ; shift  ;;
	esac
done

if [ "$MFLAG" ] ; then
	if [ ${#distros[li]} -gt 1 ] ; then[/li]		DFLAG=yes
		i=$(echo ${distros[li]} | tr " " ",")[/li]		declare -F | grep -q ' choose$' && Os=$(choose radio $i) || {
			N=0
			retry=""
			while [ $(( $N * 1 )) -lt 1 -o $(( $N * 1 )) -gt ${#distros[li]} ] ; do[/li]    			echo ${distros[li]}	| tr " " "[/li]" | awk '{ printf "[%s]  %s
", NR, $0 } ; END { E="'"$retry"'" ; printf "
%sPlease give a number between 1 and %s: ", E, NR}' 
				read  N
				[ "$N" ] || N=0
				retry="Invalid value. " 
    		done
			let N--
			Os=${distros[$N]}
		}
		Os=${Os%% }
	else
		Error "No guest OS found."	
	fi
fi

if [ "$OFLAG" ] ; then
	declare -F | grep -q 'fileopen$' && iso=$(fileopen $isoDir) || read -e -i "$isoDir" -p "File name: "  iso
fi


if [ "$iso" ] ; then
	if [ "$(dirname $iso)" == "." ] ; then
		iso=$(basename $iso)
		[ -f $(pwd)/$iso ] && iso=$(pwd)/$iso || iso=${isoDir}$iso
	fi

	if [ ! -f $iso ] ; then
		declare -F | grep -q 'fileopen$' && iso=$(fileopen $isoDir) || read -e -i "$isoDir" -p "File name: "  iso
	fi

	[ -f "$iso" ] || Error "iso image $iso not found"
fi

if [ "$Os" ] ; then
	vmName=${vmName:-${Os}-${defaultMachine}}
	Os=$(basename $Os .iso)

	[ "$vmName" != "$defaultMachine" ] && vboxmanage showvminfo $vmName &>/dev/null && ISO=$(vboxmanage showvminfo "$vmName" | sed -n 's/IDE Controller (1, 0).*: \(.*.iso\).*/\1/p')

	if [ ! -f "$iso" ] ; then
		if [ -f "$ISO" ] ; then
			iso=$ISO
		else
			[ -d "$isoDir" ] || Error "Default Machine Folder $isoDir not found." 
			iso="${isoDir}${Os}.iso"
			[ -f "$iso" ] || iso="${isoDir}${vmName}.iso"
			[ ! -f "$iso" -a  "x$DFLAG" == "xyes" ] && downloadIso && iso="${isoDir}${Os}.iso"
			[ ! -f "$iso" -a  "x$TFLAG" != "xyes" ] && Error "You should specify an iso image or use the option -D to download one."
		fi
	else
		[ -f "$ISO" -a "$ISO" == "$iso" ] && vboxmanage startvm $vmName
	fi 
else
	vmName=$defaultMachine
fi

if [ "x$TFLAG" == "x" ] ;then
	[ -f "$iso" ] || Error "You should specify either an OS or an iso image"
fi

gad=$(guestAdditions)

if [ "x$TFLAG" == "x" ] ; then
vboxmanage showvminfo $vmName &>/dev/null || {
[ -f $machineDir/$vmName/$vmName.vbox ] && vboxmanage registervm $machineDir/$vmName/$vmName.vbox || vboxmanage createvm --name "$vmName" --ostype $(getOsType $Os) --register 
}
fi

if [ "$TFLAG" ] ; then
cat << EOFV

vboxmanage modifyvm $vmName
	--memory $ram
	--vram $vram 
	--boot1 dvd
	--boot2 floppy
	--ioapic on
	--pae off
	--rtcuseutc on
	--accelerate3d on
	--mouse usbtablet
	--usb on
	--audio $audio
	--audiocontroller $audioctl
	--ostype $(getOsType $Os)
EOFV
else
	vboxmanage modifyvm $vmName \
	--memory $ram \
	--vram $vram \
	--boot1 dvd \
	--boot2 floppy \
	--ioapic on \
	--pae off \
	--rtcuseutc on \
	--accelerate3d on \
	--mouse usbtablet \
	--usb on \
	--audio $audio \
	--audiocontroller $audioctl \
	--ostype $(getOsType $Os)
	
	vboxmanage showvminfo $vmName | grep -q "IDE Controller" || VBoxManage storagectl $vmName --name "IDE Controller" --add ide
	vboxmanage showvminfo $vmName | grep -q "SATA Controller" || VBoxManage storagectl $vmName --name "SATA Controller" --add sata 
	vboxmanage showvminfo $vmName | grep -q "$iso" || VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium $iso
	vboxmanage showvminfo $vmName | grep -q "$gad" || [ "$gad" ] && VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 1 --device 1 --type dvddrive --medium $gad
	vboxmanage showvminfo $vmName | grep -q "$iso" && vboxmanage startvm $vmName
fi

It was a long night + day and I don’t garantee it bugfree. That’s why I called it 2.0 ‘beta’.

This version uses the config file /etc/vboxlive.cfg:

# system wide /etc/vboxlive.cfg
# variables  in this file can be ovrewritten in ~/.vboxlive.cfg

declare -l DFLAG
#
# you might need to change these values 
ram=1024					 # Memory to allocate to the virtual machine (in MB)
vram=128					 # video memory to allocate (in MB)
arch=32                      # default architecture (32 or 64)
isoDir=/srv/iso              # directory where your iso images are stored 
DFLAG=no          			 # try to download live CD image if not found.
#
# you shouldn't need  to change these values 
audio=pulse                  # none|null|oss|alsa|pulse
audioctl=hda                 # ac97|hda|sb16
defaultMachine="LiveCD"      # name of the default virtual machine to run live CDs.
guestAddDir=(/usr/share/virtualbox /opt/VirtualBox/additions)

# You might change distros default versions
archbang_ver="2011.10"
archlinux_ver="20110104"
centos_ver="6"
chakra_ver="2011.09"
debian_ver="squeeze"
dragonflybsd_ver="2.10.1"
fedora_ver="15"
gentoo_ver="11.2"
kanotix_ver="Hellfire-2011-05"
knoppix_ver="6.7"
mageia_ver="1"
mandriva_ver="2010.2"
mepis_ver="11.0"
mint_ver="11"
openindiana_ver="151a"
opensuse_ver="11.4"
pclinux_ver="2011"
puppylinux_ver="5.2.8"
ubuntu_ver="oneiric"

# You might add/change ditros urls.
MIRROR1="ftp://ftp.osuosl.org/pub"
MIRROR2="ftp://ftp.uwsg.indiana.edu/linux"
MIRROR="$MIRROR1"

# official sites / primary mirrors.
archbang_mirror="http://sourceforge.net/projects/archbang"
archlinux_mirror="http://arch-live.isawsome.net/iso/archiso"
chakra_mirror="http://sourceforge.net/projects/chakra"
debian_mirror="ftp://cdimage.debian.org/cdimage/release"
dragonflybsd_mirror="ftp://mirror-master.dragonflybsd.org"
fedora_mirror="http://fedora.mirror.nexicom.net"
gentoo_mirror="http://distfiles.gentoo.org"
kanotix_mirror="ftp://linux.rz.ruhr-uni-bochum.de/kanotix"
mageia_mirror="ftp://mageia.webconquest.com"
mandriva_mirror="ftp://ftp.uwsg.indiana.edu"
openindiana_mirror="http://dlc.openindiana.org/isos"
opensuse_mirror="http://download.opensuse.org"
puppylinux_mirror="ftp://distro.ibiblio.org/pub/linux/distributions/puppylinux"
#ubuntu_mirror="http://cd.image.ubuntu.com/releases" 	# Ubuntu official site uses different paths. Don't use it!

# mirrors
centos_mirror="$MIRROR/centos"
debian_mirror="ftp://debian.osuosl.org/debian-cdimage"
fedora_mirror="$MIRROR/fedora"
gentoo_mirror="$MIRROR/gentoo"
knoppix_mirror="$MIRROR/knoppix"
mepis_mirror="ftp://mirror.cs.vt.edu/pub/MEPIS"
mint_mirror="ftp://linuxfreedom.com/linuxmint/linuxmint.com"
pclinux_mirror="ftp://ftp.ch.debian.org/mirror/pclinuxos"
ubuntu_mirror="$MIRROR/ubuntu-releases"
#opensuse_mirror="$MIRROR/opensuse"
#archlinux_mirror="$MIRROR/pub/archlinux"

archbang_iso="$archbang_mirror/files/archbang-VER-ARCH.iso"
archlinux_iso="$archlinux_mirror/VER/archiso-live-2011-01-04.iso"
centos_iso="$centos_mirror/VER/isos/ARCH"
chakra_iso="$chakra_mirror/files/VER"
debian_iso="$debian_mirror/current-live/ARCH/iso-hybrid"
dragonflybsd_iso="$dragonflybsd_mirror/iso-images"
fedora_iso="$fedora_mirror/linux/releases/VER/Live/ARCH"
gentoo_iso="$gentoo_mirror/releases/ARCH/VER"
kanotix_iso="$kanotix_mirror/KANOTIX-current"
knoppix_iso="$knoppix_mirror"
mageia_iso="$mageia_mirror/iso/VER"
mandriva_iso="$mandriva_mirror/linux/mandrake/official/iso/VER"
mepis_iso="$mepis_mirror"
mint_iso="$mint_mirror/stable/VER"
openindiana_iso="$openindiana_mirror/VER"
opensuse_iso="$opensuse_mirror/distribution/VER/iso"
pclinux_iso="$pclinux_mirror/live-cd"
puppylinux_iso="$puppylinux_mirror/puppy-VER"
ubuntu_iso="$ubuntu_mirror/VER"

# iso file name contains the following expression:
centos_exp="LiveCD"
debian_exp="desktop"
opensuse_exp="LiveCD"
knoppix_exp="$knoppix_ver"
mepis_exp="$mepis_ver"
mint_exp="dvd"
ubuntu_exp="desktop"
pclinux_exp="pclinuxos"
dragonflybsd_exp="$dragonflybsd_ver"

This file is included in the package vmscripts.
All variables in this file can be overwritten in the user ~/.vboxliverc.

Running Linux live CDs in disk-less virtual machines under VirtualBox

I have installed VirtualBox by using the Yast tools, in 12.1 And yes, it works - have run ubuntu in it.
When installing vboxlive using its repository, version 12.1 and run the script I get a box telling me that VirtualBox is not installed.
Looking into the script I see that VirtualBox is spelled like that in the " vboxinstalled=$(rpm -qa | grep VirtualBox) " which returns empty
as this is the way the rpms are named in 12.1
Maybe a new naming? Have to see if it is sufficient to change the rpm statement above.
me@linux:~> rpm -qa | grep virtual
virtualbox-guest-tools-4.1.4-3.2.3.x86_64
virtualbox-guest-kmp-default-4.1.4_k3.1.0_1.1-3.2.3.x86_64
virtualbox-host-kmp-desktop-4.1.4_k3.1.0_1.1-3.2.3.x86_64
virtualbox-guest-x11-4.1.4-3.2.3.x86_64
virtualbox-host-kmp-default-4.1.4_k3.1.0_1.1-3.2.3.x86_64
virtualbox-guest-kmp-desktop-4.1.4_k3.1.0_1.1-3.2.3.x86_64
virtualbox-qt-4.1.4-3.2.3.x86_64
virtualbox-4.1.4-3.2.3.x86_64
virtualbox-devel-4.1.4-3.2.3.x86_64
python-virtualbox-4.1.4-3.2.3.x86_64

This scriptlet fails when using the repository files from openSUSE.

If you install this version:

http://download.virtualbox.org/virtualbox/4.1.6/VirtualBox-4.1-4.1.6_74713_openSUSE114-1.x86_64.rpm

or this one:

http://download.virtualbox.org/virtualbox/4.1.6/VirtualBox-4.1-4.1.6_74713_openSUSE114-1.i586.rpm

Using the Extensions:

http://download.virtualbox.org/virtualbox/4.1.6/Oracle_VM_VirtualBox_Extension_Pack-4.1.6-74713.vbox-extpack

Directly from Oracle, then this scriptlet will work. I would suggest you might be better off doing so plus the latest version from Oracle is newer.

Thank You,

Good point!
Actually you didn’t even need to install VirtualBox (directly) to use vboxlive … meaning that if it’s not installed, vboxlive would have installed it for you, including all dependencies. (I will test it later today on a fresh 12.1). The name hasn’t change, it is still “VirtualBox”, but vboxlive looks for the Oracle version, and the one you installed is the OSE version, which is indeed named “virtualbox”.
You can try to replace

vboxinstalled=$(rpm -qa | grep VirtualBox)

with

vboxinstalled=$(rpm -qa | grep -i VirtualBox)

and the script shouldn’t complain anymore.
I will update the script ASAP.

If you installed vboxlive from my repo (it is included in the package vmscripts), you should have the latest /etc/vboxlive.cfg, that I updated yesterday. This file contain the latest versions and urls of the different distro guests supported by vboxlive. You can overwrite some or all the variables defined here in the file ~/.vboxliverc, that you’ll have to create. For example, faster mirrors closer to your location should be defined here. You can also set up several defaults, like the amount of RAM you want to assign to your virtual machines. /etc/vboxlive.cfg never get replaced with vmscripts update. The latest version of this file is saved as /etc/vboxlive.cfg.rpmnew instead, so users can decide if they want to use it (by renaming it) or not.

In the latest /etc/vboxlive.cfg, you will still see

VirtualBox_rel="11.4"

It means that the Oracle VirtualBox version will still be installed from Oracle 11.4 repo. It should work - that’s what I’m going to test later today. The reason is that Oracle doesn’t have a repo for openSUSE 12.1 yet. This variable should be changed as soon as this repo becomes available.

Or simply run

vboxlive --install

which is supposed to do all these steps (an even some more) or just start any supported guest with the option -D (cause it will likely have to download the iso image first).

Thus, the following command should install VirtualBox if it’s missing as well:

vboxlive -o ubuntu -D

… or display an error message if you have the OSE version … but I explained how to fix it in my previous post (and will fix it too).

Actually this command would be more appropriate to find out if VirtualBox is installed:

vboxmanage -v

What does it say for the OSE version?

Actually this command would be more appropriate to find out if VirtualBox is installed:

vboxmanage -v

What does it say for the OSE version?

I get the following response…

4.1.6r74713

Thank You,

Yes, me too. But we’re both using the PUEL version. Anyway, if @ruddamm-10 successfully used vboxlive (which uses plenty of vboxmanage commands) with the OSE version of VirtualBox (actually, I’m not sure that it is still called “OSE”), I can use vboxmanage -v to determine if any of the VirtualBoxes is installed. It will be simpler and faster than querying the rpm database … and will also please the few people in the world who might have built VirtualBox from sources or installed a non rpm package under openSUSE.

Actually you shouldn’t have got this message, even with the OSE version, because the function to install VirtualBox only starts if vboxmanage is not found (in your path).

which vboxmanage &>/dev/null || installVBox

Then, the function queries the rpm database, as you noticed, but you shouldn’t have reached that point.

So, if vboxmanage was in your path, this function should not have been called at all. vboxmanage is a symlink to VBox. My first guess woud be that this symlink doesn’t exist in the OSE version. But if it were the case, you couldn’t have run a virtual machine either.

:\