WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Virtual Box Guest Additions  (Read 9709 times)

Offline Kingdomcome

  • Sr. Member
  • ****
  • Posts: 286
Virtual Box Guest Additions
« on: August 21, 2009, 01:14:24 AM »
Seeing as how quite a few people are using TC/MC inside VBox, including myself, I have made a script to automate the acquisition of the Guest Additions from the running VM.  This script has been testing using VBox 3.0.4 and TC/MC 2.2 with full Xorg.  I recommend booting with bootcodes 'base norestore nolocal' to create the extension which you can then copy to your persistent tce/directory.  This build process requires the compile environment, Xorg with dependencies, Xorg-devs with dependencies, linux-kernel-headers, and usbutils and uses almost 300MB of memory/swap to complete.  The resulting extension will only be 1.5MB though.  I will include a working xorg.conf.vbox that will get renamed and moved into /etc/X11 by the script. The script will complain if you don't download or create the xorg.conf.vbox.  

I will keep the script posted here and an attachment updated as suggestions, request, or improvements are made
Updated 08/22/09 0000 EST to fix bugs and clean up code
Updated 08/24/09 2100 EST to fix another bug

  installVBGA.sh:
Code: [Select]
#!/bin/sh

. /etc/init.d/tc-functions
[ `id -u` = 0 ] || { echo "Must be run as root"; exit 1; }

TCE_DIR=`cat /opt/.tce_dir`
TC_USER=`cat /etc/sysconfig/tcuser`

xorgconfig(){
   if [ -r "$1" ];then
      XORG_CONF=$1
   elif [ -r "$(pwd)/xorg.conf.vbox" ]; then
      XORG_CONF=$(pwd)/xorg.conf.vbox
   else
      echo "${RED}No xorg.conf.vbox found. It is strongly recommended that you"
      echo "download xorg.conf.vbox from the same location as this script"
      echo "and then run this again.${NORMAL}"
      read -p "Are you sure you want to conintue this script? " driveon
      case ${driveon} in
         y|Y|yes|YES) echo "${RED}You have been warned${NORMAL}" ;;
         *) exit 1 ;;
      esac
   fi
   if [ -d /etc/X11 ]; then
      if [ -r "/etc/X11/xorg.conf" ]; then
         echo "Moving current xorg.conf to xorg.conf.bak"
         mv /etc/Xll/xorg.conf /etc/X11/xorg.conf.bak
      fi
   else
      mkdir -p /etc/X11
   fi
   [ -r "${XORG_CONF}" ] && mv ${XORG_CONF} /etc/X11/xorg.conf
}

findadditions(){
   echo ${YELLOW}
   echo "##########################################"
   echo "#                                        #"
   echo "#  Please mount the Guest Additions ISO  #"
   echo "#  by choosing Install Guest Additions   #"
   echo "#   from the Devices menu of your VM     #"
   echo "#                                        #"
   echo "##########################################"
   echo -n "${NORMAL}press Enter when ready"
   read garbage
   cd_dev=`blkid | grep -e iso9660 -e vbox | head -1 | awk -F: '{print $1}'`
   [ ${cd_dev} ] || { echo "Guest Additions not found"; exit 1; }
   cd_mnt="/mnt/$(echo ${cd_dev} | awk -F/ '{print $3}')/"
   mount ${cd_dev} ${cd_mnt} -o ro > /dev/null 2>&1
   VB_INSTALL=`ls ${cd_mnt} | grep -i linux | grep -i x86 | head -1`
   [ ${VB_INSTALL} ] || { echo "Guest Additions not found"; exit 1; }
   export VB_INSTALL
}

getdeps(){
   deps="compiletc.tce Xorg-7.4.tcel Xorg-7.4-dev.tce linux-headers-2.6.29.1-tinycore.tce usb-utils.tcel"
   for depname in $deps; do
      if [ ! -f /usr/local/tce.installed/$(getbasefile ${depname} 1) ]; then
         sudo -u ${TC_USER} tce-wget ${depname}
      fi
   done
}

checkformicro() {
   microcore=$(version | grep microcore)
   if [ ${microcore} ]; then
      [ $(echo ${microcore} | grep -i rc) ] && { echo "Not suitable for RCs"; exit 1; }
      mirror=`awk '/Mirror/ {print $2}' /opt/.tcrc`
      proto=`awk '/Protocol/ {print $2}' /opt/.tcrc`
      xlibs="${proto}://${mirror}/release/core_elements/Xlibs.core.tczl"
      cd ${TCE_DIR} && wget ${xlibs} && wget ${xlibs}.md5.txt
      md5sum -c Xlibs.core.tczl.md5.txt || { echo "Bad download, try again"; exit 1; }
      sudo -u ${TC_USER} tce-load Xlibs.core.tczl
   fi
}

runscript(){
   logfile="/var/log/VBoxGuestAdditions.log"
   touch /tmp/mark
   echo "Running VBox Install..."
   ${cd_mnt}${VB_INSTALL} 2>${logfile} >${logfile} &
   rotdash $!
   grep "Successfully" /var/log/VBoxGuestAdditions.log > /dev/null
   if [ $? != 0 ]; then
      echo "Installation failed. Check /var/log/VBoxGuestAdditions.log \
      for more info"
      exit 1
   fi
}

