Friday, April 8, 2016

Exploring Linux Kernel with Virtualbox - Part 1 - The environment setup

Finally few experiments is about to fire with Linux Kernel. I am sharing those learning curve with a blog-post to invite readers for feedback. I have setup virtualbox to debug linux kernel and it has been fun so far. I want to make it more interesting by debugging/exploring major functionalities of linux kernel. Here is my initial start to this festival and I hope it will last long!

For all the demotivators, stop right here and read:

There are humongous online references and in form of printed text. So why is this juggling required ?

You know! experiences ingrain to brain more than reading theory. When you dont have such related work in your office, you buy those experiences by motivating yourself!

It's just beginning with exploration towards networking aspect of kernel. Hope I will come up with various other parts of linux not limited to networking.

The initial few sessions concentrate on bringing up setup and a tiny debug session.

My setup

Host: Ubuntu x86_64
Guest 1: Ubuntu i686
Guest 2: Ubuntu i686 (As of now not much in use. Primarily used to simulate network forwarding)

What you need in Host OS?

a) VirtualBox
b) VirtualboxGuestAdditions
c) Ubuntu i686 ISO (from Ubuntu site)

Install above utils with

sudo apt-get install virtualbox virtualbox-guest-additions-iso

Once installed, it is time to create virtual machine. I am not elaborating the process involved since lots of tutorials point at this procedure. Here are the steps leading to installation of guest OS.

Creating a virtual network

Create a Host only adapter Network interface under File-->Preferences-->Network.

Here I have added vboxnet1 as well but it is not required as of now.

Edit the settings (as shown in figure below) of added interface and disable the DHCP server and assign a manual address of your choice.

Choosing RAM size

I have healthy 16GB of RAM and hence chose 2GB for my VM. You can choose appropriate size that fits to your actual physical memory or choose size recommended by virtualbox.

Choosing disk space

Make sure to give at-least 24GB of disk space to accommodate guest OS. I prefer fixed size since we will not do much installation other than linux kernel. VDI image was chosen for storing VM disk. I have not experimented with other formats. If you wish to inter operate with other VMs, you can chose other formats.


Networking between host & guest

After VM is created, click on created VM and click on Machine Settings in Toolbar.

Note: There are two types of settings

(i) Global Settings which is applicable to all VMs
(ii) Per VM settings which refers to VM specific settings.

When I refer as "Machine Settings" it means VM specific settings.

Enable Adapter1 as NAT for connecting towards Internet.

Note: If Internet requires proxy, the proxy has to be set inside guest OS.

Enable another Host-only adapter interface and choose already created interface in Creating Virtuan Network section

Enable clipboard sharing

This is very important if you need to work with clipboard data between host & guest (copy & paste)

Goto Machine Settings-->General-->Advanced, choose "Bidirectional" for both parameters as shown below.

Enable file sharing

This enables you to share files between host & guest. To make use of this functionality, Goto Machine Settings-->Shared Folders and add a folder of your choice.

Installing OS

Boot the machine and it will guide you do browse for virtual boot disk. At that time, point to ISO file downloaded for installation. Make sure to disable downloading updates from internet.

The installation is like any other linux OS. The only recommendation from me is to have custom partitions as below.

(i) Dedicated /home partition for kernel compilation (about 14GB)
(ii) Dedicated / partition for installing new kernel (about 8GB)
(iii) Rest 2GB can be for swap

Note: The below picture is just an illustration and does not conform to the above mentioned parameters

Installing Guest Additions

Once installation is completed, first step is to Install guest additions on guest OS. But I prefer to defer this step for the moment. Why? Soon the secret will be unfolded ;).

Once the guest OS is booted, first and foremost, download the kernel source.

sudo apt-get install linux-source

This will be place /usr/src directory as compressed bz2 file.

Create a directory in /home/<user>/ say name "kernel" and copy the bz2 file to that directory. Once done extract the kernel source. Below file name is just for illustration. It could be something else in your native system.

tar -xf linux-source-4.2.0.tar.bz2

Now the system is ready for kernel game and we are ready to cheer! The sequel will be explained in subsequent blog post.

No comments:

Post a Comment