mandag 28. mars 2011

Start using Virtualbox on FreeBSD

Start using Oracles Virtualbox on your FreeBSD server.

Goals:
  • Compile and enable virtualbox. 
  • Headless windows client mainly for remote desktop access
  • Try out a web interface called phpvirtualbox
System information:
  • FreeBSD Release 8 is running on a P4 3Ghz HT with approx 3Gig ram. (Nothing impressive, really)
  • Server has several network cards and is VLAN enabled. Server is not running any firewall.
  • Apache 2.2 and php5.
Some pitfalls I had to jump over:
  • The version of virtualbox in ports collection today (March, 2011) is the virtualbox-ose 3.2.12_1. This version do NOT have the VRDP protocol implemented. This version is equiped with the former vnc head solution, which has to be enabled before compiling.
  • Virtualbox puts your hosts in the respective users home directories. I want them somewhere else.
  • My hosts are not started automatically. Let's make cron do the job.
Make virtualbox:
  1. Update your ports collection
  2. Go to /usr/ports/emulators/virtualbox-ose and do a make config. Enable DBUS, VNC and WEBSERVICE before doing the make install clean.
  3. You dont need to be root to run a guest. Just add your user to the vboxusers group.
  4. To force virtualbox to store it's files in an alternative location, add VBOX_USER_HOME=/usr/local/virtualbox/ or your directory of choice to one of your startup script. make sure this directoy belongs to the user or the vboxusers group and has adequate permissions set.
Implementing a gui for Virtualbox, phpvirtualbox
  1. Return to ports collection, /usr/ports/www/phpvirtualbox/, and do the make install clean. I assume you have Apache2.2 and php5.
  2. Implement the following in your alias directive of httpd.conf and reload apache: 
  3. Alias /phpvirtualbox /usr/local/www/phpvirtualbox/
         AcceptPathInfo On
         <Directory /usr/local/www/phpvirtualbox>
                 AllowOverride None
                 Order Allow,Deny
                 Allow from all
         </Directory>
  4. Modify /usr/local/www/phpvirtualbox/config.php and add your username and no password.
  5. Execute, as your user, the following command; this will inhibit password protection. My system is on my local network so the security threat is minimal.
  6. VBoxManage setproperty websrvauthlibrary null
  7. You should now be able to run vboxwebsrv in your cli and point your browser towards http://server/phpvirtualbox. Break the vboxwebsrv when you're done.
Managing your guests
  • Use the web gui to manage the details of your guests.
  • To start your guest through cron, add the folowing to crontab with crontab -e;
  • VBOX_USER_HOME=/usr/local/virtualbox/hamster
  • @reboot /usr/local/bin/VBoxManage startvm "guest01" --type headless
  • To list your vm's, run VBoxManage list vms or VBoxManage list runningvms.
  • To start a guest with vnc-head, run VBoxHeadless --vnc --vncpass secret guest01
  • To kill your guest, run VBoxManage controlvm guest01 poweroff
     


Last edit: 2011-03-28
Thord Matre