VirtualBox/Setting up an Ubuntu virtual machine

From Wikibooks, open books for an open world
Jump to: navigation, search

Once you have VirtualBox installed on your host computer -- it doesn't matter if your host OS is Linux, MacOS, or something else -- setting up an Ubuntu virtual machine is easy.

host operating system pre-install steps[edit]

  • Go to http://www.ubuntu.com/ , hit the "download" link, and pick whichever version of Ubuntu you want to try out in a virtual machine. For example, you may want to try the 32-bit version of Desktop Ubuntu 14.04.1 LTS. Download it to your host computer. This may take a few minutes -- continue with the following while it's downloading.
  • Start the Oracle VM VirtualBox Manager.
  • Hit the starry blue "New" icon.
  • Name the virtual machine. (Many people give woefully uncreative names like "testUbuntu14")
  • Choose Type: Linux
  • Choose Version: Ubuntu (32 bit).
  • Hit the next button a few times (default 512 MB RAM, 8 GB hard drive file -- you can make these bigger or smaller later)
  • You should see an icon for your virtual machine in the left sidebar of the Oracle VM VirtualBox Manager.
  • (Optional: If your purpose for setting up this machine is to practice installing Ubuntu on a RAID array in a safe sandboxed environment, set up additional virtual hard drive images now under Settings >> Storage).
  • Click on the icon for that virtual machine ("testUbuntu14") and hit the big green arrow "Start" icon.
  • Has the download finished yet? When it's done downloading, you should have a file that ends in ".iso".
  • The "Select start-up disk" window should pop up. Hit the little folder icon to bring up a file chooser, then pick the ISO image you just downloaded. If you want to try the 32-bit version of Desktop Ubuntu 14.04.1 LTS, you'll choose the "ubuntu-14.04.1-desktop-i386.iso" file and click the "open" button. That should close the file chooser. Then click the "start" button.
  • A window saying something like "testUbuntu14 [Running] - Oracle VM VirtualBox" should pop up and take a minute or so to boot up. Eventually it should show a big "Welcome" window with two big options: "Try Ubuntu" or "Install Ubuntu". We hit the "Install Ubuntu" option.
  • (By default, we'll be running in a tiny 640x480 pixel "virtual monitor" window for a while -- we'll fix the screen resolution later).

installing inside the virtual machine[edit]

