Unix Shell in Windows
There are many things that i love with Unix: better developer tools, modularity, configurations are stored in text files, and shell scripts. The shell are so powerful, that it can replace full-featured IDE. Combined that shell flexibility, alongside with plethora of developer tools in the repository, and a little bit of imagination, you’ve got recipes for awesomeness.
But sadly, many things didn’t work out of the box in the Unix & Linux world. Drivers, for example, are problematic than it’s Windows counterparts. The rapid changes in the technology stack is also why there is so little ISV support in here. Another drawbacks are lack of QA/QC and fragmentation. You can see the list here, which is why Linux hasn’t taken the Desktop share yet.
Now, can we use the awesomeness of Unix, with the workstation power provided with Windows? What if I like the Windows world for it’s Drivers, and Applications, but also want to learn nginx, nodejs, and tuxlite? Absolutely, by using Virtual Machine (VM), Putty, and Ubuntu Server.
We’ll be using Virtualbox in Windows. The steps can also be used in other Hypervisor like VMWare or Hyper-V
Why Ubuntu Server
It has option called ‘minimal virtual machine’ that lets you install only bare minimum components and kernel optimized for virtual machine. It will also discards many stuff required for systems to work in the bare metal environment, like device drivers. This means lower footprint, and perfect for installing just what we need – the Unix Shell.
Virtual Machine Configurations
- The minimum memory required for Ubuntu Server to install is 128MB. You could use less, but the installation will probably failed
- Disable Audio and USB Controller. We don’t need those.
- Configure the VM to use two network adapters: the first one is attached to NAT , while the second one is attached to Host-Only interface . Make sure the adapter type is ‘Paravirtualized Network (virtio-net)’. This adapter type tells our Hypervisors to communicate with the guest directly through well-defined software interface, eliminating the needs to emulate underlying hardware. link
- If you need to share files between host OS and guest OS, then configure the shared folders.
Ubuntu Server Installation
- Press F4, and choose ‘Install minimal Virtual Machine’. Then, proceeds to Install Ubuntu Server. This is important
- When asked to choose the network interface, use the interface that is attached to NAT. On my system, it’s eth0
- When partitioning disks, i highly recommend to use LVM (Logical Volume manager). LVM abstracts the underlying disks partition to be much more flexible, but the configuration can be a bit painful.
- In the software selection dialogue, choose OpenSSH only.
- Proceed the installation. Then restart.
- Login into your guest OS
- You need to know the external network interfaces to be able to ssh into it. Use ifconfig command. Note the IP of your secondary interface / eth1.
- Open Putty, Enter the VM’s IP and ssh port (default is 22), and click Open.
- You need to install the Virtualbox Guest Addition to be able to open the shared folder you set earlier. Type these into the terminal:
sudo apt-get install make gcc linux-headers-$(uname -r)
sudo mount /dev/cdrom /media/cdrom
sudo usermod -a -G vboxsf your_username
sudo umount /media/cdrom
The shared folder will be mounted at
- Save the connection preferences by right-clicking putty window > change settings. You can shutdown the VM with shutdown -h now
- We can start our VM’s as headless mode, to further minimize the resource usage. This mode will start our VM without the Virtualbox Application Window, and your VM will stay on the background. The only way to connect to it is by using ssh
6.1 First, create file start.bat, and put these:
start /b script.vbs
6.2 Then, create script.vbs, and put these:
Set WshShell = WScript.CreateObject("WScript.Shell")
obj = WshShell.Run("script.bat", 0)
set WshShell = Nothing
6.3 Finally, create script.bat, and put these. The first line is to change to Virtualbox installation directory, while the second line is to start your VM. Change “UbuntuServer_12.04″ to your VM’s name
cd /d "C:\Program Files\Oracle\VirtualBox"
VBoxHeadless -s "UbuntuServer_12.04" -v off
- To start your shell, Klik start.bat first, then open putty, and load the preferences you saved earlier.
Optional: Putty Customizations
Now your ‘Unix shell’ is ready. Just ssh using putty to the VM, and you’re ready to go. If you need to provide further integration between the guest and the host, just configure the shared folder integration of your hypervisors
One final thing: your shell by default ain’t pretty. Here’s how to make it acceptable to look at:
- On your guest OS, install ncurses-term
apt-get install ncurses-term
- Once you have that package installed, you can instruct PuTTY to identify with that
$TERMstring in the Connection > Data
Once connected, make sure that your
$TERMstring matches what you specified
$ echo $TERM
- On category: Terminal > Bell:
3.1 Action to happen when a bell occurs: Visual bell (flash window)
3.2 Taskbar/caption indication: Flashing
- On Category: Window
4.1 Lines of scrollback: 20000
4.2 Reset scrollback on keypress: Checked
4.3 Reset scrollback on display activity: Unchecked
- On Category: Window > Appearance
5.1 Font: Adobe’s Source Code Pro, 11pt
5.2 Font quality: ClearType
5.3 Gap between text and window edge: 2
- On Category: Window > Translation
6.1 Character set: UTF-8
6.2 Handling of line drawing characters: Unicode
- On Category: Window > Selection
7.1 Paste to clipboard in RTF as well as plain text: enabled
- On Category: Window > Colours
8.1 Default Foregroudn 200,200,200
8.2 ANSI Blue: Red:74 Green:74 Blue:255
8.3 ANSI Blue Bold: Red:140: Green:140 Blue:255
- On Category: Connection
9.1 Seconds between keepalives (0 to turn off): 25
- Remember to save this settings preferences
On my system, the guest VM is quite lightweight and fast. It only consume about 20MB of virtual memory, and the VM start up instantly. You could possibly add the VM to automatically start up when the Windows start, without slowing down the system.