install linux as a virtual machine

This post is a one stop reference for all steps that need to be followed to install Linux as a Virtual Machine (guest) on another Operating System (host), using a hypervisor program (VM player). There is no need to download a precompiled Virtual Disk Image; we can create our own through the hypervisor program itself.

In this example, the guest OS is Ubuntu 14.04 LTS 64bit, and host OS is Windows 7 64bit. The hypervisor program used is Oracle VirtualBox.

1. Install VirtualBox
Install VirtualBox (latest) after downloading from here. Since our host is Windows 7 64bit, the one of interest is for Windows host and 64bit. This is approximately 100MB.

2. Download Linux ISO
Download the standard ISO image of Ubuntu Linux 14.04 LTS 64bit from here. This is approximately 1GB.

3. Create VM
a. Open VirtualBox and click on ‘New’ to create a VM. Give a name like ‘Ubuntu1404’. The other choices automatically select Linux and assume 64bit, which is what we want. For other architecture, change it.

b. Next, select 1GB of RAM to be used by this VM. With all the fuss about new GNOME and Unity desktops, 1GB is a good balance. Since our host is Windows 64bit, we can safely assume we have at least 4GB RAM. Otherwise, it is more prudent to install the OS as a dual boot rather than running as VM in the first place. For 32bit guest, 512MB RAM should suffice.

c. Next, select ‘Create a virtual hard drive’. The recommended size is 8GB; spare a couple more if possible to make it 10. This is not required, but just gives us some extra space in case of a large download or installing lots of packages.

d. In the next two screens, select VDI (default), and ‘dynamically allocated’ so that 10GB is consumed only when required, until then it is available for host to use. ‘Fixed size’ will also do, in which case entire 10GB will be unavailable at once to the host system.

e. Next steps will ask for the ISO image to install the OS on that virtual hard drive. Point the location of ISO image to where downloaded in step 2, then the install steps are as straightforward as if we are doing everything on a single isolated hard drive of another computer. So in most cases, the first option in the installer of ‘erase everything’ will do just fine. For more assurance, select ‘custom’, confirm that the only hard drive visible is the virtual one, and set the root mount point (‘/’) to it. The bootloader will have automatically selected the virtual drive. All these, because the host drive is not visible to the installer, thus there is no way to mess it up.

f. After installation, the VM is created for use. Restart the VM if prompted, and it will boot into Ubuntu Desktop. The VM will be displayed on a separate window of its own, and VBOX will run on another ‘main’ window. Now we can perform some necessary adjustments.

4. Install Guest Additions
Start the VM by clicking on ‘Show’ (if not running). It will prompt about some shortcuts that can be used to shift focus out of the guest into the host. Make a note of them. Once the deskotop has come up, go to the VBOX menu (on the window displaying the VM, not the main VBOX application) by using the appropriate shortcut. In Devices menu, click on ‘Install Guest Additions CD Image’. This will mount the VBOXGuestAdditions.iso as a media and open a terminal, on which, the extra packages will be installed automatically. This comes with VirtualBox, and contains extra features like:
a. Mouse pointer integration
b. Shared folders
c. Support for desktop resolutions higher than 640×480
d. Seamless windows
e. Generic host/guest communication channels
f. Time synchronization
g. Shared clipboard
h. Automated logons (credentials passing)

Most of them are very useful, so no point in holding from installing the extra packages for them. Once the guest additions are installed, restart the VM, and immediately we can see a change in screen resolution towards better. Also, mouse integration is now seamless, i.e. we no longer need to provide any shortcut to shift focus, simply moving the mouse will do.

Other benefits can be availed by changing some ‘Settings’ (Gear icon on the VBOX main window, or Machine > Settings menu on the VM window) like
In General > Advanced, select ‘Bidirectional’ for clipboard sharing.
In Display > Video, set the VRAM to 128MB (max allowed).
In Network > Adapter 1 > Attached to, check that ‘NAT’ is selected.
For more information, refer the documentation.

Note: The guest additions that come with VirtualBox may not be the right one for the guest OS version being installed. This may affect some features. In my case, the ‘Switch to Seamless Mode (Host + L)’ and ‘Auto-resize Guest Display (Host + G)’ were found to be not working after I installed the guest additions as mentioned above (i.e. from Devices menu). In order to bypass this problem, pull the right guest additions from the Ubuntu repository:

sudo apt-get install virtualbox-guest-x11

This will download the guest additions specific to the guest OS version. This is only about 2 MB of additional download over the one installed through VirtualBox.

5. [Optional] Proxy settings for VM
If behind a proxy, set the proxy settings to be used to connect from the VM (shut it down first):
a. In VBOX main application, select File > Preferences > Proxy. Set the proxy server (ex. http : // myproxyserver . com) and port (say 80), in the fields provided.
b. In VM, programs like apt-get, Node npm, Python pypi etc. require separate proxy settings. Else, with the previous step, only the browser will be able to connect from VM and these will not work. Each of these programs have their own proxy configuration setting; lets set for the one to be most frequently used, apt:

$ sudo gedit /etc/apt/apt.conf.d/01proxy

The ’01proxy’ file will not exist at first, so we create it thus. Then add the below line to it:

Acquire::http::Proxy "http://myproxyserver.com:80";

Save the file, and test apt-get:

$ sudo apt-get update

For other programs, set proxy in their individual config locations, like global/ local config list for npm, etc.

Now the VM will be fully usable as a virtual computer inside Windows, that has 10GB HDD and 1GB RAM.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s