Setup a Linux (Ubuntu) Environment

In this lab, we will go through the steps to setup a virtual machine (VM) on your own computer. This allows you to work in a Linux environment, regardless of the operating system (OS) running on your computer. We called the OS running on your computer the host OS, and the OS running in an VM the guest OS. Also, we include some basics of Linux and VirtualBox, which hopefully prepare you to work in a Linux environment.

Content

  1. Start a Linux VM (using VirtualBox)
  2. Using a Terminal in Linux
  3. More about VirtualBox
  4. References

Start a Linux VM

1. Obtain VirtualBox

VirtualBox is one of the software for VM hosting. It runs on Mac OS, Windows, and Linux, and is freely available on its official website, https://www.virtualbox.org/wiki/Downloads. You may download an installer of the latest version, according to your computer's OS.

VirtualBox Download Page

After downloading the installer, open it to install VirtualBox and use the default configurations, i.e., all you need to do is to click "Next" to proceed and "Yes" for prompts asking for permissions to modify computer's settings until the installation completes.

2. Obtain the VirtualBox machine image

Download the machine image for our course, which is a clean installation of 32-bit Ubuntu Trusty Desktop. The image, named "csci3150-ubuntu.ova", can be obtained here.

The settings of the VM:

3. Import the machine image

Open VirtualBox,

VirtualBox window

Select "File" > "Import Appliance ...".

Import machine image

Locate the machine image and click "Next".

Locate machine image

Keep the machine settings and click "Import".

Review machine image setting

Wait until the machine import completes and the machine will be listed in the VM manager.

Import completes

Make sure the network cable is connected by default:

Select the VM and click "Settings"

Network setting of VM

Choose "Network" > "Adapter 1" and check "Cable Connected"

Network setting of VM

4. Run the machine

Power up the machine

Select the VM, click "Start", and a new window pops out which shows the console of the VM.

Run the machine

Back to Top

Login

Wait while the machine and OS boots, until you see the login screen below. You may then login using the default username "csci3150", with password "csci3150".

Before login

After login, you will see a desktop, with the system bar on the left (in contrast to that at the bottom for Windows and Mac OS).

After login

And now we have finished setting up a VM running Linux.

Back to Top

Power off the machine

You may normally shutdown the machine in the OS, by clicking the "wheel" icon on the top right-hand corner and select "Shut Down ..." at the bottom of the list.

Shutdown from OS

Select "Shutdown" on the right in the prompt.

Shutdown from OS

The windows showing the console of VM will then close.

If you want to reboot your VM instead of shutting down, choose "Restart" on the left.

When it is impossible to shut down from OS, e.g. OS becomes unresponsive, you may force the VM to shutdown from VirtualBox as follows:

Select "File" > "Close".

Poweroff VM

Select "Power off the machine" > "OK".

Poweroff VM

Back to Top

Host key of VirtualBox (Important!!)

VirtualBox uses the right "Ctrl" key as the Host key by default, as shown at the bottom right-hand corner of the VM's window. By pressing the "Host key", you may attach/detach your input devices to/from the VM. When you intend to press/issue "Ctrl" inside the VM, use the left "Ctrl" instead of the right one to avoid confusion.

Back to Top

Using a Terminal in Linux

While most tasks can be done via the graphic user interface (GUI), it is important to learn how tasks can be performed using commands via a terminal in this OS course. Here we will try some basic examples.

Open a terminal

A terminal can be opened via searching.

Click the top-most icon in the system bar and enter "terminal" in the search bar.

Search terminal

Other than searching, you may use the shortcut "Ctrl"+"Alt"+"t".

Here is a terminal window:

Terminal

Note that the prompt csci3150@csci3150-VM:~$ is in form of [user]@[hostname]:~$. The examples of commands afterwards always start with the $ that corresponds to that at the end of this prompt.

Close a terminal

A terminal can be closed by

Back to Top

File management

Here are some examples on basic file management.

