:wc: relfile 00-WikiIndex

---3 Making ''VirtualBox'' Guest Addition for Fatdog

%abs=
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.
%=


---4 Background

Skip directly to the [[#steps] steps].

[[https://www.virtualbox.org/]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 
[[+blank https://www.virtualbox.org/wiki/VirtualBox_PUEL] 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. 
   - As a host, installing is easy - get the 64-bit "All distribution" 
     tarball, and just run it - (with devx and it will install to reasonable location and
     it will update the init script as necessary.

   - As a guest, Fatdog is immediately usable,
     booting directly to desktop with mouse integration. 
   . 

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:
   - Get the kernel source and devx SFS into the guest.
   - Load both devx and kernel SFS.
   - From ''VirtualBox'' Manager, load the Guest Addition CD image.
   - Then from inside the guest, mount the disc, and launch
     ==''VBoxLinuxAdditions.run''== inside the mounted disc.
   - Wait and cross your finger that everything goes smoothly, and
     if necessary adjust some of the paths after the installation is 
     complete.
   .

It works, but there are two minor problems:
   # 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).
     
   # 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:

   # You are doing this on the host, so you have full access to host's
     tools.
   # Yet, the host is **not** affected by this process.
   # The guest does not need to be running.
   # 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.


---4 Overview

How is it done?
   # Load devx and kernel source on the host.
   # Extract contents of ==''VBoxLinuxAdditions.run''== on the host.
   # Run the installer from the extracted contents of 
     ==''VBoxLinuxAdditions.run''== in sandbox.
   # Collect the files from the sandbox copy-on-write layer and
     update/modify the paths as necessary.
   # Package it with ==makepkg== or ==mksquashfs==
   . 

%notice=
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. 
%=

(:steps:)
---4 The actual steps

   # 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.
   
   # Mount the Guest Addition iso image
---==example
rox /opt/VirtualBox/additions/VBoxGuestAdditions.iso
---=

   # 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)
---==example
mkdir -p /tmp/xxx
cd /tmp/xxx
---=

   # Extract the contents ==''VBoxLinuxAdditions.run''== from the mounted ISO image,
     storing it in our temporary directory.
---==example
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==).
     
   # We are done with the Guest Addition iso image, so un-mount it (same 
     command as when you mounted it).
---==example
rox /opt/VirtualBox/additions/VBoxGuestAdditions.iso
---=

   # Launch sandbox-lxc, and enable "desktop emulation".
---==example
sandbox-lxc.sh
---=
%notice=
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.
%=

   # 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.
---==example
cd /tmp/xxx/install
sh install.sh
---=

   # 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.

---==example
# 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
---=

%wikiseq=
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.
%=

   # 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:
---==example
# from within /tmp/vboxadd
makepkg -c n -l n /root/vbox-additions-4.3.26-x86_64-1.txz
---=     
     
     To make an SFS:
---==example
cd /tmp
mksquashfs vboxadd /root/vbox-additions-4.3.26.sfs
---=     
  
%wikiseq=
     Change 4.3.26 to ''VirtualBox'' version you are using. ::
     Remove ==/tmp/vboxadd== when you are done.
%=     

   # 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).
     
   # Once the sandbox-lxc is shutdown, you can remove ==/tmp/xxx==.
   .

That's all there is to it.