writemenu(){
cat <<EOF>> /usr/local/tce.menu/vboxguest
<JWM>
<Program label="Start Vbox Client">/usr/bin/VBoxClient-all</Program>
</JWM>
EOF
}

writepostinstall(){
cat <<EOF>> /usr/local/tce.installed/vboxguest
addgroup daemon
adduser -SDH -G daemon -s /bin/sh vboxadd
/etc/init.d/vboxadd start
EOF
chmod +x /usr/local/tce.installed/vboxguest
}

fixpackage(){
   sed -i s/group=1/group=daemon/ /etc/init.d/vboxadd
   [ -f /etc/X11/xorg.vbox.nobak ] && rm /etc/X11/xorg.vbox.nobak
}

findfiles(){
   cd /
   find etc/ -newer /tmp/mark -not -type d > /tmp/vboxguest.list
   find etc/X11/xorg.conf >> /tmp/vboxguest.list
   find lib/ -newer /tmp/mark -not -type d >> /tmp/vboxguest.list
   find sbin/ -newer /tmp/mark -not -type d >> /tmp/vboxguest.list
   find usr/ -newer /tmp/mark -not -type d >> /tmp/vboxguest.list
}

createpackage(){
echo "Creating Package"
tar czf /home/${TC_USER}/vboxguest.tcelm -T /tmp/vboxguest.list
cat <<EOF> /home/${TC_USER}/vboxguest.tcelm.dep
pixman.tcel
expat2.tcel
fontconfig.tcel
openssl-0.9.8h.tcel
Xorg-7.4.tcel
usb-utils.tcel
EOF
}

finishup(){
   echo "${WHITE}##############################################"
   echo "#                                            #"
   echo "# vboxguest.tcelm should be in your home dir #"
   echo "#                                            #"
   echo "${RED}#####################################################################"
   echo "#                                                                   #"
   echo "# The client application will need to be started either             #"
   echo "# manually from the menu or by placing the command \"VBoxClient-all\" #"
   echo "# in ~/.xsession above the last line: \"wait \$WM_PID\"                #"
   echo "#                                                                   #"
   echo "#####################################################################${NORMAL}"
}


xorgconfig $1
findadditions
getdeps
checkformicro
runscript
writemenu
writepostinstall
fixpackage
findfiles
createpackage
finishup
exit 0

  xorg.conf.vbox:
Code: [Select]
Section "ServerLayout"
Identifier     "X.org Configured"
Screen      0  "Screen0" 0 0
InputDevice    "Mouse0" "CorePointer"
InputDevice    "Keyboard0" "CoreKeyboard"
EndSection

Section "InputDevice"
Identifier  "Keyboard0"
Driver      "kbd"
Option      "XkbRules"       "xorg"
Option      "XkbModel"       "pc105"
Option      "XkbLayout"      "us"
EndSection

Section "InputDevice"
Identifier  "Mouse0"
Driver      "vboxmouse"
EndSection

Section "Monitor"
Identifier   "Monitor0"
EndSection

Section "Device"
Identifier  "Card0"
Driver      "vboxvideo"
EndSection

Section "Screen"
Identifier "Screen0"
Device     "Card0"
Monitor    "Monitor0"
EndSection
« Last Edit: August 25, 2009, 05:37:41 PM by Kingdomcome »

Offline xpto09

  • Newbie
  • *
  • Posts: 30
Re: Virtual Box Guest Additions
« Reply #1 on: August 21, 2009, 10:00:10 PM »
Code: [Select]
getdeps(){
   deps="binutils.tcel base-devs.tce bison.tce diffutils.tce file.tcel \
   findutils.tce flex.tce gawk.tce gcc.tcel gperf.tce grep.tce m4.tce \
   make.tce patch.tce pkg-config.tce sed.tce pixman.tcel expat2.tcel \
   fontconfig.tcel openssl-0.9.8h.tcel Xorg-7.4.tcel pixman-devs.tce \
   expat2-devs.tce fontconfig-devs.tce openssl-0.9.8h-devs.tce \
   Xorg-7.4-dev.tce linux-headers-2.6.29.1-tinycore.tce usb-utils.tcel"

   for depname in $deps; do
      if [ ! -f /usr/local/tce.installed/$(getbasefile ${depname} 1) ]; then
         sudo -u tc tce-wget ${depname}
      fi
   done
}


I apologize for my newbie question, but could you explain to me why you used "getbasefile"
and the number "1"?
I am learning shell script.
« Last Edit: August 21, 2009, 10:06:11 PM by xpto09 »

Offline ^thehatsrule^

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 1726
Re: Virtual Box Guest Additions
« Reply #2 on: August 21, 2009, 11:29:12 PM »
It's to get the "example" part out of "example.tce"
See /etc/init.d/tc-functions for the function

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
Re: Virtual Box Guest Additions
« Reply #3 on: August 22, 2009, 01:45:47 AM »
You could also set repository path to mirror at top of script:

