How to Build a Ubuntu Linux host under VirtualBox

From Texas Instruments Wiki
Jump to: navigation, search

TIBanner.png

Return to the Sitara Linux Software Developer's Guide

Note - If behind a company firewall, be sure to set the necessary proxy settings within Ubuntu 10.04 LTS



Introduction

This guide shows how to get a virtual Ubuntu Linux machine running with VirtualBox.  This process has been successful with Ubuntu 8.04, 9.10 and 10.04 and versions of VirtualBox 3.1.2 and later (currently 3.1.8). Please only use the Ubuntu 10.04 release as this is what is called an LTS (Long Term Support) as there are SDK scripts that will be checking for this release identity.

Requirements:

  • Windows XP host with internet connection, at least 1G of RAM and 40G of free hard drive space.


Download Ubuntu ISO image

Get the Ubuntu CD ISO image from: http://www.ubuntu.com

Ubuntu com.png

Click download and the follow instructions to download and save the ISO image (CD image).



Download VirtualBox (Vbox) and install

Get VirtualBox 3.1.8 (Vbox) from: http://www.virtualbox.org/wiki/Download_Old_Builds_3_1 Virtualbox org.png

  • Click on Downloads link
  • Click VirtualBox for Windows hosts (currently v. 3.1.8)
  • Save to Windows machine

NOTE - We have tested with both v3.1.6 and v3.1.8 with no known issues. v3.2.2 however does appear to have an issue when setting up a Shared Folder. For this reason, please be sure to download v3.1.6 or v3.1.8


The Vbox installation will temporarily disrupt the network connection of the Windows host machine. It is a good idea to disconnect from any network drives or remote connections before running the Vbox installation.

  • Run the executable to install Vbox
  • Accept license and all default settings.


Create a New Virtual Machine with VirtualBox

The following steps are performed with Vbox 3.1.6.  The exact steps with other versions may vary slightly

  • Run Vbox.
  • From the initial Vbox GUI click New.


  • This will launch a wizard that will step through the creation of the virtual machine.  Click Next.
  • Type a unique name for the new machine. A good name will include 'Ubuntu' and the Ubuntu version and maybe some other distinguishing info about the machine itself. This will help distinguish the virtual machine from others that may also be under Vbox.

Vbox name.png



  • You may want to increase the default RAM size. We have selected 512MB.  Click Next.

Vbox basemem.png


  • Keep the default virtual hard disk settings (Create new Boot hard disk). Click Next.

Vbox hdd.png


  • Select Dynamically expanding storage for the hard disk storage type. Click Next.


NOTE: It is highly recommended to select a hard disk of at least 20GB or higher.  Keep in mind that this is the maximum size that your virtual hard drive can reach if you've selected the "dynamically expanding storage" option, i.e. it will not immediately take up that many GB of your hard drive. You will need this space for the SDK installation and your development.


  • Click Finish.



Configuring your Virtual Machine under Virtual Box

With your virtual machine now created in VirtualBox you need to configure your new machine by highlighting your machine name and clicking on Settings.


  • Modify the OS Type.  Set OS to Linux and Version to Ubuntu. Click Next.

Vbox general.png


  • If you have not already done so, you may want to increase the default RAM size of your Vbox. We have selected 512MB. Also set CD/DVD-ROM to to highest Boot Order. Click Next.
  • Note: Recommended RAM size is 1024MB -- else you may see swap and memory usage complete full causing builds to fail.

Vbox system.png


  • It may be useful to change the default Video Memory to something more than 12MB. We have selected 64MB.

Vbox display.png


  • Next Add an Attachment to Add a CD/DVD Device and point it to the ubuntu-10.04-desktop-i386.iso. When you Start your virtual machine for the first time, it should boot from the CD/DVD and install Ubuntu 10.04 from this iso file.

Vbox storage.png


  • Setting a Network Adapter will depend largely on your Windows machine and available network adapters. Enable Network Adapter and select Bridged Adapter for Attached To. If needed expand Advanced to see more adapters. We would not recommend using a Wireless adapter.