The previous steps created .vdi file that acts like a fresh, empty hard drive, and now we're going to install Ubuntu on it exactly the same we would on a physical machine with a physical fresh, empty hard drive.

  • We pick the "Install Ubuntu", make sure everything is checked on the "Preparing to install Ubuntu" screen, then hit the "Continue" button.
  • You are at the "Installation Type" window, still inside the "testUbuntu14 [Running] - Oracle VM VirtualBox" window, right? We accept the default "Erase disk and install Ubuntu" and hit the "Install Now" button. (There's also a "Encrypt" option here that does full-disk encryption,[1] and a "Encrypt my home folder" option[2] a few steps later).
  • ... Continue ...
  • After entering your user name and password and hitting "continue", Ubuntu will take many minutes install.
  • Write down that password on a sticky note. We'll need it later.
  • Eventially you see the "Installation Complete" message. Hit the "Restart Now" button.
  • Typically Ubuntu shows a "All processes ended within 2 seconds" message, with a few more obscure messages. If it appears to hang on that screen, at the top of the "testUbuntu14 [Running] - Oracle VM VirtualBox" window, hit the "close window" icon and choose "Power off the machine", OK.
  • Open up the Oracle VM VirtualBox manager. The "testUbuntu1" VM currently has the "Powered Off" icon, right? Select the VM, and hit the green arrow "start" icon.
  • It may take Ubuntu a minute to boot up the first time from a cold start. (VirtualBox *should* have automatically ejected the ISO image, so you'll see a normal Ubuntu desktop with the default Ubuntu background, menu bars, etc.
  • This would be a good time to hit the "Software Updater" icon on the left side (not to be confused with the "Ubuntu Software Center"), and install the latest updates.
  • Hey, remember that password we wrote on a sticky note earlier? Type it in and hit the Authenticate button.
  • This may take a few minutes -- minimize the Updater window and continue with the following while it's downloading and installing updates.

So, are we finished installing?

return to the host operating system for further installation steps[edit]

Next we install the Guest Additions.[3]

  • Go back to the host operating system. At the top of the "testUbuntu14 [Running] - Oracle VM VirtualBox" window, choose Devices >> "Insert Guest Additions CD image..."
  • (VirtualBox simulates inserting a CD into the simulated optical drive, and Ubuntu auto-mounts that CD under "/media/a/").[4]
  • When Ubuntu gives the "VBOXADDITIONS... automatically started. Would you like to run it?..." pop-up window, hit "run".
  • Hey, remember that password we wrote on a sticky note earlier? Type it in and hit the Authenticate button.
  • Ubuntu pops up a new terminal window and takes a minute to install and start up "VirtualBox Guest Additions". When the last line of that terminal window says "Press Return to close this window...", click inside that window and press Return.
  • Go back to the host operating system. At the top of the "testUbuntu14 [Running] - Oracle VM VirtualBox" window, most people find it convenient to enable Devices >> Shared Clipboard >> Bidirectional.
  • Shut down the virtual machine from the "gear" icon in the upper right corner, "Shut down..." >> Shut Down.
  • Open up the Oracle VM VirtualBox manager. The "testUbuntu1" VM currently has the "Powered Off" icon, right? Select the VM, and hit the green arrow "start" icon.
  • (The next time you restart after installing the guest additions, the "virtual monitor" window should now be 800x600 pixels).
  • (Now when you look under "/media/a/", the "Guest Additions CD image" is still there -- do I need to do something to "take it out of the (virtual) drive"? If so, how?)
  • (optional) To automagically resize the size of the virtual monitor to fill the "testUbuntu14 [Running] - Oracle VM VirtualBox" window whenever you stretch or shrink that window,
    • At the top of the "testUbuntu14 [Running] - Oracle VM VirtualBox" window, choose View >> Auto-resize Guest Display.
    • When you installed the Guest Additions (as described above), that option should have been enabled. There is apparently two separate bugs that can keep it greyed out even after installing the Guest Additions and rebooting:[5][6]
    • Some people suggest editing a "/etc/X11/xorg.conf" file, but that file apparently no longer exists in Ubuntu14.
    • Some people suggest using apt-get to (re)install guest additions, uninstalling that version, and then re-install the guest additions again from the VirtualBox ISO:[7]
      • Inside the virtual machine, open a terminal window and run "sudo apt-get install build-essential dkms virtualbox-guest-additions-iso". Hit "y" to continue.
      • Next, uninstall the guest additions: "sudo apt-get remove --purge virtualbox-guest-additions-iso> "Insert Guest Additions CD image..." and re-install it, as described above.
      • Reboot
      • wait a minute until the GUI desktop comes up
      • At the top of the "testUbuntu14 [Running] - Oracle VM VirtualBox" window, choose View >> Auto-resize Guest Display.


A few things you can do with this virtual machine[edit]

If your purpose for setting up this machine is to practice administering RAID arrays -- setting up a new RAID array, failing, operating while degraded, adding empty hard drives to the array, rebuilding, scrubbing, etc. -- in a safe sandboxed environment, you can add and remove additional virtual hard drive images at any time under Settings >> Storage.


You can easily move this virtual machine to some other computer -- even a computer running a completely different host operating system. (One exception: 64-bit Ubuntu will not run on 32-bit hardware. 32-bit Ubuntu, however, runs fine on both 64-bit Intel processors and 32-bit Intel processors.)

An operating system inside a virtual machine may see several hard drives. Typically they are all actually ".vdi" files stored on a single host hard drive. But some people tweak the VirtualBox settings so that the operating system can directly access (perhaps in read-only mode) physical drive(s), so the hard drive that guest operating system sees is, in fact, a physical hard drive.

Many people disable the "fading windows" effect and other pretty effects by installing "CompizConfig Settings Manager" and turning off "effects" and "Enhanced Zoom Desktop".

Many people install and use a "fast, lightweight" window manager such as GNOME Flashback (Metacity)[8] or XFCE,[9]

Some people install zRam for better performance with limited RAM. This is a single command in Ubuntu 12.04 and newer: open a terminal window, and run[10]

   sudo apt-get install zram-config

Using ssh to access an Ubuntu virtual machine[edit]

Inside the virtual machine window, you can open a terminal window and ssh to some other server -- that's all installed by default.

Often people want to access a text terminal on an Ubuntu server from a Windows box -- that takes a few more steps:[11][12]

  • Make sure the openssh-server is installed:
    • Open the Ubuntu Software Center from the left sidebar, type "openssh-server" in the search sidebar, and click the install button.

OR

    • Open a terminal window from the left sidebar, and run the command
   sudo apt-get install openssh-server
  • Edit the config file
   sudo vim /etc/ssh/sshd_config
  • Find the line that says "PasswordAuthentication", and make sure it says
   PasswordAuthentication no

then save that file and exit.

  • restart the ssh server
   sudo /etc/init.d/ssh restart
  • Install PuTTY on the Windows box. (This works more-or-less the same as the "ssh" command installed by default in Ubuntu).
  • Get the IP address of the Ubuntu box: At the top of the virtual screen there's an icon that allegedly looks like an internet connection; pull it down and choose "Connection information".
  • Most likely the IP address will begin with "10." or "192.", a local address that is not usable outside the local network.
  • (FIXME: is this really the Right Thing to Do?) In the Oracle VM VirtualBox Manager, select the virtual machine, choose the big yellow gear "Settings", choose "Network" on the left side, and change the "Attached to:" from "NAT" to "Bridged Adapter", and hit OK.
  • Get the IP address of the Ubuntu box again: At the top of the virtual screen there's an icon that allegedly looks like an internet connection; pull it down and choose "Connection information". (This will almost certainly be a different IP address than the one you saw before enabling "Bridged Adapter").
  • Run PuTTY on the Windows box, and type the "Bridged Adapter" IP address in the "Host Name or IP address" box, and hit Enter.

You should be able to log into the virtual machine now.


Further reading[edit]