Code: [Select]
MIRROR="$(awk '/Mirror/ {print $2}' /opt/.tcrc)"

Offline Kingdomcome

  • Sr. Member
  • ****
  • Posts: 286
Re: Virtual Box Guest Additions
« Reply #4 on: August 22, 2009, 10:02:41 AM »
Thanks for the suggestion.  Implemented in the checkformicro() function.  For the downloading of the normal extensions, tce-wget (through tce-load) is already using the mirror specified in /opt/.tcrc.  Keep in mind that if you are attempting to run this in MC with a custom repository, it will need to have a similar directory structure as the official repo for the releases and core elements.  Although as stated in first post, it is strongly recommended that this be run after rebooting and using bootcodes "base norestore nolocal" which would use the official repo. This is recommended to avoid adding the compile environment and Xorg-devs to your persistent tce/ directory.

Offline JoXo009

  • Full Member
  • ***
  • Posts: 152
Re: Virtual Box Guest Additions
« Reply #5 on: August 24, 2009, 04:50:09 AM »
Good piece of work this script making the guest additions of virtualBox available on TC.

Usually the official edition from Sun will be used as virtualBox:
http://dlc.sun.com/virtualbox/vboxdownload.html

This PUEL licensed edition is free for any personal (even commercial) use:
http://www.virtualbox.org/wiki/VirtualBox_PUEL

But it is't not free distributable, with the consequence that this version can't be used to build a stand alone extension.

For free distribution you have to use the GNU licensed open source version which has got nearly aquivalent content. The main difference is that the free version hasn't got USB passing through capability. For details see:
http://www.virtualbox.org/wiki/Editions

Anyway the free version has got guest additions too. The only limitation is that the free versions mustn't be called 'Virtual Box', as this name ist trademarked for Sun:
http://forums.virtualbox.org/viewtopic.php?f=10&t=11951

Even if both versions are nearly equivalent, details and download sources for the free version are pretty diffcult to find. Following a collection of the links I stumbled over:

Snapshot and code repository offerded by Sun (see bottom of the page):
http://www.virtualbox.org/wiki/Downloads

The virtualBox guest additions installer project on Google Code:
http://code.google.com/p/virtual-box-windows-guest-additions-installer/
http://code.google.com/p/virtual-box-windows-guest-additions-installer/wiki/MainPage

There is a German Debian site with some more links
http://packages.debian.org/lenny/virtualbox-ose-guest-source

Inclusive a download link for the OSE version guest additions:
http://packages.debian.org/lenny/all/virtualbox-ose-guest-source/download

Finally there is a Virtual Box OSE Debian install howto here:
http://chirale.wordpress.com/2007/12/23/virtualbox-ose-debian-install-howto/


Offline Kingdomcome

  • Sr. Member
  • ****
  • Posts: 286
Re: Virtual Box Guest Additions
« Reply #6 on: August 24, 2009, 09:10:14 PM »
It may take a little time, but I am working on getting VBox-OSE compiled on TC and then grabbing the Guest Additions out of that which should be free distributable.

Offline moB

  • Newbie
  • *
  • Posts: 49
Re: Virtual Box Guest Additions
« Reply #7 on: May 04, 2010, 10:45:45 PM »
Good piece of work this script making the guest additions of virtualBox available on TC.

Usually the official edition from Sun will be used as virtualBox:
http://dlc.sun.com/virtualbox/vboxdownload.html

This PUEL licensed edition is free for any personal (even commercial) use:
http://www.virtualbox.org/wiki/VirtualBox_PUEL

But it is't not free distributable, with the consequence that this version can't be used to build a stand alone extension.


See portable-virtualbox for a solution... here the portable wrapper for VBox downloads and installs *to itself* the VirtualBox runnable from Sun. There is a mandatory "not an official version ... not sun supported..." splash screen.

To sum up:
    one downloads and runs portable installer,
    it downloads sun vbox installer & extracts files from it & deletes it.


 
Quote
For free distribution you have to use the GNU licensed open source version which has got nearly aquivalent content. The main difference is that the free version hasn't got USB passing through capability. For details see:
http://www.virtualbox.org/wiki/Editions

If you are running VBox from linux you don't need "USB passing through" as one can access these from the host filesystem.

Assuming your guest additions are in place mount a folder on your host OS.
  [# mount.vboxsf name mountpoint ] Where name is a name of a VBox shared folder on your host OS and mountpoint is a folder on your guest OS.

From the host OS open a terminal in the name folder and make a symbolic link to root.
  [# ln -s / hostroot ] Where / is the root and hostroot is a name you like for the link.

Now you can open emelfm, for example, and navigate (on Debian, for example) to USB.
 [ mountpoint/hostroot/media/disk ]

If you are running msWin this is not as easy, but links can be made if you go get the tools.or are running a suitable version. Info available on google, or I can look about for more if anyone needs.

OK. nuff for today on this old topic.

Thanks for the guest additions for TC Kingdomcome!