I’ve been trying to find a good way to run linux inside windows on my laptop for a long time. Why I want to do that? In this way I can work together with linux packages (like gcc and grace) and windows software (like ArcGIS, MS Excel/Access), which the dual-boot could not do. Linux-only option is not working well since I need to play games under Windows (okay, I’m fond of it :)) and none of the linux-host VMs support DirectX 9c yet.
Therefore, a perfect solution for me should be:
* Quick start and shutdown of guest inside the host
* Light-weight, it is not necessary to have window manager (like Gnome, KDE)
* In the guest, it will have full read/write/execute access to host files
* The ability to compile and execute
* Allow port forwarding so that I can ssh into guest from external machines
* Install and uninstall software easily (like apt-get functionality in ubuntu)
* Stable and safe for production
For now my best solution is using VirtualBox, I wrote some notes in the last part for my future reference, and other alternatives that I’ve tried before are also listed.
Cygwin:
Cygwin is the first software I tried, it does the job pretty well. If you need a one-click install for X support, try Cygwin/X. However, the install time is way too long, and it’s hard to adjust software once installed. Every software needs to be recompiled using a specific gcc compiler under win32 –- MinGW. I stopped using it because of this.
Andlinux:
Andlinux is a great alternative. The combination of colinux (a linux kernel which runs inside windows) and Xming (a light-weight X11 solution under windows without installing cygwin), and start colinux from windows service are very smart ideas. It uses ubuntu 7.10 so you can add/remove softwares in aptitude/synaptic. The host files are shared using CoFS, and easily accessible. It is very handy and convenient for use and seems to be a perfect option. The only problem on my Lenovo X61 tablet (Vista) is, it will freeze the host when wireless is on and it seems that the problem is because of the latest Intel wireless driver.
I’ve used it for quite a while, except the incompatibility with wireless driver, everything is fine. I kept using it until I see this note about the CoFS system:
CoFS is fully usable for coping files from and to windows. But never run a compiler on a cofs! (parts of this article are ‘based’ on two mails by HN on cofs)
I used gcc to compile my codes for a long time and I don’t want to lose files! Though I don’t have access to see exactly what’s the problem, to be safe it’s best to stop using until there is a more stable version.
Another file share that andlinux provided is using Samba. I had a hard time figuring how to do that without making my folders visible in the windows network.
VirtualBox:
I’ve keep focusing VirtualBox for a long time. Today the latest version (2.1.4) finally solved the bug that it will freeze windows using linux guest, and another bug that it is unable to let files have execute access using shared folder, so I decide to give it a try.
Since I don’t need window manager, the best way seems to be VirtualBox+Xming+putty.
First, install a ubuntu command-line system in VirtualBox (after booting from CDROM, hit F4 and select “command-line install” at the startup menu), and install any necessary packages (dkms, build-essentials, linux-header, openssh, etc) using aptitude and synaptic.
Install the VirtualBox guest additions: Click “Install guest additions” under VirtualBox menu “Devices”, then make sure VBoxGuestAdditions.iso is mounted as CD-ROM, then find the contents under /media/cdrom0. If it is empty, run the following command:
sudo mount /dev/scd0
(check /etc/fstab first for the correct label if other than scd0)
Change directory to /media/cdrom0 and sudo sh ./VBoxLinuxAdditions-x86.run. If dkms, build-essentials, and linux-header have been installed, the installation should go through.
After that, set up port forwarding in windows host using the following commands:
Open a windows terminal (cmd), change directory to the virtualbox folder (like c:\program files\virtualbox), and run the following commands:
VBoxManage setextradata “VM NAME” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/sshfwd/Protocol” TCP
VBoxManage setextradata “VM NAME” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/sshfwd/GuestPort” 22
VBoxManage setextradata “VM NAME” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/sshfwd/HostPort” 2222
Replace VM NAME with the guest name in VirtualBox and sshfwd with any name as long as they are unique, and replace 2222 with any port you would like to open in the host system.
Then start Xming and putty, connect to localhost port 2222, and remember to click “Enable X11 forwarding” under SSH->X11 category.
Now I can start any X11 applications from the command line in putty!
To access the host files, first set up the shared folder in VirtualBox (make sure it has full access and make permanent). Then make a directory under /mnt, like /mnt/shared, and add the following line to /etc/rc.local: (Assume the shared folder name is “shared” when setting it up in the VirtualBox; and there is only one user, or you have to find your own gid and uid using id <your username>)
mount -t vboxsf -o gid=1000,uid=1000,dmode=0777,fmode=0777 shared /mnt/shared
Reboot and the files should be automatically mounted at /mnt/shared. To access from the home directory, use
ln –s /mnt/shared
And a link to the directory will appear!
The only cons is, there is a minimized virtualbox window in the taskbar at all times. But is doesn’t matter to me.