(Note that the commands are in one single line, i.e. don't break them into multiple lines!)

Back to Top

File editing

Text-based editor

Here are two commonly used text editors.

Nano / Pico

Back to Top

The most powerful user, "root"

There is always an ultimate user "root" in Linux, who has the right to do everything. Since the password is not yet set for "root", it is impossible to login in as root. However, a "sudoer" user, which is "csci3150" in our case, may upgrade herself to "root" via the command sudo: execute $ sudo su followed by entering the password of "csci3150". Note that the ending character of the command prompt changes from $ to # after sudo. To downgrade yourself back to "csci3150", execute exit.

Upgrade yourself to root

Back to Top

File transfer

Share folder (between VM and your computer's OS)

VirtualBox allows folder sharing between your computer and the VM. To use this function, you need to first install the "Guest Additions".

Select "Device" > "Insert Guest Additions CD image ...".

Install guest additions

Confirm the installation by clicking "Run" in the prompt.

Install guest additions

Wait until the installation completes, and press "Enter" to close the window.

Install guest additions

Add a new folder in the machine setting:

Select "Machine" > "Settings" > "Shared Folders". Click the "Adds new shared folder" button on the right.

"Shared folders" in "Settings"

Create a folder named "shared" on host OS and set it as a shared folder named "shared" for the VM. Remember to check both "Auto-mount" and "Make Persistent".

Setup "shared" folder

After adding the folder, you shall see an entry added to the list of shared folders. Click "OK" to confirm.

Confirm shared folder added

Back to the VM, add "csci3150" to the group "vboxsf" by executing the following command in a terminal.

$ sudo usermod -a -G vboxsf csci3150

Add "csci3150" to "vboxsf" group

Reboot the VM. VirtualBox will then automatically mount the shared folder inside the VM for you upon boot.

After the machine reboots, open a terminal and execute the following command to check if the folder is mount .

$ mount

Check if shared folder is mount

You shall found the line, shared on /media/sf_shared type vboxsf (gid=999,rw), which tells you that the shared folder is mounted on the local folder /media/sf_shared.

Let try using the shared folder by creating an empty document in the folder on the host OS, e.g. "hello.txt". After creating the file, your shall see the file inside your VM.

Check if the file is visible to guest OS

Then, write some content to "hello.txt" in VM using any text editor, e.g. nano (save by pressing "Ctrl"+"x" followed by "Y", and press "Enter").

Check if the new content is reflected on the host OS.

Back to Top

Package installation

Ubuntu uses APT to manage packages. It automatically resolves and installs dependencies when a new package needs to be installed.

To install a package, e.g. "vim", type $ sudo apt-get install vim. Type "Y" to confirm the installation.

Installing package

The GUI of APT is "Ubuntu Software Center".

Installing package

For packages available on web in .deb, you can always download them and double-click to install.

Beware that this VM runs on a 32-bit OS, which is corresponds to the architecture "i386". Choose packages built for the "i386" architecture, otherwise they won't install.

Back to Top

Command Manual

It is a good habit to understand commands by looking into their manual page, e.g. find out the usage and options available for listing a directory, $ man ls.

man example on `ls`

Back to Top

More about VirtualBox

Turning the screen resolution of your VM

Coding on a screen with low resolution, e.g. 640 x 480, can be painful... Fortunately, VirtualBox VMs are able to adjust their screen resolution according to the window size after installing the "Guest Additions".

Follow the steps to install "Guest Additions" in the Shared folder section (if you haven't do so). Reboot the VM after installation, and try resizing the VM's window to a customized size :)

Back to Top

References

Official guide on Ubuntu Desktop

An easy and rich guide to the basics of Ubuntu Desktop: https://help.ubuntu.com/14.04/ubuntu-help/index.html

Workaround for frequent error reporting popups

In a terminal,

$ sudo rm /var/crash/*

(Reference: Online forum post)

More on virtual machines

How to create a VirtualBox VM from scratch:

You may refer to the guide from VirtualBox: https://www.virtualbox.org/manual/ch01.html#gui-createvm

Alternative(s) to VirtualBox

There are other alternatives for hosting VMs on your own computer, e.g. VMware. The VMware workstation player is free for download, however, it only runs on Windows and Linux.

Running 64-bit virtual machines

If you want to create your own VM and install a 64-bit OS, you will need to enable the feature in the BIOS, namely VT-x for Intel processors, or AMD-v for AMD processors

Back to Top