Friday, May 27, 2011

GSoC Welcome Package

Just now received my Welcome package from Google. I am overjoyed and couldn't stop looking at it, so sharing the pics of the things I received:

The Citi Bank Prepaid Card:

My Precioussss ;-)

The GSoC Notebook, Pen and the Sticker

The Welcome Letter from Google:

Yaay!! I am happy :)

Sunday, May 22, 2011

Problem No. 1: Building MANPATH

I am starting a series of posts to discuss about the interesting problems that I will be facing in my project and my views on how to solve them. For those who don't know about my project for GSoC 2011 for NetBSD please see my project page [1].

The very Ist problem that I need to solve is finding the MANPATH. MANPATH is an environment variable which tells us the directories where man pages are stored. I need it because the very first thing my project needs to do is to parse all the man pages and build an index, but it won't be possible unless it knows the different directories where man pages might be stored.

Very often is the case that MANPATH is not defined in the system. In such scenario I need to fallback on a mechanism which will build the manpath for me. Following is the strategy that I have thought for solving this:

Following is the strategy that I have thought of implementing:

makewhatis: Will be responsible for constructing the database from scratch, parsing each man page using libmandoc. For this it will need to know the locations of the man pages. I propose using /etc/apropos.conf as the default place to look for the manpath.

/etc/apropos.conf: For now, I believe it should store the path where man pages are stored. It might contain other information in future.

manpathbuilder: In case /etc/apropos.conf does not contain a definition for manpath or it has been removed, makewhatis will call manpathbuilder. It will build the manpath by parsing information from /etc/man.conf. Once the manpath is built it will be stored in /etc/apropos.conf and control returned to makewhatis which can recheck /etc/apropos.conf (or maybe manpathbuilder return the manpath to makewhatis directly ?)

Why /etc/apropos.conf ? Well it takes some time to build the path containing all possible directories (/usr/share/man/man1, /usr/share/man/man2, ... , /usr/X11R7/man/man1, ... , etc) and the current code of manpathbuilder is also not very efficient, so it makes sense that once we have built the manpath we make it persistent for future uses and only redo the work when it is actually needed.

I have written most of the code for manpathbuilder, although it is highly inefficient from memory or runtime point of view, but it seems to work. I will improve it as I get some more time (struggling with exams at the moment).

UPDATE: I discussed with Joerg about the outline I have drafted above. We reached to a better alternative. He suggested that rather than writing an additional utility manpathbuilder and an extra config file (/etc/apropos.conf), we could add a new option to man(1) by patching it. This will provide us the complete manpath and also will serve as an easy point of access to let the end user to see if anything is wrong with the path. 

So in the coming days, I will be working on patching man(1) to add a new option which will give the list of directories where man pages are stored (like /usr/share/man/man1:/usr/share/man/man2,...) 

The simplified outline


Sunday, May 15, 2011

Making NetBSD dual boot with Linux

The day I decided that I am going to submit a  proposal for NetBSD for GSoC 2011, I installed it on one of my primary hard disk partitions to give it a try and have more solid understanding of the platform before I start to write my proposal. Installing NetBSD is a very easy thing to do, and the NetBSD guide [1] does a great job explaining the whole installation process in a very detailed manner.

However, It's not easy to just switch to a new OS all of a sudden, so I wanted to setup a dual boot system alongside with my existing Linux. Although the NetBSD guide does mention about setting up dual boot systems but it didn't discuss about the possible caveats that may crop up in the process, and as it turns out, setting up a dual boot of NetBSD + Linux can be a tough nut to crack for the newbies.

So, here I am writing this blog post after having fixed the problem. I hope this post will be useful for me in the future and to others who may also come across this not so rare problem. 

The following guide assumes that you already have Linux installed on one of your partitions and you are installing NetBSD.

In the NetBSD partition manager screen where you need to select the partition to install NetBSD, let the 'd' and 'a' flags remain with the Linux partition and set the 'I' flag only for the NetBSD partition. 

Do not install the NetBSD boot loader when sysinst (the NetBSD install program) prompts you to while installing NetBSD.
Don't install the NetBSD bootcode in MBR

After the installation of NetBSD finishes and you reboot, you will be directly booted into Linux (no surprises here), because we did not install the NetBSD boot loader in the MBR and GRUB didn't know about the existence of NetBSD so it directly booted Linux. Our next step will be to tell GRUB about NetBSD so that from the next time onwards it will give us a choice between NetBSD and Linux.

Note: These instructions are for GRUB2

  • Create a file 06_netbsd in /etc/grub.d/ and write the following script in it to chain load the NetBSD boot loader:

#!/bin/sh -e
echo "Adding NetBSD 5.1 on sda1 to GRUB 2 menu"
cat << EOF
menuentry "NetBSD 5.1 on sda1" {
insmod bsd
set root=(hd0,1)
chainloader (hd0,1)+1
This script assumes that you have installed NetBSD in the Ist partition of your first hard disk. GRUB2 counts hard disks from 0 but partitions from 1, thus we have (hd0,1). If for example you had NetBSD in the 3rd partition, you would use (hd0,3).
  • Make this script executable by the following command:
$sudo chmod a+x 06_netbsd
  • After this, we need to tweak another file. Run the following commands:

 $sudo gedit /etc/default/grub 

  • In this file you need to comment out the line saying: 


To comment it out, simply put a # in front of this line in the file and save it.

  • Now we need to run the 'update-grub' command and we are done. After running 'update-grub' , GRUB2 will add menu entry for NetBSD in it's configuration file (boot.cfg) and the next time you boot, you will be presented with the options to boot either into NetBSD or Linux.

For those using GRUB (not GRUB2), I believe they can simply add the menu entry in the menu.lst file and it should be ok (I am not sure, as I did not try). Also GRUB used to count partition numbers from 0, so if you had installed NetBSD in the Ist partition you would use (hd0,0)

In the end I would like to say that, these are my personal notes and might be opinionated at some points. I am pretty sure there must be other ways of doing it even from NetBSD. This method worked for me the best.

Monday, May 2, 2011

The Start of a Dream

I know I've been very late in posting this blog entry, but nevertheless I am here. So finally my proposal for The NetBSD Foundation has been accepted as part of Google Summer of Code 2011[1]. I am in an extremely excited and elated state of mind since the time I got to hear this news. I must say this is an all time high point of my student life. When I posted this news on Facebook, Kinshuk Sunil pointed out that "it is not a dream come true, but the start of a dream" and it really is a start of a dream for me. I am more positive and confident than ever.

I had set this as a target for me to become an open source contributor and participate in Summer of Code. It took me a lot of hard work and time to achieve this but it's worth it. I wanted to participate even during the previous years of SoC but to be honest, I didn't have enough courage and guidance around me to be able to do it. 

And more than anything else, I am very happy to make my parents proud after so many years of constant hard work they have put and sacrifices they have made to send me to school to chase my dream of becoming a software developer. I hope it's the first of many more proud moments that I will be giving to them in the future.

I must thank all the mentors and admins of The NetBSD Foundation as they have been very kind and helpful, usually it's very hard for someone like me who has very little experience with a BSD operating system to be accepted, but they showed trust and confidence in me. This will encourage me to make extra efforts to make this project successful and become a long time contributor.

I will write more about my project and NetBSD in the upcoming blog posts. So wait for it... :)