Running Ubuntu 17.04 on VirtualBox with Shared Folders
June 26, 2017
Introduction
Today I decided to create a new Ubuntu 17.04 virtual machine on my Mac
mini. I had already made one a few weeks ago, but not really happy
with the disk size I had selected; too large. Nor was I happy with
mounting shared folders via rc.local
,
see
Mounting VirtualBox Shared Folders. This
time I wanted to mount those folders by adding lines to /etc/fstab
.
On Ubuntu 16.04 I had some odd issues with MySQL in combination with VirtualBox shared folders. Issues that gave me the impression that somehow the database got corrupted. I haven't been able to pin point the cause yet. To play safe, on Ubuntu 17.04 I didn't use a shared folder for the database files, hence the larger disk size. But on this new install I want to check this out once more, and hopefully find out what is causing this.
I prefer to use Shared Folders because I can edit my files on either the host, a Mac mini, or guest without having to transfer files back and forth. Moreover, Time Machine takes care of the backup of those files and the much smaller virtual disk image.
Dowloading and verifying Ubuntu 17.04
I visted the Ubuntu 17.04 (Zesty Zapus) release page
and downloaded
the
64-bit PC (AMD64) desktop image. As
I am running VirtualBox on a Mac mini I used shasum
to verify its
integrity:
$ shasum -a 256 ubuntu-17.04-desktop-amd64.iso
b718c7fb1066589af52f4ba191775b0fb514c5fb6fa7d91367043e1db06d8a0b ubuntu-17.04-d
esktop-amd64.iso
The result reported is identical to the first result in Zesty's SHA256SUMS file.
Creating the Ubuntu Zesty Zapus Virtual Machine
I started VirtualBox and activated the New (blue sun) icon to start the creation of a new virtual machine. I entered/selected the following values in the "Name and operating system" dialog and activated the Continue button:
- Name: Ecce 17.04.
- Type: Linux.
- Version: Ubuntu (64-bit).
The name for this virtual machine was taken from the Cadwal Chronicles by Jack Vance. A trilogy I highly recommend to read, if you like to read science fiction.
Because my 2014 Mac Mini has 16 GB of memory and I want to use this virtual machine for development, in the "Memory size" dialog I entered 8192 MB, or half of the maximum available. I activated the Continue button to move on to the next step.
In the "Hard disk" dialog I left the default, "Create a virtual hard disk now", selected and activated the "Create" button.
In the "Hard disk file type" dialog I lef the default, "VDI (VirtualBox Disk Image)", selected and activated the "Continue" button.
In the "Storage on physical hard disk" dialog I left the default, "Dynamically allocated", selected and activated the "Continue" button.
In the "File location and size" dialog I only changed the default size of 10.00 GB into 12G and activated the "Create" button.
Futher Configuration of the Virtual Machine
After I had created the virtual machine I had to do some additional configuring. With the new virtual machine selected I activated the Settings (yellow cog) icon.
- In the "Display" pane I enabled 3D acceleration
- In the "Storage" pane I selected the "Empty" entry under "Controller: IDE" on the right hand side. Next, I activated the CD icon to the far right of "Optical Drive:". In the pop up menu I selected "Choose Virtual Optical Disk File...". I browsed to the Ubuntu image I downloaded earlier and activated the "Open" button.
- In the "Network" pane I selected Bridged Adapter for "Attached to". In the advanced options I entered the MAC address for "Ecce" so my router can use DHCP to assign the correct IP address to this virtual machine.
- In the "Ports" pane I activated the "USB" tab. In this tab I selected "USB 3.0 (xHCI) Controller". With the default USB 2.0 I ran in the past into "Failed to attach the USB device" errors.
Note, while you can create Shared Folders in the "Shared Folders" pane I created them on the command line, as explained below.
Installing Ubuntu 17.04
Start the Ubuntu Virtual machine by activating the Start (green arrow) icon. With English selected, I activated the large "Install Ubuntu" button that showed up after a short while.
In the next step I ticked "Download updates while installing Ubuntu" and activated the "Continue" button.
In the next step I left the default "Erase disk and install Ubuntu" selected and activated the "Install Now" button. Note that this is the virtual hard disk created earlier and not the host's hard disk and hence no data will be lost.
I activated "Continue" in the "Write changes to disk" dialog.
Next, Ubuntu guessed the time zone correctly so I just activated "Continue" without making any changes once more.
In the next step I changed my keyboard layout to English (US) - English (US) as English is the language I used the most on my computer, instead of Spanish. Next, I activated the "Continue" button. Note that if, like on my system, there is no such button you have to make the window of the virtual machine larger by stretching it to the right.
In the next step I entered my name, computer name (ecce), and password. My username was correctly obtained from my first name. I activated "Continue" to finally start the actual installation process, which took less than 3 minutes. I restarted the virtual machine as requested, and pressed Enter as requested somewhat later.
Installing the Guest Additions
Virtual Guest additions are required to make Shared Folders work. So after the restart I logged into the virtual machine for the very first time.
In the menu bar of the virtual machine under Devices I activated the "Insert Guest Additions CD image...". A dialog window opened asked if I would like to run it. I activated the "Run" button. Next, I had to enter my login password, as I am also the super user, in order to install the Guest additions. When the installation was done, I ejected the CD and restarted the virtual machine.
Now, with the guest additions installed, I changed the resolution of the Ubuntu virtual machine to 1920 x 1200, which is full screen on the Dell monitor I am using.
Setting up the Mount Points on the Guest
Next, I created the required mount points on the guest machine:
mkdir -p ~/{.my-local,Amber,mysql-dumps}
mkdir -p ~/Public/GoodReader/
sudo mkdir /var/lib/mysql
sudo mkdir -p /home/svn/
I use .my-local
for perlbrew
and to store some other programs. My
work is stored in the Amber
directory. Back in 1994 when I started
my own company I named it 'Castle Amber', hence the name.
For this set up I also want to share the MySQL database files and my
subversion directory. Although I switched to git
years ago I now and
then need to work on an old project, and convert it from svn
to git
.
Setting up Shared Folders on the Host
I stopped the virtual and ran the follow commands on the command line of the host machine:
VBoxManage sharedfolder add "Ecce 17.04" --name ".my-local" \
--hostpath /Users/john/.my-local
VBoxManage sharedfolder add "Ecce 17.04" --name "Amber" \
--hostpath /Users/john/Amber
VBoxManage sharedfolder add "Ecce 17.04" --name "Documents" \
--hostpath /Users/john/Documents
VBoxManage sharedfolder add "Ecce 17.04" --name "Downloads" \
--hostpath /Users/john/Downloads
VBoxManage sharedfolder add "Ecce 17.04" --name "Pictures" \
--hostpath /Users/john/Pictures
VBoxManage sharedfolder add "Ecce 17.04" --name "mysql-dumps" \
--hostpath /Users/john/mysql-dumps
VBoxManage sharedfolder add "Ecce 17.04" --name "GoodReader" \
--hostpath /Users/john/Public/GoodReader
VBoxManage sharedfolder add "Ecce 17.04" --name "svn" \
--hostpath /Users/john/Public/svn
mkdir -p ~/Library/MySQL/mysql
VBoxManage sharedfolder add "Ecce 17.04" --name "mysql" \
--hostpath /Users/john/Library/MySQL/mysql
Note that you can find out the exact name of a virtual machine by listing all available ones using:
$ VBoxManage list vms
"Ecce 17.04" {18af93bb-cc60-41e1-96ab-d36ef08b18f8}
As I wanted the data created by MySQL out of the way I decided to create
a directory MySQL
under /Users/john/Library
with a sub directory named
mysql
.
Automatically Mounting Shared Folders on the Guest
Next, I started the guest and configured it in such a way that the
shared folders are mounted automatically at boot. Because at boot the
required VirtualBox module is not loaded yet it has to be added to
/etc/modules
. After editing the file looks like follows on my
Ubuntu guest:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
vboxsf
Next, I added the following lines to /etc/fstab
on the Ubuntu guest:
.my-local /home/john/.my-local vboxsf uid=1000,gid=1000 0 0
Amber /home/john/Amber vboxsf uid=1000,gid=1000 0 0
Documents /home/john/Documents vboxsf uid=1000,gid=1000 0 0
Downloads /home/john/Downloads vboxsf uid=1000,gid=1000 0 0
Pictures /home/john/Pictures vboxsf uid=1000,gid=1000 0 0
mysql-dumps /home/john/mysql-dumps vboxsf uid=1000,gid=1000 0 0
mysql /var/lib/mysql vboxsf uid=124,gid=132 0 0
GoodReader /home/john/Public/GoodReader vboxsf uid=33,gid=33 0 0
svn /home/svn vboxsf uid=33,gid=33 0 0
The numeric values for uid
and gid
were obtained using the id
command on the guest. For my account these values are:
$ id -u john
1000
$ id -g john
1000
Both GoodReader
and svn
are used by the Apache web server, and
need to be mounted by user www-data
, group www-data
. The numerical
values for each are 33. For mysql
the uid
is 124 and the gid
is
132 while running under 17.04. This differs from 16.04, so beware.
After saving the changes to /etc/fstab
I restarted the virtual
machine and logged back in. I verified that each mount point in my
home directory showed the expected files and directories and that I
was the owner using ls -al
. After this, I verified the svn
and
mysql
mount points as well.
Next I installed MySQL and made the installation secure as follows:
sudo apt-get install mysql-server mysql-client
mysql_secure_installation
As expected, the data created by this step became available in OS X
under /Users/john/Library/MySQL/mysql
:
$ ls -al ~/Library/MySQL/mysql/
total 376848
drwxr-xr-x 13 john staff 442 Jun 26 18:02 .
drwxr-xr-x 3 john staff 102 Jun 26 16:40 ..
-rw-r----- 1 john staff 56 Jun 26 17:44 auto.cnf
-rw-r--r-- 1 john staff 0 Jun 26 17:44 debian-5.7.flag
-rw-r----- 1 john staff 419 Jun 26 17:44 ib_buffer_pool
-rw-r----- 1 john staff 50331648 Jun 26 18:04 ib_logfile0
-rw-r----- 1 john staff 50331648 Jun 26 17:44 ib_logfile1
-rw-r----- 1 john staff 79691776 Jun 26 18:04 ibdata1
-rw-r----- 1 john staff 12582912 Jun 26 17:45 ibtmp1
drwxr-xr-x 77 john staff 2618 Jun 26 17:44 mysql
drwxr-xr-x 90 john staff 3060 Jun 26 17:44 performance_schema
drwxr-xr-x 108 john staff 3672 Jun 26 17:44 sys
drwxr-xr-x 110 john staff 3740 Jun 26 18:02 wikidb
Running ls -al
inside the guest shows, again as expected:
$ sudo ls -al /var/lib/mysql
[sudo] password for john:
total 188428
drwxr-xr-x 1 mysql mysql 442 Jun 26 18:02 .
drwxr-xr-x 77 root root 4096 Jun 26 18:45 ..
-rw-r----- 1 mysql mysql 56 Jun 26 17:44 auto.cnf
-rw-r--r-- 1 mysql mysql 0 Jun 26 17:44 debian-5.7.flag
-rw-r----- 1 mysql mysql 419 Jun 26 17:44 ib_buffer_pool
-rw-r----- 1 mysql mysql 79691776 Jun 26 18:04 ibdata1
-rw-r----- 1 mysql mysql 50331648 Jun 26 18:04 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Jun 26 17:44 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 Jun 26 17:45 ibtmp1
drwxr-xr-x 1 mysql mysql 2618 Jun 26 17:44 mysql
drwxr-xr-x 1 mysql mysql 3060 Jun 26 17:44 performance_schema
drwxr-xr-x 1 mysql mysql 3672 Jun 26 17:44 sys
drwxr-xr-x 1 mysql mysql 3740 Jun 26 18:02 wikidb
While the sorting order differs, the sizes and timestamp of each file is identical.
Note that I had already imported one database, wikidb
, at this point.