VirtualBox/Setting up a Virtual Machine/Ubuntu

From Wikibooks, open books for an open world
Jump to navigation Jump to 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.

(This was tested installing Ubuntu Desktop 18.04 LTS as a guest in VirtualBox-6.0.18 on a Windows 10 host. Other versions and other hosts should work similarly.) (For Ubuntu 14.04.1 LTS, see https://en.wikibooks.org/w/index.php?title=VirtualBox/Setting_up_a_Virtual_Machine/Ubuntu&oldid=3656915 ).

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 Ubuntu Desktop 18.04 LTS. Download it to your host computer. Don't wait until it is done, which 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 "testUbuntu18")
  • Choose Type: Linux. (Ubuntu is one kind of Linux. Remember, this is the guest operating system running inside the virtual machine, not your host operating system).
  • Choose Version: Ubuntu (64 bit).
  • The default is 1024 MB RAM -- bump this up to at least 2048 MB RAM for Ubuntu 18.[1]
  • Hit the "Next" or "Create" button a few times (2048 MB RAM, keep the default 10 GB hard drive file -- you can make these bigger or smaller later), until you 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 ("testUbuntu18") 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" in your downloads folder.
  • The "Select start-up disk" window should pop up. Hit the little folder icon next to the drop-down box to bring up a file chooser. Then pick the ISO image you just downloaded. If you want to try the 64-bit version of Ubuntu Desktop 18.04.4 LTS, you'll choose the "ubuntu-18.04.4-desktop-amd64.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. It takes a minute or so for the Ubuntu LiveCD to boot up inside that window. 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 800x600 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. 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" option.
  • We choose keyboard layout, etc., hitting "Continue" a few times.
  • 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.[2] (The "Encrypt my home folder" option[3] has apparently been removed,[4] in response to bug #1756840.[5]).
  • ... Hit the "Continue" button a few more times ...
  • 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.
  • Eventually you see the "Installation Complete" message. Hit the "Restart Now" button.
  • Typically Ubuntu shows a few text logging messages as it shuts down.
  • If it appears to hang on that shutdown screen, at the top of the "testUbuntu18 [Running] - Oracle VM VirtualBox" window, hit the "close window" icon and choose "Power off the machine", OK. Then Open up the Oracle VM VirtualBox manager. The "testUbuntu18" VM currently has the "Powered Off" icon, right? Select the VM, and hit the green arrow "start" icon.
  • If you see the "Please remove the installation medium, then press ENTER:" message, go ahead and press ENTER -- VirtualBox should remove the (virtual) CD (actually a ".iso" file) automatically.
  • 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 should *not* see the two big "Try Ubuntu" or "Install Ubuntu" options from the LiveCD ISO image).
  • When you see a bar with the username you typed in earlier, click it and type the password you wrote on the sticky note earlier.
  • Since this is the first time Ubuntu 18 has booted, you'll see the "What's new in Ubuntu". Check out the new features, click "Next" a few times, then "Done".
  • Typically the "Software Updater" window pops up saying "Updated software ... do you want to install it now?" You may as well click the "Install Now" button.
  • 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.

Please go to VirtualBox/Guest Additions/Ubuntu and follow the instructions there.


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)[6] or XFCE,[7]

To try out Xubuntu (with XFCE), at the command line type "sudo apt-get install xubuntu-desktop gksu leafpad synaptic" (not including the quotes). Then press enter, type your password, then press enter again. It takes a few minutes for Ubuntu to download and install the Xubuntu stuff. Then log out of Ubuntu. At the login window, click the logo next to your user name, and pick "Xubuntu session".

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[8]

   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:[9][10]

  • 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]

  • "Ubuntu Installation/SystemRequirements" says "2048 MiB RAM (system memory) for virtualised installs."
  • EFF. "Privacy in Ubuntu 12.10: Full Disk Encryption".
  • Dustin Kirkland. "Ubuntu’s Encrypted Home Directory: A Canonical Approach to Data Privacy".
  • https://ubuntuforums.org/showthread.php?t=2397546 "Installation doesn't ask to encrypt home folder on 18.04"
  • "Ubuntu ecryptfs-utils package bug #1756840".
  • Pjotr. "Do this first in Ubuntu 14.04 LTS"
  • Pjotr. "Turn Ubuntu 14.04 into Xubuntu 14.04"
  • Andrew. "Increased performance in Linux with zRAM (virtual swap compressed in RAM)"
  • Ubuntu. "SSH/OpenSSH/Configuring".
  • "Enable SSH in Ubuntu 14.04 Trusty Tahr".