Thursday, February 13, 2014

Accessing a Web Server on a Virtual Box Ubuntu Guest from the Host Server

I do a lot of development of web applications in VirtualBox virtual machines running Ubuntu. Although I could (and sometimes do) set up the virtual machine to have multiple monitors, I usually don't, instead leaving one monitor for the host OS (Win7) and another for the VM.  So it's handy for me to be able to run a browser on the host OS and access a web application on the VM. In VirtualBox, I accomplish this with Port Forwarding.

Go into settings for the VM and select Network->Advanced and click Port Forwarding.

Then enter the IP address of your host machine, the port to forward, the IP address of the guest and the port the web application runs on.The example below sets up forwarding from http://localhost:8080 to a web application running on port 8080 (Tomcat in this case) on the VM:





Mint as a new VM?

UPDATE: after going through all of this, the OS locked up on me. I had to hard-stop it and then could notrestart - VirtualBox couldn't find the boot disk. So I'm going back to Ubuntu. I don't know why this happened, but I don't have time to explore it either...


I've gotten in the habit of created Ubuntu virtual machines on my laptop for various projects. I have a new one starting up and decided to create a new VM for that. I was going to install Ubuntu, but I recently heard about the Mint OS. Kind of an Ubuntu clone with a different desktop - Cinnamon instead of Unity. Since Unity isn't my favorite part of Ubuntu, I thought I'd give mint a try. So here's the blow-by-blow.

I have a Dell XPS I7 quad-core with 16Gb RAM and 2x750GB HDDs. The hardware is a beast. It's running Win7. I use Oracle VirtualBox to create the VMs.

I downloaded the 64 bit ISO of the Cinnamon version of mint from http://www.linuxmint.com/

I already have VirtualBox installed, so I started out by creating a new VM in VirtualBox. I specified a 64bit Ubuntu system with 10gb RAM and an 80GB hard drive. In settings I put the following:

  1. General->Advanced: Bidirectional Shared Clipboard and Bidirectional Drag'n'Drop
  2. System->Processor: 4 CPUs, 100% execution cap, Enable PAE/NX
  3. Display->Video: Max Video memory (128 MB), 1 monitor, Enable 3D Acceleration (more on monitors below).
  4. Network->Advanced->Port Forwarding: I add in some forwarding depending on what I'm doing so that I can run a browser on the Win7 host OS and access a web server on the Guest VM. But that can't be done until we know the IP address of the Guest. See image below.
  5. Shared Folders: I create two -- one for a directory on the Win7 HDD through which I can share files and another to the Dropbox directory on the Win7 HDD. I could install Dropbox on the VM OS, but why have those files duplicated on the host and the guest. I make these shared folders Automount and *not* readonly. See image below




Now, I'm ready to install the OS into the VM, which is easy the first time I click "Start" in the VM. I have to say, if I screw that part up, I haven't looked into how to install on a second start :-) - I just point at my downloaded ISO and go...

Unlike Ubuntu, there are no questions or anything. So I'm guessing I need to customize it after the install. First things first, reset the root password:  sudo passwd root -- That makes all the installs easier.

And I set up the mounts to Dropbox and the shared folder:

sudo mkdir /home/Dropbox
sudo chmod 777 /home/Dropbox
sudo mount -t vboxsf Dropbox /home/Dropbox
sudo mkdir /home/Sharing
sudo chmod 777 /home/Sharing
sudo mount -t vboxsf Sharing /home/Sharing

And created a shell script I can run when starting up to make those mounts (I can never remember the mount command).

More on the various tools and apps I installed later...