Building a VirtualBox image (Compilers)

From Spivey's Corner
Jump to: navigation, search

These instructions show how to install a minimal version of Xubuntu Linux under VirtualBox on a Mac. Instructions for a Windows host would be very similar.

Downloading and installing

Creating a virtual machine

Configuring the virtual machine
  • Run VirtualBox via Launchpad or the Start button. Choose New.
    1. Type a name for the machine (Compilers will do), and choose Linux / Ubuntu 32 bit; click Continue (see screenshot).
    2. Accept 1024MB memory.
    3. Accept Create a virtual hard disk now.
    4. Accept VDI.
    5. Accept Dynamically allocated.
    6. Accept default location and 10GB.

Installing Linux

Inserting the installation CD
  • Select the new machine and click Start. You will be prompted to choose a CD image to boot from; click the icon at the right and find the image mini.iso you downloaded earlier. Click Start.
Choosing software packages
  • You are now in a text-mode installer: stop clicking and start typing! Press Return to accept Install.
    1. Use the arrow keys to choose English on one screen, United Kingdom on the next.
    2. Say No to Detect keyboard layout, and choose explicitly; I used English (UK) and English (UK, Macintosh), though this gives £ rather than # for Shift-3. Under Windows, you're likely to want English (UK) and English (UK) again.
    3. Choose a name for your machine if you like, though ubuntu will do.
    4. Accept the defaults for the mirror of the Ubuntu archive. No proxy should be needed.
    5. Type your full name, edit your username if you like, choose a password.
    6. No to Encrypt your home directory. Accept Europe/London timezone.
    7. Partition using 'Guided – use entire disk'. Accept defaults. You have to select Yes explicitly to write the new partition table, but it's quite safe: you are operating on a virtual disk held in a file, not directly on the hard disk of your Mac.
    8. Wait while the basic parts of Linux are downloaded and installed. There are several progress bars that slowly climb to 100%, only for another task to start back at 0%; I hate that.
    9. Choose No automatic updates and wait some more.
    10. At the Software selection screen, leave 'standard system utilities' selected and add 'Xubuntu minimal installation' (see screenshot). You could use 'Lubuntu minimal installation' instead, or neither for a text-mode installation. Choose Continue and wait some more.
    11. Say Yes to 'Install the GRUB boot loader to the master boot record'. (It's the MBR of the virtual disk we're talking about, rather than the MBR of your Mac hard disk – not that it has one.)
    12. Say Yes to 'System clock set to UTC'.
    13. When prompted, use the Devices menu and Optical Drives / Remove disk from virtual drive. You will need to use Force Eject. Then allow Linux to reboot.

Settling in

  • When Linux comes up, type the password you chose earlier.
  • Click on Mouse Whiskers and Terminal Emulator to get a shell prompt.
  • Install VirtualBox guest additions. This isn't essential but supports cut and paste between host and guest, and makes the guest desktop resize automatically to fit the host window. Use the command sudo apt-get install virtualbox-guest-dkms
    Testing the installation
  • Then set up the software we need.
    1. Type sudo apt-get install mercurial ocaml-nox
    2. Type sudo apt-get install qemu-user gcc-arm-linux-gnueabihf (Note that tab completion works).
  • Now download and build the lab software.
    1. hg clone http://spivey.oriel.ox.ac.uk/hg/compilers
    2. (cd compilers/lib; make)
    3. (cd compilers/keiko; make)
    4. cd compilers/lab4
    5. make
    6. make test1-pprolog (see screenshot).
  • Install other software you need to work on the labs. For example, a text editor: sudo apt-get install gedit.
  • You can now unmount the VirtualBox disk image and throw it and mini.iso in the Trash.

Refinements

  • (On the Mac) add a hacked keyboard layout that makes Shift-3 map to #. [Actually, it's already possible to type a # by using RightAlt-3 in Terminal, in Gedit and in Emacs.]
  • Change terminal to be black-on-white if that's what you like, or green-on-black if you're 1337. I'm more 4711 myself.
  • Reduce the size of the emacs font by doing Options / Set default font followed by Options / Save options. Same for Gedit. (On Xubuntu, it's easier to change these individually than to poke about trying to change the system default.)

Access to the lab machines

You can access the lab machines using SSH from the Linux guest and avoid the messiness of PuTTY on Windows.

  • To do this from outside the Oxford domain, it works to connect to VPN in the host (Windows or MacOS), then SSH from the guest. Installing VPN on the guest doesn't work so well, because DNS is no longer available on the guest. This can be fixed, but it's simpler to avoid the problem.
  • You can use ssh-keygen in the guest to create a login key, followed by ssh-copy-id ecs.ox.ac.uk to install it; then you can access the lab machines without typing a password each time. There's no need to use a passphrase for the key if you don't want to.
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/mike/.ssh/id_rsa): <enter>
Enter passphrase (empty for no passphrase): <enter>
Enter same passphrase again: <enter>
Your identification has been saved in /home/mike/.ssh/id_rsa.
Your public key has been saved in /home/mike/.ssh/id_rsa.pub.
$ ssh-copy-id mike@ecs.ox.ac.uk
The authenticity of host 'ecs.ox.ac.uk (129.67.150.241)' can't be established.
ECDSA key fingerprint is SHA256:RfV6BisTTiQLLxpyxDkuteX0llmVpECefUtUlFOoUpA.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install the new keys
mike@ecs.ox.ac.uk's password: <password> 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh 'mike@ecs.ox.ac.uk'"
and check to make sure that only the key(s) you wanted were added
  • Use scp ecs.ox.ac.uk:/users/mike/pi/guest-rsa . to fetch the SSH key needed for access to Mike's Pi server.

Copying files in and out

Create a folder in the host to share, or share your desktop.

  • In VirtualBox, use Settings/Shared Folders. Check automount. Save and boot the guest.
  • In the guest, add yourself to the vboxsf group with addgroup <name> vboxsf. Log out and in again.
  • You will find the shared folder under /media/sf_<folder>.

Some alternatives to shared folders:

  • For small amounts of text, after installing the guest additions, use cut and paste between host and guest.
  • Use a USB key, which can be mounted on the guest by using the USB button at the bottom of the guest window. You may need to install the VB extension pack and enable USB 2.0 or 3.0 to do this.
  • Use scp to and from a server (such as the lab machines).
Personal tools

Variants
Actions
Navigation
Tools