Exploring Vagrant with Ubuntu and Oracle XE

I ran across Andrej Koelewijn’s article about Vagrant over a year ago, and I have been wanting to explore it ever since.  I do a lot of playing around with different things, and Vagrant looked like it would be a cool, quick way to spin up a new image of an OS.  I would love to get it to the point of being able to spin up an instance of PeopleSoft.  I am no where near there now, though.

This is just my first run through.  I set an easy goal of trying to get Oracle XE running on Ubuntu via the repositories.  Unfortunately, I learned that that repository isn’t worth the time.  Still, it was a fruitful exercise, and I definitely will be playing around more with Vagrant.

Follow along if you like…

Installing Vagrant

For me, since I am running Ubuntu 12.10, I found Vagrant already in the repositories.  I could easily install it from the software repositories:

Vagrant in the Software Center

Note that I already had Oracle’s virtual box installed.  The vagrant install was as straightforward as it gets.

If you aren’t using Linux or Ubuntu, you can check out the Vagrant download page.  They support many other platforms.

Vagrant Downloads

Choosing an OS/Box

The website tutorial uses Lucid, which is an old version of Ubuntu.  I want to keep up to date, so I went searching for something newer.  I found that the Vagrantbox.es Website had a great list.

To start with, I chose the latest version of Ubuntu.  I needed 64-bit to support PeopleSoft, which may come eventually.  So, here’s what I chose:

Ubuntu 12.10 Quantal x86_64 (Guest Additions 4.2.2) — https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box

You’ll see further in the article, that I had to change to a 32-bit image because the repository didn’t support 64-bit images.  So, I used this image:

Ubuntu Server 12.04.1 i868 (VirtualBox 4.2.1) — http://dl.dropbox.com/u/4031118/Vagrant/ubuntu-12.04.1-server-i686-virtual.box

Later on, Oracle Linux would be a good choice to experiment with.  I’ll save this box for later:

Oracle Linux 6.3 x86_64 (chef) — https://dl.dropbox.com/s/zejz4yljiexqcfu/oracle64.box

I was even curious to find a Windows box on the list.

Windows Server 2008 R2 – Datacentre core (Puppet, VirtualBox 4.2.4)  — http://dl.dropbox.com/u/58604/vagrant/win2k8r2-core.box

Building the box

I created a directory specifically for this.  For me, that was: ~/app/vagrant/ubuntuoracle

Then, I ran this command to download and create the new box:

vagrant box add ubuntuoracle https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box

That didn’t take too long since I have a nice Internet connection, but did take a few minutes.  Here is what the output looked like:


skp@chestnut:~/app/vagrant/ubuntuoracle$ vagrant box add ubuntuoracle https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box
[vagrant] Downloading with Vagrant::Downloaders::HTTP...
[vagrant] Downloading box: https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box
[vagrant] Downloading box: http://cloud.github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box
[vagrant] Extracting box...
[vagrant] Verifying box...
[vagrant] Cleaning up downloaded box...

At this point, I didn’t have anything new in my Virtual box manager.

Then, I ran this command to initialize the box:

vagrant init ubuntuoracle

This is the output:


skp@chestnut:~/app/vagrant/ubuntuoracle$ vagrant init ubuntuoracle
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

Just out of curiosity, I opened the “Vagrantfile”, and if I ignore all of the comments, this is all that was in it:


Vagrant::Config.run do |config|

    config.vm.box = "ubuntuoracle"

end

Again, I found nothing new in my Virtual Box Manager at this point either.

Finally, I ran this command:

vagrant up

Troubleshooting Failing Booting

Here’s my output:


skp@chestnut:~/app/vagrant/ubuntuoracle$ vagrant up
[default] Importing base box 'ubuntuoracle'...
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.

Guest Additions Version: 4.2.2
VirtualBox Version: 4.1.18
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] Failed to connect to VM!
Failed to connect to VM via SSH. Please verify the VM successfully booted
by looking at the VirtualBox GUI.

To see if it is running and what the name is, you can use VBoxManage:


