Assignment: VM

(Edited 27 Jan: put sudo in front of the command apt-get install command below.)

This assignment due 27 January 2017 at 8PM on Collab.

Purpose

The purpose of this assignment is to familiarize yourself with the environment we will use in future assignments.

Our VM environment

We will use a 64-bit Ubuntu 16.04 LTS machine for the course. We recommending installing a virtual machine of this type to do your work for this course. You may, alternatively, use a native installation of Ubuntu 16.04 LTS or attempt to use some other Linux distrubution, but the course staff will not support configurations if you run into problems.

Note that the solutions to some of our assignments may depend on the specific version of compilers and libraries included with this version of Ubuntu, so we strongly advise you still setup this VM even if you already have a working Linux installation.

Note that previously this course has been taught using 32-bit x86 VMs and programs. We hope to switch to 64-bit x86 as it should be more consistent with what prior courses are now teaching and is more likely to match systems you will use in the near future. However, there is a small chance some students may have machines which cannot support a 64-bit VM. If this true, we want to find out as soon as possible, so we can adjust future assignments.

VM Installation Instructions

These are instructions for installing Ubuntu 16.04LTS desktop in VirtualBox. If you wish to install an Ubuntu 16.04LTS in an alternative environment, that is okay, too, but we will not provide instructions for that. (One example of an alternative your instructor likes is using vagrant and the ubuntu/xenial64 “box”.)

Install VirtualBox

If you do not already have VirtualBox installed, follow these instructions. For these instructions, you will be asked to identify your “host” operating system. This is the operating system you will be running the virtual machine software on and not the operating system.

  1. Download VirtualBox version 5.1 from https://www.virtualbox.org/wiki/Downloads. Choose the appropriate version for your host operating system.
  2. Download Ubuntu 16.04 LTS from http://releases.ubuntu.com/16.04/. Choose the “64-bit PC (AMD64) desktop image” disc image.
  3. Install VirtualBox:
    1. Run the installation file you downloaded from the VirtualBox site to start the VirtualBox Installer.
    2. Click Next.
    3. Click Next, possibly after changing the installation location.
    4. Select the shortcuts you want to use.
    5. Select “Yes” on the Network Interfaces warning page. However, ou have any other applications that require uninterrupted network, wait for those applications to finish before proceeding with the VirtualBox Installation.
    6. Click Install to begin the installation process.
  4. Install Ubuntu 16.04 LTS. If you receive a message about “VT-x/AMD-V hardware acceleration is not available on your system” during this process, or you the list of VM versions does not only contains “32-bit” versions; see the section “VT-x support” below;
    1. Start VirtualBox.
    2. Choose a name for your VM.
    3. Select “Linux” as the VM type, “Ubuntu (64-bit)” as the VM version, then click “Next”.
    4. Use the recommended memory size (or specify a larger size, if you choose).
    5. Select “Create a new virtual hard disk now” and click “Create”.
    6. Select “VDI” as the disk type and click Next.
    7. Select “Dynamically allocated” and click Next.
    8. Choose the size of your VM’s hard drive and where it will be stored in the host OS. If you have the space, we recommend around 20GB. Click “Create”
    9. In the “Settings” screen for your VM, goto “Storage”, then select the “empty” cdrom (CD icon).
    10. If you want to run the VM on a large monitor, you may want to go to “Settings”, then “Display” and increase the amount of Video RAM (say to 32 or 64 MB).
    11. Click the CD icon next to the “Optical Drive” drop box and choose the disc image you downloaded earlier.
    12. Start your VM by clicking on the “Start” button.
    13. Follow the on-screen Ubuntu installation instructions. Note: You will see a message about erasing the disk and installing Ubuntu. It’s OK, it is going to erase the virtual disk—not your real disk
  5. Install development tools.
    1. In the Ubuntu VM, wait for the virtual machine to restart. Login to the VM.
    2. Open a terminal. To do this, click the Ubuntu logo in the upper-left corner of the dashboard and search for “Terminal”.
    3. You may wish to pin the terminal to the Ubuntu dashboard by right-clicking its icon and selecting this option on the menu that pops up.
    4. Run the following command:

      sudo apt-get install build-essential flex g++-multilib libc6-dev-i386 libc6-dev:i386 virtualbox-guest-dkms
      

      This will install:

      • C and C++ compilers that support both 32-bit x86 and 64-bit x86;
      • the parser generator flex, which we may use later in the semester
      • tools for making the guest OS be able to take advantage of some special features of the VM such as shared folders

Unix exercise and deliverable

  1. Open a terminal window.
  2. Open a text editor, such as gedit or pico, and create a file called hello_world.c in your home directory containing the following:

    #include <stdio.h>
    int main(int argc, char **argv) {
        printf("Hello world! I am a Wizard in Training.\n");
        return 0;
    }
    
  3. Run clear command to clear the terminal
  4. Compile the C source file you created with for 64-bit with gcc -o hello64.exe hello_world.c
  5. Run this file and to make sure it works with ./hello64.exe
  6. Compile the C source file you created with for 32-bit with gcc -m32 -o hello32.exe hello_world.c
  7. Run this file and to make sure it works with ./hello32.exe
  8. Run the command uname -a
  9. Take a screenshot of your terminal window. There are several options for doing this: a. Research, for example with web search, how to do this in your host OS. b. Take screenshot in the VM’s OS using gnome-screenshot -i. c. Research an alternate way to take a screenshot in your host OS.
  10. Submit the screenshot via Collab as your submission for this assignment.

Useful VM tricks

We also recommend figuring out how to access files on your VM from your host OS. One way to do this is to use VMWare’s shared folders feature which lets you access folders on the host OS from inside your VM. You can configure this from the VM settings. (You might need to reboot the VM to have this take effect.)

VT-x support

For 64-bit VMs, VirtualBox requires some hardware support from your processor. This support is present on almost all processors made recently (including all laptop or desktop processors introduced by Intel since 2013). However, some computer manufacturers disable this support by default. When they do this, you can usually reenable the feature in BIOS or “the Setup Utility”.

How you access the BIOS/Setup varies between manufacturers. Common ways include pressing Enter or F2 or F12 or Del while booting the machine. If you are using Windows 10, you may need to first shut down the machine while holding shift – some Windows 10 installations default to not performing a “complete” shut down. You should be able to lookup full instructions online for accessing BIOS/Setup based on the model of your laptop or desktop.

Once in the Setup utility, the option to change is likely to be called something like “Intel VT-x” or “Intel Virtualization Technology”. Confusingly, this setting is sometimes under category called “Security” instead of something more obvious. After changing it, save the settings and reboot.

The exact steps involved in acccessing the setup utility and changing this setting will vary. But, for example, on my laptop, a Lenovo Thinkpad T460, I did the following:

If you have trouble setting getting 64-bit VMs to work on your machine, please do not hesitate to contact the course staff for assistence.

In the unlikely event that you have a laptop that does not support running 64-bit VMs with VirtualBox, we will make alternate arrangements such as making the assignments only use 32-bit, or finding a way for you to do the assignments by remote logging into lab machines.