Ubuntu Virtual Machine: How to Install Ubuntu on VirtualBox

I moved my WordPress blog to a VPS from DigitalOcean and I wanted to have a local version of my VPS for testing. This guide will teach you how to install an Ubuntu server as a virtual machine using VirtualBox on a mac. To prepare you will need to download 2 files:

For this tutorial I will be using VirtualBox on a Mac and installing Ubuntu Server 14.04 LTS as a virtual machine. This tutorial also assumes you are familiar with the Nano Text Editor.

Install VirtualBox

Installing VirtualBox is a very simple process. Open the VirtualBox file you download and double-click the package to install. Accept all the default options and VirtualBox will be installed on your local computer.

At this point you can launch VirtualBox to start the process of installing the Ubuntu server virtual machine.

Create Ubuntu Virtual Machine

Using the VirtualBox application select New from the Machine Menu.

VirtualBox Ubuntu Virtual MachinesHere is a list of the options that you should choose as you progress through the Ubuntu virtual machine creation process:

  • Name = Ubuntu 14.04 LTS
  • Type = Linux
  • Version = Ubuntu (32 bit)
  • Memory = 512MB (or higher if your VPS has more memory)
  • Create a virtual hard drive now
  • Hard Drive File Type = VDI
  • VDI Storage = Fixed
  • VDI Size = 8GB

The virtual machine creation will take a few minutes.

Mount the Ubuntu Server Install Image

  • Select your new Ubuntu virtual machine and click the Settings button
  • Click the Storage tab
  • Under Controller: IDE, click the disk image that shows Empty
  • Click the disk icon next to the CD/DVD Drive drop down menu and select Choose a virtual CD/DVD disk file

VirtualBox Virtual CD Disk File

  • Navigate the open file screen to select the Ubuntu server install image that you downloaded
  • Click OK to close the settings page

Ubuntu Virtual Machine Installation

You are now ready to start your Ubuntu virtual machine for the first time by clicking the Start button. Your Ubuntu virtual machine will start by launching from the Ubuntu server install image you selected and guide you through the typical Ubuntu installation.

Options to choose (adjust as needed)

  • English
  • Install Ubuntu Server
  • English
  • United States
  • Detect Keyboard Layout = No
  • English
  • English
  • Hostname = ubuntu
  • New User = username (use username that will be deleted)
  • Encrypt Home Directory = No
  • Time Zone = Denver/Mountain (adjust for your timezone)
  • Partitioning method = Manual
  • Select VBOX HARDDISK
  • Create new empty partition table on this device = Yes
  • Select FREE SPACE
  • Create a new partition
  • New Partition Size = max
  • Type = Primary
  • Use as = Ext4 journaling file system
  • Mount point = /
  • Mount options = defaults
  • Label = none
  • Reserved blocks = 5%
  • Typical usage = standard
  • Bootable flag = off
  • Done setting up the partition

Ubuntu Partition Disk

  • Finish partitioning and write changes to disk
  • Do you want to return to the partitioning menu = no (you don’t want a swap created)
  • Write the changes to disk = Yes
  • HTTP proxy = blank for none
  • No Automatic Updates
  • Software Selection = OpenSSH Server
  • Install GRUB Boot Loader = Yes

First Boot – commands in VirtualBox window after logging in with username from installation

sudo passwd root #enables root account
sudo nano /etc/network/interfaces #add second interface below to allow connection from host
auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255

sudo nano /etc/ssh/sshd_config #modify to allow root login via SSH
PermitRootLogin yes

sudo poweroff #power off virtual machine

Create VirtualBox Host-only Network

  • From the VirtualBox menu select Preferences
  • Click the Network tab
  • Click the Host-only Networks tab
  • Click the Add button to Add a new Host-only Network
  • Clock OK

VirtualBox Host-only Network

  • Select your new Ubuntu virtual machine and click the Settings button
  • Click the Network tab
  • Click the Adapter 2 tab
  • Click the Checkbox to Enable Network Adapter
  • Select Attached to Host-only Adapter
  • Select the Network Name vboxnet0
  • Click OK

VirtualBox Adapter 2

Second Boot – commands in ssh terminal

Select your new Ubuntu virtual machine and click the Start button. If everything was done correctly you can now login using your ssh client (Terminal on a Mac).

ssh root@192.168.56.101
username=username #username chosen at installation
deluser $username #delete ubuntu setup user
rm -rf /home/$username #delete ubuntu setup user directory
poweroff

Your VirtualBox Ubuntu Virtual Machine should now be configured like a new DigitalOcean VPS with a root user enabled.

One thought on “Ubuntu Virtual Machine: How to Install Ubuntu on VirtualBox

  1. Toni

    Dear John,

    thank you for your very good article.
    Is it possible to create three partitions for SWAP, Ubuntu and Home in a virtual machine? Maybe it’s useful to have a SWAP partition and a home partition for data when you try a later Ubuntu distribution in the future and you want your data and settings back to your new Ubuntu distribution.

    Have you tried VMware Fusion or Parallels for virtualisation of Ubuntu in OS X?

    I have a MacBook Pro Mid-2009, 4GB RAM, 2,66Ghz Dual Core, SSD (running with TrimEnabler!) and would like to install Ubuntu Desktop 14.04 LTS amd64 in a virtual machine with three partitions. Do you have any advices?

    Best wishes,

    Toni

    PS: Do you get exactly the same VPS from your cloud server to your local machine for testing? Could you explain the transferring step and feature provided by DigitalOcean, respectively. Please.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.