Categories
Linux

VirtualBox, Windows and Linux: Getting the best out of both worlds!

Windows and Linux are two entirely different OS. They have their own strengths and weaknesses. Many software and solutions are unique to either of the platform. If you’re an intelligent person, you’d love to get the best out of the both platforms.

If I talk about myself, I need Windows for many reasons. For academic purposes and as because of some minor but critical compatibility issues. My Notebook PC has issues with WiFi connectivity on Linux. Same goes for my Nokia X2 which can not talk to my PC via bluetooth if I am on Linux. On the other hand, I am a LAMP engineer. Linux is a must for my day to day works. In the past I used to run a Windows XP inside virtualbox. That used to solve some of my problems but not all. To be honest, till today, Windows has the best hardware compatibility no matter how their other features suck. We can argue whether it’s the fault of the hardware manufacturers or not but that won’t change the fact at all.

Finally, I have decided that I shall keep Windows 7 as my default OS and install Ubuntu inside virtualbox. In this way, I can access the required features of the Linux platform (LAMP, Postfix, nGinx and all others) and at the same time enjoy the benefits of Windows.

Even more interesting, I can share directories between the OS, so I can easily share my www on Windows and make the same stuff available on Linux. I planned to make the shared www the doc root of the apache in Linux so I can test the same application on Linux without hassles. This will give me the ability to try those PECL extensions, PEAR packages and other contents which are generally not available for Windows. So what did I do?

1) I installed VirtualBox (http://virtualbox.org)

2) I inserted my Ubuntu 10.10 disc. I proceeded with creating a virtual machine. On the way, I created a virtual hard disk in VirtualBox for the installation. The wizard is pretty simple. Anyone would be able to install Ubuntu on VirtualBox with ease.

3) After the Ubuntu installation was complete, I logged into the system. From the VirtualBox Window, I went to “Devices” menu, then clicked “Install Guest Additions”. This command added a CD to the virtual machine (Ubuntu). I went to “Places” > < Virtualbox Guest Addition CD name >. I double clicked the “autorun.sh” file and ran it on terminal. After a few moments, it was installed. The Guest Additions enable file sharing between the guest and host OS.

4) In the VirtualBox window, I clicked on “Devices” menu and then “Shared Folders”. I added a shared folder named “www” with full access. This was in fact the www root of my WAMP server.

5) Then I logged into Ubuntu and installed LAMP. After that, I opened up the “/etc/rc.local” file and typed in the following command:

What did it do? It actually mounted the shared www in /var/www when the machine (Ubuntu) started up. Making my WAMP server www available on LAMP. Since I have given the folder full access while sharing, I can use the terminal to do some dark magic on the files as well 😉

So, from now on, I no longer need to struggle while creating a “.htaccess” file or “index.php” file on Windows. Terminal will do that. 🙂

If you want to access the LAMP localhost from your Windows, go to “Devices” > “Network Adapters”. Add a “Host only adapter” to access it from the host OS. If you have a router and want to forward your port to the virtual machine, add a “Bridged Adapter” and select your WiFi or LAN driver.

After setting up the adapters, restart your machine and open terminal. Type in:

You can see the IP addresses attached to the virtual machine. Apparently you can access the LAMP www both via eth0 and eth1 IP address.

I have an exam tomorrow but couldn’t resist to share the little experiment and the awesome outcome! I was on a haste and everything might not be clear. Feel free to ask any questions. I shall respond when I can manage some time 🙂

Have fun!

Update: Backup the virtual HDD. In case something happens, you will be able to reuse it and skip all the installation hassles.