Setting Up a Virtual Machine¶

Read time: 50 minutes (12503 words)

We will be working in Linux for this class, and since most of you do not have Linux running on your chosen development system, we are going to use an important tool in the development world: a virtual machine.

Basically, a virtual machine is just a program designed to act like a real computer. There are several possible such engines available:

• VMware - used in our labs (a commercial product available on all platforms)

• VirtualBox - a free tool from Oracle (which we will use here)
• Parallels - a commercial product for Mac

VMware seems to be the most advanced engine, but it is complex. There is a free version of this product, which is what is installed on lab machines. I prefer to use the VirtualBox engine these days.

Note

Running this (on a Windows system) will tell you if your hardware is suitable for this course. If not, see me immediately and we will set you up on a Rackspace server that you can use for your work. Note that in this case, you will not have access to the GUI applications, just a simple command line environment.

Also, just because this tool tells you that your processor can run a VM, does not mean everything is fine. You may need to get into the BIOS on your system and set it to allow VM tools to run. See me for help with this, since what you need to do depends on your system!

To install VirtualBox on a PC or Mac, you need to navigate to the product website and download the correct installer. I am going to demonstrate installing this tool on my Windows 10 system.

Here is the link I used to get the Windows installer:

Launch this program by double-clicking on the program file name in Windows Explorer:

Click on “next” to proceed.

You can accept the default location for this program. Click “Next” to continue

Again, the defaults are fine. Click “Next” to continue.

Here, the installer is warning you that you might lose access to the Internet during the installation. No streaming video should be going on! Click “Next” to continue.

Now, we are ready to install the program. Click “Install” to continue.

At this point, the installation will begin. The installer will copy files into place. You will probably see this pop-up during the process.

Click on “Install” to let drivers be installed.

The installation should complete with no problems. Click on “Finish” when this screen appears.

Now that you have VirtualBox installed, we need to create a real virtual machine running Linux.

Warning

This is going to take some time, since the file you need to download is about 1.8 GB. To save some time, I will place this file on your “I” drive, which you can access from a school lab machine.

We will be using a desktop version of Ubuntu Linux to run software for this course. The VM will be a 64-bit system, meaning that you need to set this up on a system with a suitable 64-bit processor.

We start off by downloading the operating system from the Ubuntu website. The version we will be using is 18.04 LTS, meaning that it will be supported for at least five years. We will be installing the desktop version, complete with a GUI, but you are free to use the console-only server version which will let you simulate working on a remote server.

This is the file you can use to set up your machine:

Installing the OS¶

Start off by starting VirtualBox

Click on the “New” button at the top of the screen. We are going to build a new computer, and not give any money to Fry’s!

In this screen, we name our machine. The name I picked makes it obvious to me which class this is for. (I have several VM machines set up for all kinds of purposes!)

The first thing to do is decide how much memory we are going to allocate to this machine when it is running. You need to be careful here, since if you give the VM too much memory, your host machine will slow down!

I usually use one to two gigabytes for Linux VM machines, more for a Windows VM!. If your machine has 4GB of RAM, stick with 1GB here. My laptops all have 8-16GB of RAM so I set mine to 2GB.

On this screen we decide how big our virtual hard disk will be. There is no need to go crazy here, this is not a place to load up video or music files. Instead only add things you need for the intended use of this VM. We are going to do C++ development in this machine. Since we are setting up a VM with a GUI interface, I use 20GB for the hard disk size.

Note

