SSH login on a VirtualBox VM using NAT

I find it useful to have a virtual machine running in the background, to test and explore stuff without the risk of breaking my main host. VirtualBox provides a fast and easy way to run virtual machines on your system. You can do pretty much the same using KVM visualization, but this post is focused on VirtualBox, on a Linux desktop.

VirtualBox provides different options as it comes to networking. The default setting is NAT networking, and it is sufficient for most of my needs.

The guest I am using is Ubuntu Server 14.04 LTS. What I want to do is SSH from my host to my virtual machine so I can work with it from my host’s terminal emulator and have less windows cluttering on my desktop. I can also use copy/paste with my terminal emulator between my host and guest, since we can’t use the VirtualBox shared clipboard without an X server running on the guest (which I don’t need). Another thing is that you won’t be stuck with the mouse and keyboard capture of VirtualBox’s gui, which prevents you from using alt+tab to switch between applications on your host.

For the following steps, I assume your guest VM is already installed and shut down.

The first step, is to open a port on your virtual machine for SSH to work. From the VirtualBox Manager, select your VM, and click on Settings/Network/Advanced/Port Forwarding. Now, create a rule for SSH.

Name: SSH
Protocol: TCP
Host IP: leave empty
Host port: 8022 (you can use another port as you like)
Guest IP: leave empty
Guest port: 22 (This is the official Secure Shell “SSH” port)

Click okay to accept your new rule. You can now close the VirtualBox Manager window, but take note of your VM’s name (mine was simply called “Ubuntu Server”).

You can do the previous step using the command line, like the following:

$ VBoxManage modifyvm "Ubuntu Server" −−natpf1 "SSH, tcp, , 8022, , 22"

Now, what you want to do is start your virtual machine in headless mode. You can do this from the Oracle VM VirtualBox Manager using your mouse’s contextual menu but we’ll be using the command line.

For a terminal emulator or the command line, type the following:

$ VBoxManage startvm "Ubuntu Server" --type headless

Now, your VM is starting in headless mode (in the background). Give it a second to boot. (You can take a peek in the VirtualBox Manager to see the booting process from the preview panel).

Once your virtual machine is running, you can now SSH inside it from your terminal.

$ ssh -p 8022 vmusername@127.0.0.1

That’s it! You are now free of the VirtualBox gui environnement, while using your VM environnement in a fast and efficient way.

Install 16bit windows software (.exe) on linux

I recently bought a book about Microcontrollers. It’s the kind of costly educational book that comes with a CD inside.

Even if it’s the latest edition of the book, the CD was made for Windows 98. It’s a 32bit application so it should work properly on Windows 7 or 8. Well, no.

It happens that the installation package (executable setup file) from the CD is a 16bit installation package. Windows 7 and 8 are not supporting 16bit applications anymore.

Linux saves the day! I installed an application called “wine” which is available from Ubuntu’s repositories. You can get it from source too: http://www.winehq.org/

When installed, put the CD in your laptop, and double click on your 16bit executable file.

Results may vary depending on what you are installing, but I was lucky enough that everything worked without any issues, and now I can run this windows application directly on linux.

This is the application that was on the CD: http://midnightdesignsolutions.com/hc908/win_ide.html

The book: http://www.amazon.ca/Microcontroller-Theory-Applications-HC12-Edition/dp/0136152058

My Dual Boot Setup (Windows 8 Pro & Ubuntu 14.04 LTS)

My laptop is dualbooting Windows 8 Pro and Ubuntu 14.04 LTS using grub. The two OS are also sharing common directories for pictures and music. Here’s my setup. I am not responsible for the risks you will take with partition management. Also read every steps before making changes, and make sure that you will have enough disk space for everything. Also note that you cannot directly share Windows libraries with Linux /home libraries. In this example, I create a common partition to share a single music directory, so that Windows Media Player and Rythmbox use the same music library.

  • Install Windows 8 first and do the following steps before installing Linux. I won’t explain how to partition everything, but I used about half of my 256GB hard drive for Windows C:. Installing Windows before Linux will save you some headaches.
  • Turn off Windows 8’s “Fast Startup”. Disabeling this hidden option makes Windows use a regular cold boot, like previous version of Windows. Windows 8 uses a new hybrid boot process that makes booting faster, but it will give you a headache trying to use Grub for dual-booting. Note that disabeling “Fast Startup” will actually slow down the boot process a little bit. I don’t really care since I use a SSD.
    • Go to Control Panel
    • Open Power Options
    • Click on “Choose what the power butons do” on the left
    • Click on “Change settings that are currently unavailable”
    • Scroll down and uncheck “Turn on fast startup (recommended)”
  • Now you can install Ubuntu 14.04 LTS or any other Linux distro painlessly with grub as the boot loader. Windows should be detected and added to grub automatically.
    • I created a boot, swap, root and ntfs extended partitions while installing linux. Make sure not to touch the ntfs partitions created by Windows. See the following partition scheme as an example:
      • sda1 & sda2: Windows (128GB total)
      • sda3: Extended partition (remaining space 114GB)
        • sda5: ext2 /boot (256MB)
        • sda6: swap (2GB)
        • sda7: btrfs / (40GB)
        • sda8: ntfs /windows (Remaining space, around 85GB)
    • Nope, you cannot set /home in a ntfs partition, I leave it inside root. You are free to do things differently!
    • Make sure you have enough space in the new /windows ntfs directory for everything you want to share between Windows and Ubuntu.
  • When Linux is installed, make sure dual-booting is working as expected. Then, boot in Windows, and move the directories you want to share with Linux in the newly created ntfs partition (probably in D:). In the new ntfs partition, I created a music and a picture directory. Then:
    • Right click on Windows Music folder from the file manager
    • Click on Properties
    • Click on “Location” tab
    • Choose the new Music directory in the new ntfs partition (Probably on D:)
    • Agree to move all the files to the new directory. Make sure you have enough space!
    • Repeat the process for the other folders you want to share.

You are now sharing a common partition between Windows and Ubuntu. I find it useful that Windows Media Player and Rythmbox share the same directory for their music libraires. It prevent useless duplication and saves some space. You can do the same thing with your pictures and documents too. It’s a way to stay organised and save space on a dual-booting system. Note that you can’t directly share your linux /home directory with Windows’s directories. For example, you cannot set Windows “Music” library to be the same as Linux’s “/home/music” library. I would be happy to learn that I’m wrong though.

I noticed that /windows directory in linux won’t mount upon startup if windows is hibernated. This is a good thing, because if you add files to the directory from linux, and resume windows, the files will be lost.