Wednesday, September 3, 2008

Ubuntu compile your installed kernel howto

I have often the need to build some driver (like a VMWare network driver) against the installed kernel headers. To do this you need to do a bit of work on Ubuntu before the driver will compile:

# Get to the right location and ensure your current kernel 
# headers are installed.
$ cd /usr/src$ uname -r2.6.24-19-generic

# so in my case I need the 2.6.24.-19 headers.
$ sudo aptitude install linux-source linux-headers-2.6.24-19 \
                        kernel-package libncurses5-dev

# unpack sources and link them, ensuring that /usr/src/linux
# points to the source tree.
$ sudo ln -s /usr/src/linux-source-2.6.24 linux

# create the .config in your headers directory.
$ cd linux
$ sudo cp /boot/config-2.6.24-19-generic .config

# now we can make the build of our kernel.
$ make && make modules

# after this is finished I am able to build my VMWare
# driver by pointing it to the /usr/src/linux tree.
# note that I do not install the kernel, just create the
# necessary files to build drivers.