Jump to content

VirtualBox/Setting up a Virtual Machine/Ubuntu

From Wikibooks, open books for an open world

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 20.04 LTS as a guest in VirtualBox-6.1 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 | edit source]
  • 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 20.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 "testUbuntu20")
  • 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 17.10 or later.[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 ("testUbuntu20") 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.
  • a file like "ubuntu-20.04.2.0-desktop-amd64.iso" file
  • The "Select start-up disk" window should pop up. Hit the little folder icon next to the drop-down box to bring up the "Optical Disk Selector" window. If the ISO image you just downloaded isn't already visible, hit the big green plus sign ("+") to bring up a file chooser. Then pick the ISO image you just downloaded and hit "open". In the "Optical Disk Selector" window, click on the ISO image you just downloaded and hit "Choose". Then click the "start" button.
  • A window saying something like "testUbuntu20 [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 | edit source]

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.
  • (Optional) When you reach the "Installation Type" window, there's also an "Advanced Features..." button here if you want full-disk encryption.[2] (The "Encrypt my home folder" option[3] has apparently been removed,[4] in response to bug #1756840.[5]).
  • 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.
  • ... 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.
  • 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.
  • 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 "testUbuntu20 [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.
  • 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.
  • If you see a "Connect Your Online Accounts" window, click "skip" for now.
  • 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.
  • Another way to install updates: press Ctrl+Alt+T to open a terminal window, then type
sudo apt update && sudo apt upgrade

then hit enter to install updates.[6]

    • If you see the message "... is not in the sudoers file. This incident will be reported.", it may be related to a minor glitch in "Unattended Guest OS Install". There are several ways to fix this by adding your username to the sudo group.[7]
  • 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 | edit source]

Next we install the Guest Additions.

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

(optional) If you have a very high-resolution monitor (high-DPI screen), the icons and default text in Ubuntu may look tiny and hard to read. One fix: In VirtualBox Manager, choose a VM, click the "Settings" gear, choose the "Display" tab from the left sidebar, and change the "Scale Factor:" to 200% (from the default of 100%).

Sharing folders with host OS

[edit | edit source]

To share folders between the host and the guest OS,

  • In the host OS open the Oracle VM VirtualBox Manager
  • choose the guest VM in the left sidebar
  • choose Settings in the right sidebar
  • choose "Shared Folders"
  • In the upper-right side, pick the folder with the plus sign ("+"),

and in the file-picker window that pops up, choose the folder you want to share. (There's options here for "Read-only" and "Make Permanent"). (If you leave the "Mount Point" blank, the folder will be mounted under "/media/" and the same folder-name as in the host OS).

  • Inside the virtual machine, open the "files" application from the left sidebar.
  • You should see the folder you selected earlier. Click on that folder to mount it.
  • If you get "You do not have the permissions necessary",

in the guest VM open a terminal with Ctrl+Alt+T and run[8][9][10][11]

sudo adduser $(whoami) vboxsf
reboot

A few things you can do with this virtual machine

[edit | edit source]

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 in the VirtualBox Manager 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)[12] or XFCE,[13]

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

   sudo apt-get install zram-config

Using ssh to access an Ubuntu virtual machine

[edit | edit source]

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:[15][16]

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

You may want to access some physical USB device from inside the virtual machine. (For example, you may want to run the Android SDK sandboxed inside a virtual machine, and then give it access to upload to a physical mobile phone).

  • In the VirtualBox manager, select the virtual machine, and then click on "Settings", then choose "USB".
  • ̈(optional) Choose USB 3.0 and click "OK" to save. (can only do this when the virtual machine is "powered off").
  • start the virtual machine
  • Plug in the USB peripheral device
  • In the VirtualBox manager, select the virtual machine, and then click on "Settings", then choose "USB" (again).
  • To pass *all* USB devices to the virtual machine, click the far right USB icon with the circle, then press OK.
  • To pass only *selected* USB devices to the virtual machine, click the far right USB icon with the plus sign. A list of all the currently-plugged-in USB devices should pop up. Choose one to add, then press "OK". (Repeat for any other devices you want to pass through).

The Ubuntu OS in that virtual machine should now automatically connect to those physical USB devices.

Booting the virtual machine from a physical bootable USB stick...[17]

increase virtual hard drive size

[edit | edit source]

To increase the virtual hard drive size, so Ubuntu sees a (virtually) larger hard drive, [FIXME]


Further reading

[edit | edit source]
  1. "Ubuntu Installation/SystemRequirements" says "2048 MiB RAM (system memory) for virtualised installs."
  2. EFF. "Privacy in Ubuntu 12.10: Full Disk Encryption".
  3. Dustin Kirkland. "Ubuntu’s Encrypted Home Directory: A Canonical Approach to Data Privacy".
  4. https://ubuntuforums.org/showthread.php?t=2397546 "Installation doesn't ask to encrypt home folder on 18.04"
  5. "Ubuntu ecryptfs-utils package bug #1756840".
  6. Abhishek Prakash. "16 Things to do After Installing Ubuntu 20.04". 2020.
  7. "How can I make my own account a sudoers on VirtualBox?".
  8. "How to access a shared folder in VirtualBox?".
  9. "File permission issues with shared folders under Virtual Box (Ubuntu Guest, Windows Host)".
  10. Jack Wallen. "How to share folders between guest and host in VirtualBox".
  11. VirtualBox forums. "HOWTO: Use Shared Folders".
  12. Pjotr. "Do this first in Ubuntu 14.04 LTS"
  13. Pjotr. "Turn Ubuntu 14.04 into Xubuntu 14.04"
  14. Andrew. "Increased performance in Linux with zRAM (virtual swap compressed in RAM)"
  15. Ubuntu. "SSH/OpenSSH/Configuring".
  16. "Enable SSH in Ubuntu 14.04 Trusty Tahr".
  17. "How to Boot VM From USB Stick".