That 20GB size for the “Disk Image is not how big the virtual disk file will be when you start, it is how big it can grow to if you install lots of stuff! (We will not be doing that for this class,

Click on “Create” to continue.

You now have a new computer to play with. However, it has no operating system now. There are a few more hardware changes we need to make as well.

Click on the “Settings” menu item.

This window has a lot of options you can explore. There are a few standard things I do with my VM setups.

Click on the “Display” menu item:

Since we are using a GUI interface here, we need to tweak the video system a bit.

I raise the amount of video memory to that max value, 128MB. This is not a gaming video system, but we will be doing a bit of graphics work in our lab projects.

Note

The Dell laptop I use to PC development work has a high-resolution screen, with over 3000 pixels across the screen. When I set up a VM with the default settings, the VM window was tiny, and the text was barely readable. I raised the “Scale Factor” to 200% and the result was readable. I would try running with the default settings, and experiment with this setting if things seem too small. (This is the first machine I have had this problem with!)

Note also that I tried to turn on “2D Video Acceleration” but got the “Invalid settings detected” message. I actually turned that off after this screen shot.

Next, click on the “Shared Folders” menu item.

We will add a folder on your host machine and “map” that folder into the VM. This is extremely handy when you want to copy files between the host and the VM:

Right-click on the “Machine Folders” item in this screen. Select “Add Shared Folder”: :

I created a folder on my PC where I will put files to be shared. The settings you see here reflect that folder on my system. You can map any folder on your host system that you like. The “Folder Name” is the name that folder will have on the VM file system. We will talk more about this setup in class (after I test things a bit on my new Dell!)

Click on “OK” to continue.

Next, click on the “Storage” menu item:

Now, we need to set up the DVD so we can install Ubuntu! Note the “Empty” line next to the icon that looks like a DVD.

Click on the line with “Empty”. You will see a new window on the right.

On the line that says “Optical Drive”, click on the DVD icon on the far right, and choose “Choose Virtual Optical Disk File”. Navigate to the ISO file you downloaded (or copied from the “I” drive) and click on “Open”. Once this is selected, click on “OK’. This should return you to the settings menu.

Click on “OK” again, and you should be back on the main VirtualBox control panel.

At this point, you are ready to fire up your new machine, and let the OS install. Click on “Start” to power up your new machine. Since we have set up a virtual DVD with the OS installer in it, your machine will boot from that DVD.

Note

I missed on screen in building these notes. The installer will offer to “Try Ubuntu”, or “Install Ubuntu”. We want to install it.

It will also tell you that it will erase your hard drive and everything on it. Do not worry, that message is talking about the Virtual Hard Drive in the VM machine, not your host machine. This is totally safe.

The next few screens should be fairly obvious. The default settings are fine, so just click on “Continue” to move forward.

Unless you really want to use some foreign language keyboard, choose English here.

Assuming your host is connected to the Internet, it is best to allow updates to be installed as this process continues. These are the settings I used.

Here is where that scary message about erasing your hard disk is seen. Press on! Click on “Install Now”.

Another scary screen, just press “Continue”

Here you set your time zone. The installer should have detected the correct choice. Austin is not allowed, so Chicago is the right choice for us.

On this screen, you set up the default user account. Pick a user name you like, and enter a password (twice). The name on your computer will show up on command lines, so keep it short.

When you get here, the installer will plug away installing everything. This will take a few minutes to complete.

When the installer completes, you will see this screen. It is time to reboot the system and see Ubuntu!

Warning

I actually had some problems getting this system to boot up. It took about three tries before it successfully booted up. I need to research why that happened. Let me know if you experience anything similar. Once I got it started, the problem went away.

This screen wants you to uninstall the installer DVD. On my system, VirtualBox did that for me.

Note

If you seem to get right back into the installer setup, let me know. You need to shut down the VM, and remove the DVD from the VirtualBox control panel if this happens.

This is what you want to see before starting up the VM for real work.

And this is your first look at Ubuntu Linux, running in your virtual machine! Click on the “Next” item at the top to get rid of this startup stuff.

We need to run one command on this new system before we can continue. Click on that funny grid of dots at the lower-left of your screen, then move to the second screen by clicking on the lower check box on the right. .

Click on the “Terminal” icon. This will start up the terminal program so we can issue a command.

This is where we will do a lot of work. You might take a moment, and clean up things here. I usually delete the icons on the left side of this screen by right-clicking on icons I do not want and selecting “Remove from Favorites. When I see the icon for the Terminal program, I right click and select “Add to Favorites. Remember, this is a work machine, so I keep things focused on the work I intend to do. I will “play” on my host machine.

Type in this command. It will install the C++ compiler and other development tools we need.

The “sudo” stands for “Super-User DO”. It is Linux’s way of saying “I need more power!”. The super-user has the power to destroy the machine, so we wield that power carefully. Here, we need to install tools in protected system folders, so we need this level of control. As the default user of this machine, you have the power! Enter your login password to continue.

Personally, I hate white text on a dark background. If I print screen shots, they eat up a lot of black ink! Also, that kind of screen is hard to read when I project something in a classroom. You can change things by clicking on “Edit -> Preferences” at the top of the terminal window. Here I clicked on the “Colors” tab and make some changes. Feel free to explore settings. It is you who will be looking at this screen. Make it nice for you! (I may yell at you if you bring your machine to me for help and I cannot read the thing, though. YMMV!)