Vbox network.png


  • You will need to enable a Serial Port to use minicom within your Linux machine. Enable the Serial Port, set the Port Number to COM1 (typical), Port Mode to Host Device and Port/File/Path to "com1".

Vbox serial.png


  • To allow Vbox and Ubuntu to "read" your USB SD Card Reader you need to create a USB Device Filter and select the USB SD reader that is connected to your Windows machine. Enable to USB Controller and the USB2.0 (EHCI) Controller.


NOTE - You must ensure the USB SD Card Reader is connected to your Windows machine BEFORE you run VirtualBox or start your Ubuntu machine. For more information see How to Read a USB SD Card Reader in VirtualBox.


Vbox usb.png


Vbox sharedfolders.png




When you are finished your Vbox should look similar to the screen below which shows all of the settings you configured for your Ubuntu Linux machine in the Details tab.

Vbox snapshot.png


Install Ubuntu on the Virtual Machine

Once configured as seen above, your new virtual machine will display as "Powered Off".  Click on the machine to highlight it and then click the Start button.

On Start your virtual machine should boot from CD/DVD and install Ubuntu 10.04 from the ISO file.  The steps to install Ubuntu onto the virtual machine will vary depending on the version of Ubuntu. Follow the most reasonable steps to complete the installation. The steps will include the creation of a name for the machine. It can be (but doesn't have to be) the same as the name of the Vbox machine. It helps if the name designates the machine as Ubuntu with a version and a unique identifier. This name will be the hostname on a network.


The steps will also include the creation of a user account. This account will be able to process root access commands with the sudo command .  A common username and password is shown below.  These names are optional and your choice.


Username:  user

Password:  useruser


When installation completes, the machine will require a reboot.  Since the ISO file has already installed Ubuntu it will ask you to Press Enter to remove the ISO file from the CD/DVD.  Press Enter and the reboot will complete booting now from the virtual hard drive which runs Ubuntu.



Install Guest Additions

With the virtual machine booted, click the Devices menu in Vbox and select "Install Guest Additions...". If you are not logged in as root, you will need to run the autorun.sh script in the Guest Additions software directory; rather than the .run file. Using the autorun.sh script will prompt Linux to ask you for your administrator password. To get to this directory and run the script do the following:

First verify where the

$ mount 

Typically this should return that the guest additions are mounted on /media/VBOXADDITIONS, now run the autorun script to install the packages.

$ cd /media/VBOXADDITIONS
$ sudo ./autorun.sh

If the VBOX Additions is not located here, then just change directory (cd) to the mount point that has it.


Accept all the defaults. Guest Additions will allow the Vbox window to be resized. It also allows the mouse to move freely between the host and virtual machine and allows for cut/copy/paste between Windows host and virtual machine. Guest additions are also required for file sharing between the Windows and the Linux system. 



Sharing Files Between Ubuntu and Windows

VirtualBox has a Shared Folders feature which you need to setup before starting the Ubuntu image. In Virtual Box select your Ubuntu image and click Settings. At the bottom you will see Shared Folders. Specify (or create) the Windows folder you want to share with Ubuntu. Give the shared folder a name. It is a good idea to use the same folder name for both Windows and Ubuntu. 

Using Shared Folders with VirtualBox requires that the VirtualBox Guest Additions has been installed.  Also, Ubuntu updates often wreck the VirtualBox Guest Additions settings.  If folder sharing stops working after a Ubuntu update, reinstall Guest Additions.



Vbox shared.png


Nomenclature:

  • <user> - the Username of your Ubuntu machine
  • vbox_shared - the Shared Folder name for both Windows and Ubuntu



Now Start your Ubuntu machine and from Applications-Accesories-Terminal in Ubuntu create a folder on your Desktop of the same name:  vbox_shared.

mkdir /home/<user>/Desktop/vbox_shared

This line "connects" or mounts your VirtualBox Shared Folder "vbox_shared" to the folder you just created on your Ubuntu Desktop called /home/user/Desktop/vbox_shared.

sudo mount -t vboxsf vbox_shared /home/<user>/Desktop/vbox_shared


Now you can simply copy files back and forth between the vbox_shared folder from either Ubuntu or Windows. You will see the same file(s) appear in the vbox_shared folder in the other OS.


If you reboot or shutdown your Ubuntu machine you will need to sudo mount -t... your Shared Folder again as seen in the second step above.  You can do this automatically by Creating a Init Script in Ubuntu and adding the sudo mount -t... line to it.  On rebooting your Ubuntu machine, you will find the vbox_shared folder is mounted automatically each time.  



How to Read a USB SD Card Reader in VirtualBox

Prior to beginning this process, if you haven't already, shutdown the VirtualBox session, AND restart your computer.

  1. In Settings for your virtual machine, be sure to Add a USB Device Filter and select the USB SD Reader that Windows "sees".  
    1. Click the Settings button under Vbox for the virtual machine. Click USB in the left hand pane of the Settings window. A button on the right side of the window has a green plus symbol. If the mouse is hovered over this button a flag will read "Add Filter From Device". Click this button and select the card reader from the list of choices.
  2. Before you run VirtualBox and Start your Linux virtual machine, be sure that Windows first "sees" USB SD Card Reader.  Otherwise, Ubuntu will never "see" it.
  3. When you Start your virtual machine, Ubuntu will mount any active partitions found on the SD card. Depending on the SD card you may see folders or partitions open on the Ubuntu Desktop.  Also you can run "df -hT" in a Terminal to print details about the partitions.



Switching mouse/keyboard between host and virtual machine.

When you left click inside your Linux virtual machine, by default your keyboard and mouse will remain focused within the Linux machine until you press the Right CTRL button. This will allow you to go back to your Windows desktop.

To use your mouse and keyboard across both Windows and Linux without using Right CTRL to switch, install the VirtualBox Guest Additions as described below.



Configuring a Proxy in Ubuntu

If your network is behind a firewall you will need to configure the network proxy for Ubuntu in order to successfully download the applications required to complete your development environment or to browse the Internet on your Linux Host machine.

To configure the network proxy in Ubuntu go to System-Preferences and click Network Proxy as seen below.

Network proxy setup.JPG


As seen in the image below, click Manual Proxy Configuration. Specify the HTTP proxy server used by your company. You may find this information under your Windows OS inside the Internet Explorer Network Connections. On your host machine, open Internet Explorer. Go to, 'Tools', 'Internet Options', in the 'Connections' tab, click 'LAN settings'. Copy the proxy address shown. Be sure to specify the port.

Make sure you check "Use the same proxy for all protocols". Also be sure to click "Apply System-Wide". Then Close

Network proxy preferences.JPG


Finally you will be asked to entered your password in order to set your network proxy information. This is typically the same password you used to log into Ubuntu on boot.

Network proxy password.JPG


You should now be able to browse the Internet using Firefox within Ubuntu. Note: If you are still unable to browse the internet, open Firefox. Go to, 'Edit', 'Preferences', under the 'Advanced' tab, click 'Network', then click 'Settings'. Make sure the proxy address is copied into the field, 'Automatic proxy configuration URL'.



Additional changes in case apt-get does not work

In some case, sudo apt-get <package-name> may not work. In such a case, sources.list should be updated to add http://archive.ubuntu.com/ubuntu.

$ vim /etc/apt/sources.list
"deb-src http://archive.ubuntu.com/ubuntu lucid restricted main #Added by software-properties"
$ sudo apt-get -y update

Also verify or create the file /etc/apt/apt.conf, the following lines need to be present: proxy server name needs to be replaced with server name:

/etc/apt/apt.conf - should have these lines, use "sudo vi" or "sudo gedit" to edit the file depending on your preference,

Acquire::http::proxy "http:// proxy server name :80/"; 
Acquire::ftp::proxy "ftp:// proxy server name :80/"; 
Acquire::https::proxy "https:// proxy server name :80/";