skp@chestnut:~/app/vagrant/ubuntuoracle$ VBoxManage list runningvms
"ubuntuoracle_1363121046" {a6817f09-3e6e-4813-95db-75d7fdc75164}

I found that I could read the network information like this:


skp@chestnut:~/app/vagrant/ubuntuoracle$ VBoxManage showvminfo ubuntuoracle_1363121046 | grep ";NIC 1"
NIC 1: MAC: 080027733F26, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny
NIC 1 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 1 Rule(0): name = ssh, protocol = tcp, host ip = , host port = 2222, guest ip = , guest port = 22

I suspect this is part of the issue.  There is a bug between Virtual Box, Ubuntu, and NAT.

Then, I could power off the box like this:


skp@chestnut:~/app/vagrant/ubuntuoracle$ VBoxManage controlvm ubuntuoracle_1363121046 poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

To test the theory about NAT, I uncommented this line in the Vagrantfile:


config.vm.network :bridged

Then, I called the destroy command (which removed it from the Virtual Box Manager), and the up command again.

That still didn’t fix the problem, so I uncommented this line and tried again:


config.vm.boot_mode = :gui

After that I could log into the console and see what was going one.  In the documentation, I found that the typical user should be vagrant, and the password should match.  Thankfully, that was the case with my machine.

What I found was that it wasn’t really going to Bind mode yet.  It was still in NAT.  And, I couldn’t ping the machine from my host, and my host couldn’t get to the Internet.  When I changed the interface to Bind, and I did “sudo service networking restart”, then I could ping the machine.

Thanks to a post on Ask Ubuntu, I found that I could add this to the VagrantFile:


config.vm.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
config.vm.customize ["modifyvm", :id, "--natdnsproxy1", "on"]

That fixed the problem.  After that, this was my output:


skp@chestnut:~/app/vagrant/ubuntuoracle$ vagrant destroy
Are you sure you want to destroy the 'default' VM? [Y/N] y
[default] Destroying VM and associated drives...
skp@chestnut:~/app/vagrant/ubuntuoracle$ vagrant up
[default] Importing base box 'ubuntuoracle'...
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.

Guest Additions Version: 4.2.2
VirtualBox Version: 4.1.18
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Running any VM customizations...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- v-root: /vagrant

Installing Oracle

First, I read that if you have less than 1G of memory, you need to create swap space.  To avoid that, I am going to bump up the memory to 2G.  I found I could do that easily by adding this line to the Vagrantfile:

config.vm.customize ["modifyvm", :id, "--memory", 2048]

After that, I re-built the machine, and I used the ssh command to connect:

vagrant up
vagrant ssh

Then, I ran these commands to install Oracle XE:

sudo sh -c 'echo "deb http://oss.oracle.com/debian unstable main non-free" >> /etc/apt/sources.list'
wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install oracle-xe

32 bit vs 64 bit

Unfortunately, the Oracle repository only has the 32-bit version of Oracle in it.  When I tried it on my 64-bit version, it couldn’t find the URLs:


W: Failed to fetch http://oss.oracle.com/debian/dists/unstable/main/binary-amd64/Packages 302 Found

W: Failed to fetch http://oss.oracle.com/debian/dists/unstable/non-free/binary-amd64/Packages 302 Found

W: Failed to fetch http://oss.oracle.com/debian/dists/unstable/main/binary-i386/Packages 302 Found

W: Failed to fetch http://oss.oracle.com/debian/dists/unstable/non-free/binary-i386/Packages 302 Found

E: Some index files failed to download. They have been ignored, or old ones used instead.

I had to change my base image to a 32-bit image.  So, I added this image instead:

vagrant box add ubuntuoracle32 http://dl.dropbox.com/u/4031118/Vagrant/ubuntu-12.04.1-server-i686-virtual.box

Bad Oracle Repository

I have finally determined that this Oracle repository is not any good.  It keeps timing out.  Here’s what the failure messages look like:


