Sunday, November 23, 2008

Ubuntu 8.04 JEOS on VirtualBox

These instructions were written on Windows XP Pro SP3, but they can be used on any host OS on which VirtualBox runs (so OSX, Linux or Solaris, I think). The problems are all on the guest (Linux) OS, not on the host.

This was a major battle for me, but I finally got it all together. I think VirtualBox has a smaller footprint than VMWare (and doesn't install as many "services" in Windows) and in my testing, the virtual applicances are amazingly flexible and portable. Seems to work great, I thought, so I decided to uninstall VMWare and try to create an image from zero (basically).

Getting Started
  1. Install VirtualBox from Sun.
  2. Download Ubuntu 8.04 JEOS 
  3. Make a new virtual machine which we'll call Ubuntu804Jeos. This name is important and we'll need it later.
  4. Follow your nose for creating a working Linux on VirtualBox. Basically, you mount the CD image and you're good to go. The Linux virtual machine is called the "guest" OS, whereas the system that runs VirtualBox is called the "host."
  5. From the guest, try to ping google.com. This must work. If it doesn't, either give up, go find help, or figure out what the problem is using Google and your big analytic skills.
  6. Now, on to the fun stuff....
Set Up SSH
You'll definitely want to stop using the VirtualBox interface and eventually you'll need to connect to the machine, so you'll need to set up SSH.
  1. On your host machine, install some kind of SSH client like Putty on Windows
  2. Install SSH on your server. Easy, right? Use
    sudo apt-get install openssh-server
  3. How will you connect to the machine? Here's the fun part. After hours of not bothering to really understand the VirtualBox docs, I finally figured out that you don't have to change anything. From a Windows command prompt, find this program and run it with these parameters
    VBoxManage setextradata "UbuntuJeos804" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCP
    VBoxManage setextradata "UbuntuJeos804" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22
    VBoxManage setextradata "UbuntuJeos804" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 2222
  4. Don't close that window! Also, note that the name, UbuntuJeos804 was used from above. Substitute where necessary.
  5. Now you've configured your host machine's port 2222 to route to your guest machine's port 22. 
  6. Now you can connect with Putty or whatever other ssh client to localhost port 2222 and you're connected.
Set Up Lynx, LAMP, Apache, and the Port Forwarding for Apache
That was so fun! So now you'll do the same with Apache (and we'll install the whole LAMP stack while we're here)
  1. From the guest (using SSH!), install the whole LAMP stack
    sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server phpmyadmin
  2. Install lynx to have something to test with
    sudo apt-get install lynx
  3. Try to connect to Apache from inside the guest
    lynx localhost
  4. You should see the default Apache page ("It works!").
  5. Now get connected from the host. We map from port 8087 on the host to the guest
    VBoxManage setextradata "UbuntuJeos804" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestapache/GuestPort" 80
    VBoxManage setextradata "UbuntuJeos804" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestapache/HostPort" 8079
  6. That should be it! Now point a browser on your host machine to localhost:8087 and you should see the same message.
  7. While we're here, let's try PHPAdmin out too. It should be at http://localhost:8079/phpmyadmin/.
Install The Guest Additions
Now you're done! No, just kidding. The guest is on your own machine! You must be able to share files directly.
  1. Using the VirtualBox GUI, add the Guest Additions. This will do nothing (but will halfway mount the CD for the guest additions).
  2. Mount the CD
    sudo mount /media/cdrom
  3. Cd to the cdrom directory and try to run the Guest Additions
    sudo sh VBoxLinuxAdditions-x86.run
  4. This will result in all kinds of errors, so run the following meaningless commands (in which we mess with the Kernel and do all other stuff that is somehow relevant)
    sudo apt-get install gcc
    sudo apt-get install make
    sudo apt-get install build-essential
    sudo apt-get install linux-headers-`uname -r` 
  5. Reboot the machine.
  6. Do steps #2 and #3 again. Now you should have the Guest Additions installed.
Finally, You Can Share a Folder Using Vboxsf
That was necessary to be able to share a folder to your guest machine (adds the vboxsf file system type).
  1. Add a shared folder using the VirtualBox GUI. Mine is called ubuntu-share. 
  2. Now we can mount that using this command
    sudo mount -t vboxsf ubuntu-share /mnt/ubuntu-share
  3. Now your folder should be in /mnt/ubuntu-share
Running Headless
Now you might want to run the server "headless" once you don't need the GUI anymore. Use something like this
start "VirtualBox Headless" /b "C:\Program Files\Sun\xVM VirtualBox\vboxheadless" -s UbuntuJeos804
Conclusion, What's Missing
That's all I've got so far. The only thing that's missing, for my needs, is to make the mounting "sticky." I'll update this post when I figure that out.

Problems, comments, and corrections are all greatly appreciated.

Edit: I just wrote a bit more on this. Check out Virtual Hosts on Apache on your VirtualBox appliance.

6 comments:

John said...

Exactly what I needed. Thanks!

Daniel Rosenstark said...

Good to be here! I'm now running VirtualBox with Linux and Windows XP under OSX, and it works like a charm...

Thanks for reading.

John said...

To make your mounts stick, try adding this to the end of your /etc/fstab file: ubuntu-share /mnt/ubuntu-share vboxsf

It works for me under Jaunty.

Daniel Rosenstark said...

Thanks for that, I'll try it. I just noticed that etc/fstab file because I was watching my Linux vbox boot the other day. I imagine you mean with the word "mount" first, no?

John said...

Actually, no. That seems to be the syntax that works under Jaunty..

Daniel Rosenstark said...

Yeah, I'm sure Jaunty and Hardy or whatever it's called are the same in that regard.

At some point (and even now) I had some doubts about vboxsf and was using smb... vboxsf was causing weird results with rails. Anyway, thanks for the comments!