Thursday 3 April 2014

Creating a VirtualBox test system for Raspberry Pi development


Firstly, I'm going to walk through the process of setting up a Ubuntu Virtual Machine (VM) on VirtualBox, which I will use as a test environment for developing for the Pi.

Download the Ubuntu ISO from here if need be.
With VirtualBox installed on your PC. Go to New, and walk through the wizard, allocating memory, and creating a virtual hard disk.

Once that's done, boot the machine, and you'll get a "first-run" type prompt, asking you to select an installation source - direct it to the ISO you downloaded earlier.

Once the VM boots, select Install to hard disk, and walk through the graphical wizard for that. Once complete, reboot the virtual machine.

Once rebooted, login, and open a terminal.
Follow the same instructions to update the system and install the LAMP stack as we did in the post about setting up the Pi.

Once that's done, the next step is to install the VirtualBox 'Guest Additions'. These allow easier interaction between your host system and the VM.
Select this from Devices -> Install guest additions at the top of the VM window. After a few seconds you'll be prompted to run the software in the VM (you'll also be asked to authorise the installation)

Let that run through, and then reboot the VM. Now would be a good time to take a snapshot (Machine->Take snapshot). This effectively creates a backup of the system state at the time it was taken, so if you test something and screw it up, it's fairly trivial to get the system back to how it was.

Now, create a shared folder between the host and the VM - this'll make it easier to move files between them. Right-click on the folder icon at the bottom right of the VM window, and select shared folders. Click the 'Add' button at the right hand side of the dialog that appears - fill in the path, name, and options for the share (Uncheck read-only, check auto mount and make permenant)

You'll now find you have a folder on the virtual machine under /media/sf_FOLDERNAME, where FOLDERNAME is the name you gave your shared folder (eg, mine was named Temp, so on the VM it's /media/sf_Temp). You'll also find you can't access it.
To fix this, in the terminal enter

sudo gpasswd -a USERNAME vboxsf


replacing USERNAME with your own username. You will need to reboot for the changes to take effect.

The final step is to allow the host to access the VM's server.
Go to Machine->Settings->Network, and click Port Forwarding on the network adapter you're using (1 by default)
Click Add, then enter the name (HTTP), host port (I chose 8080), and guest port (80). Click OK.
Now when browsing to localhost:8080 on your host machine, you should see the "It works" page of the web server on the VM.

Take another snapshot here.

This was meant to be a short intro to the main development, but seeing as it's already a lengthy post, I'm going to leave it here, and pick up the rest of the development later.

No comments:

Post a Comment