Making VirtualBox Guest Addition for Fatdog

This article explains how to create a guest installation package for use by Fatdog64, when run as a guest inside VirtualBox virtualisation software.

It is specific to Fatdog64 and requires you to know the terms like SFS, devx, kernel-source, load the sfs, sandbox, etc which is explained elsewhere.

This articule is written for Fatdog64 700 but with minor tweaks should be applicable to other versions of Fatdog that supports similar commands and features.

Background

Skip directly to the steps.

VirtualBox is a very well designed, versatile, likeable, desktop-class virtualisation solution. It is multi-platform (Windows, Mac, Linux of various brands, and Solaris). What's not to like? It is open-source; the entire source code are available under GPLv2 license. It also comes with proprietary drivers for things like USB and RDP access; but these drivers are free (as in beer) for personal use only; and their definition of personal use is rather unique and broader than what you think it is.

It has a very long history, initially offered by its developers through and independent company called Innotek, it was acquired by Sun Microsystem and thus now belongs to Oracle after Sun was absorbed by Oracle. Unlike many of other products, however, VirtualBox continues to flourish and stays independently open, and apart from relative slowness of its development (which I don't mind because for me, it is already feature-complete), the offering - both the product and licensing - remains effectively identical since the day I tried its version 1.x.

The latest Fatdog64 (700 as of this time of writing) plays very well with VirtualBox (4.3.26 as of this time of writing), both as a host and as a guest.

When run as a guest operating system, some features, however, needs the VirtualBox guest additions software to be installed. There are many ways of doing it; the one on this article helps you to make re-distributable package that you can use on many guest installations.


The standard true-and-tested method to install the Guest additions is as follows:

It works, but there are two minor problems:

  1. Loading the devx and kernel source SFS to the guest OS is not easy (especially since folder sharing etc does not work yet - folder sharing requires guest addition software to be up and running).

  2. The resulting installation is only applicable to *that* guest. You will need to repeat the same procedure if you want to enable guest addition on other virtual machine.

Can we do better? Yes. The benefits first:

  1. You are doing this on the host, so you have full access to host's tools.
  2. Yet, the host is not affected by this process.
  3. The guest does not need to be running.
  4. The end result is a package (either installable TXZ package or SFS) that can be used over and over for many guest installs.

Interested? Read on.

Overview

How is it done?

  1. Load devx and kernel source on the host.
  2. Extract contents of VBoxLinuxAdditions.run on the host.
  3. Run the installer from the extracted contents of VBoxLinuxAdditions.run in sandbox.
  4. Collect the files from the sandbox copy-on-write layer and update/modify the paths as necessary.
  5. Package it with makepkg or mksquashfs

Note: This is of course assuming your host OS is also Fatdog64, and the version of Fatdog64 you want to use as the guest is the identical (or very similar to) the host Fatdog (the kernel version must be identical). It won't work otherwise.

The actual steps

  1. Make sure you have devx and kernel source loaded on the host. Oh, and you also need VirtualBox itself installed. You don't actually need it, but the installation provides you with a copy of the Guest Addition CD image that you need.

  2. Mount the Guest Addition iso image
    rox /opt/VirtualBox/additions/VBoxGuestAdditions.iso
    

  3. Make a temporary directory in /tmp, then cd to it (It has to be somewhere in /tmp, since we want to access it from sandbox later)
    mkdir -p /tmp/xxx
    cd /tmp/xxx
    

  4. Extract the contents VBoxLinuxAdditions.run from the mounted ISO image, storing it in our temporary directory.
    sh /mnt/+opt+VirtualBox+additions+VBoxGuestAdditions+iso/VBoxLinuxAdditions.run --noexec --keep
    
    By the end of this process, you should see an install directory inside your working directory (of /tmp/xxx).

  5. We are done with the Guest Addition iso image, so un-mount it (same command as when you mounted it).
    rox /opt/VirtualBox/additions/VBoxGuestAdditions.iso
    

  6. Launch sandbox-lxc, and enable "desktop emulation".
    sandbox-lxc.sh
    
    Note: You must use sandbox-lxc, not the standard sandbox. The installation process does something funny to the host OS, which cannot be prevented by the normal sandbox, thus sandbox-lxc is required.

    Also, you need to enable "desktop emulation". Not that we are going to use it, but doing that will share /tmp from the parent so we can access the Guest Addition files we have just extracted above.

  7. Now, inside the sandbox, run the installed and be patient and wait until it finishes. It will attempt to start some services and they will fail - worry not, what we need are the installation files, not trying to run the actual guest services in our host OS.
    cd /tmp/xxx/install
    sh install.sh
    

  8. Open another terminal. Do not EXIT or terminate the sandbox, keep it up and running until instructed to do otherwise.

    Now, in this newly opened terminal, type these commands. You don't have to type the comments, of couse - they are there so that you know what the commands are doing.

    # collect the newly created files from sandbox cow layer to /tmp/vboxadd
    sb2dir.sh vboxadd
    
    # remove unneeded cruft
    cd /tmp/vboxadd
    rm -rf dev var
    rm -r etc/xdg/autostart
    rm etc/rc.d/rc.local
    rm etc/*
    find lib ! -name '*.ko' -delete
    rm -f sbin/poweroff sbin/reboot
    
    # correct paths, create proper Fatdog startup script
    mv etc/rc.d etc/init.d
    mkdir etc/xdg/Startup
    cat << "EOF" > etc/xdg/Startup/vboxclient
    #!/bin/sh
    VBoxClient-all
    EOF
    chmod +x etc/xdg/Startup/vboxclient
    

    If you make a mistake, delete /tmp/vboxadd and re-do this step again. You can do this as often as needed - as long the sandbox-lxc process remains open.

  9. Once you have completed the previous step, you know have a nicely set of files in /tmp/vboxadd which is good for making a installation package, or an SFS.

    To make an installable package:

    # from within /tmp/vboxadd
    makepkg -c n -l n /root/vbox-additions-4.3.26-x86_64-1.txz
    

    To make an SFS:

    cd /tmp
    mksquashfs vboxadd /root/vbox-additions-4.3.26.sfs
    

    Change 4.3.26 to VirtualBox version you are using.
    Remove /tmp/vboxadd when you are done.

  10. We are done. Now shutdown the sandbox-lxc by typing in its terminal poweroff. It will ask for your confirmation whether you really want to power off, and just click yes. Only the sandbox will be powered off, not the entire system. (If you use the regular sandbox, it will power down the entire system - so don't do this in a regular sandbox).

  11. Once the sandbox-lxc is shutdown, you can remove /tmp/xxx.

That's all there is to it.