Setting up your CS144 VM using VirtualBox

This guide will walk you through setting up Ubuntu Server 18.04 on your CS144 VM. This distribution gives a reasonably streamlined installation with few unnecessary background tasks running by default.

NOTE If you want a graphical interface, we strongly recommend using the prepared image. Otherwise, if you install an Ubuntu Desktop variant following these instructions, NetworkManager may interfere with your completing the assignments.

Table of contents

  1. Prerequisites
  2. Create a VM image
  3. Install Ubunbu
  4. Install the required packages
  5. Set up SSH port forwarding to your VM
  6. (optional) Set up a shared folder

Prerequisites

  1. Install VirtualBox.

    If your host OS is linux, your distribution may already package virtualbox:

  2. Download the installation image. If you’re using the recommended Ubuntu Server image, we’ve made a local mirror for faster downloading. Otherwise, download and verify your preferred installation medium.

    This is a large file, so use a wired connection or sit close to an access point while downloading!

    IMPORTANT: if you are downloading an installation image other than the recommended one, you should cryptographically verify it before using it. Compromised ISOs are an increasingly common issue—never use an unverified ISO! (We promise our local mirror won’t pwn you. But you should verify it anyway.)

Create a VM image

Start VirtualBox. You should see this:

Virtualbox startup screen
Virtualbox startup screen

Click the New icon or type Ctrl-N to bring up the new VM dialog. As shown below, you’ll need to choose a name for your VM, select “Linux” for the Type, and select “Ubuntu (64-bit)” for the Version.

New VM dialog
New VM dialog

Next, select the amount of RAM to allocate to your VM. You should allocate at least 1 GiB, but more is better, provided that your machine has the RAM to spare.

RAM dialog
RAM dialog

Next, choose to Create a virtual hard disk now, choose a VDI image, dynamically allocate space, and increase the image size from the default to 32 GiB. (Don’t worry: it’s dynamically allocated, so it won’t actually take up 32 GiB on your hard drive.)

Create a virtual hard disk now
Create a virtual hard disk now
VDI file type
VDI file type
Dynamically allocated
Dynamically allocated
Allocate 32 GiB
Allocate 32 GiB

You should now be back at the VirtualBox home screen:

VirtualBox home screen with newly created VM image
VirtualBox home screen with newly created VM image

Click the Settings icon or type Ctrl-S to bring up the Settings dialog:

  1. choose “Storage” from the left column
  2. click on the “Empty” CD-ROM drive
  3. click the CD icon on the far right (highlighted below)
  4. click “Choose Virtual Optical Disk File…”
  5. use the file picker to choose the ISO you downloaded in Prerequisites
  6. click OK
Machine settings dialog
Machine settings dialog

You’ve set up the VM. Now it’s time to install Ubuntu.

Install Ubuntu

From the VirtualBox home screen, click the Start icon. Your VM will boot, and in about two minutes you’ll arrive at the following screen. Accepting the defaults for the next few screens:

Ubuntu install start screen
Ubuntu install start screen
Ubuntu keyboard setup screen
Ubuntu keyboard setup screen
Install Ubuntu
Install Ubuntu
Default network settings are fine
Default network settings are fine
No proxy is necessary
No proxy is necessary

On the next screen, you can accept the default or, for slightly faster download, you can change the Ubuntu mirror to http://mirrors.ocf.berkeley.edu/ubuntu:

Berkeley has a fast Ubuntu mirror
Berkeley has a fast Ubuntu mirror
Use an entire disk
Use an entire disk
Choose the only disk available
Choose the only disk available

If you’re worried that the default partitioning scheme doesn’t have swap, don’t worry! Ubuntu will create a swapfile for you.

Accept the default partitioning scheme
Accept the default partitioning scheme
Confirm that you’re ready to install
Confirm that you’re ready to install

Choose a username, machine name, and strong password.

Choose a good password!!!
Choose a good password!!!
Don’t need any of this garbage
Don’t need any of this garbage
All done! Reboot.
All done! Reboot.

When it asks you to remove the installation medium, just hit enter.

Just hit enter
Just hit enter

Your VM will reboot into your freshly-installed server environment.

Install the required packages

We’ve created a script that will install the required packages, enable folder sharing with the host OS, etc. To download it, in your VM type:

wget https://web.stanford.edu/class/cs144/vm_howto/setup_dev_env.sh

STOP and read the script! Don’t just execute some crap you downloaded from the internet. Once you’re satisfied that you understand what’s going on:

bash ./setup_dev_env.sh

Once the script has finished, you can shut down your machine for now:

sudo shutdown -h now

Set up SSH port forwarding to your VM

From the VirtualBox home screen, click Settings or type Ctrl-S, then select Network, click the “Advanced” button, and click “Port Forwarding”.

Network settings -> advanced
Network settings -> advanced

This will bring up the port forwarding dialog. Click in the top-right corner to add a new rule.

Add a port forwarding rule
Add a port forwarding rule

Give it a name, and use the following settings:

Port forwarding rule added
Port forwarding rule added

Click OK a few times to get back to the VirtualBox home screen.

This will forward port 2222 of the host machine to port 22 (ssh) for the guest machine. You will be able to SSH into your VM using

ssh -p 2222 myname@localhost

where myname is the username you chose when setting up your VM.

(optional) Set up a shared folder

From the VirtualBox home screen, click Settings or type Ctrl-S, select “Shared Folders” in the column on the left, then click the “Add” button in the top-right corner.

Add a shared folder
Add a shared folder

Select a folder from the host machine to add. We recommend ticking “Auto-mount” to have it mounted automatically when your VM boots.

For example, to share /tmp
For example, to share /tmp

Auto-mounted folders will be available at /media/sf_<FolderName>, where where <FolderName> is the name you used in the Shared Folder dialog immediately above (in this example, <FolderName> would be tmp).

If you didn’t tick Auto-mount, you can still mount shared folders manually in your VM with:

sudo mkdir -p /media/sf_<FolderName>
sudo mount -t vboxsf -o rw,gid=vboxsf <FolderName> /media/sf_<FolderName>