Hit http://se.archive.ubuntu.com precise-backports/universe Translation-en
Ign http://oss.oracle.com unstable InRelease
Ign http://oss.oracle.com unstable Release.gpg
Ign http://oss.oracle.com unstable Release
Ign http://oss.oracle.com unstable/main TranslationIndex
Ign http://oss.oracle.com unstable/non-free TranslationIndex
Err http://oss.oracle.com unstable/main i386 Packages
 Undetermined Error
Err http://oss.oracle.com unstable/non-free i386 Packages
 Undetermined Error
Ign http://oss.oracle.com unstable/main Translation-en_US
Ign http://oss.oracle.com unstable/main Translation-en
Ign http://oss.oracle.com unstable/non-free Translation-en_US
Ign http://oss.oracle.com unstable/non-free Translation-en
W: Failed to fetch http://oss.oracle.com/debian/dists/unstable/main/binary-i386/Packages Undetermined Error

W: Failed to fetch http://oss.oracle.com/debian/dists/unstable/non-free/binary-i386/Packages Undetermined Error

E: Some index files failed to download. They have been ignored, or old ones used instead.
vagrant@vagrant-ubuntu-precise:~$ sudo apt-get install oracle-xe
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package oracle-xe

So, instead of using apt-get to download it from the repository, I just browsed to the website and found the URL to the package.  So, these commands did the install for me:


wget https://oss.oracle.com/debian/dists/unstable/non-free/binary-i386/oracle-xe_10.2.0.1-1.1_i386.deb
wget https://oss.oracle.com/debian/dists/unstable/main/binary-i386/libaio_0.3.104-1_i386.deb
sudo dpkg -i libaio_0.3.104-1_i386.deb
sudo apt-get install bc
sudo dpkg -i oracle-xe_10.2.0.1-1.1_i386.deb
sudo /etc/init.d/oracle-xe configure

Connecting to the Database

Next, I wanted to connect to the database to verify that it was actually running.  My first problem was that it was listing only on the localhost.  I could see what the listener was doing just by statusing the service:

sudo service oracle-xe status

Then, I pinged the hostname to see that it was returning an ip address that started with “127”.

ping `hostname`

To fix the issue, I used ifconfig to find my current IP address.  Then, I edited /etc/hosts and changed the line with the hostname on it to use the actual ip address from ifconfig.  Finally, I just had to restart the oracle service:

sudo service oracle-xe restart

That still didn’t fix my problem although it may have brought me a step closer.  I decided that it wasn’t worth the time, and decided to just connect with sqlplus in my ssh session.  I had to set the ORACLE_HOME, but that did the trick.  Note that during the configure part, I set the SYS and SYSTEM accounts’ password to vagrant.

 export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export PATH=$PATH:/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin
sqlplus system/vagrant@XE

So, here’s the output:


vagrant@vagrant-ubuntu-precise:~$ sqlplus system/vagrant@XE

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 13 15:40:07 2013

Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

SQL> select name from v$database;

NAME
---------
XE

Review

I have hopped around, so here are the commands that ended up working all together:

vagrant box add ubuntuoracle32 http://dl.dropbox.com/u/4031118/Vagrant/ubuntu-12.04.1-server-i686-virtual.box
vagrant init ubuntuoracle32

Then, I added the following lines into the Vagrantfile:

config.vm.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
config.vm.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
config.vm.customize ["modifyvm", :id, "--memory", 2048]

Then, I continued with these commands:

vagrant up
vagrant ssh
wget https://oss.oracle.com/debian/dists/unstable/non-free/binary-i386/oracle-xe_10.2.0.1-1.1_i386.deb
wget https://oss.oracle.com/debian/dists/unstable/main/binary-i386/libaio_0.3.104-1_i386.deb
sudo dpkg -i libaio_0.3.104-1_i386.deb
sudo apt-get install bc
sudo dpkg -i oracle-xe_10.2.0.1-1.1_i386.deb
sudo /etc/init.d/oracle-xe configure

Resources

Leave a Comment

Your email address will not be published. Required fields are marked *

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