Monthly Archives: May 2014

Linux kernel compilation notes

DISCLAIMER: This is just what the name says, notes. This is not official guide.

Kernel compilation involves the following:

  1. Obtaining source
  2. Installing essential packages for kernel compilation
  3. Configuring
  4. Compiling and Installing

   The procedure varies from distro to distro. I will go through steps for a general compilation with distro specific notes added.

1. Obtaining source

   Linux kernel source is available from kernel’s homepage https://www.kernel.org/. Some distro specific commands are as follows:

  • Gentoo linux: emerge gentoo-sources
  • Debian linux: apt-get source linux
  • Ubuntu linux: apt-get source linux-image-$(uname -r)

   It’s usually recommended (even by Linus, I guess) to extract the source to user’s home under a directory say, kernel ($HOME/kernel/). But on Gentoo and Slackware, we usually extract to /usr/src/ and configured, compiled and installed as root. I’m usually on Gentoo or Slackware. Never bothered to ask the folks why they do it the way that’s frowned upon. It works. So be it.

2. Installing essential packages

   At a minimum we need gcc. Depending on distro we may need other packages as well. For eg., in Debian we need, fakeroot, kernel-package, linux-sources, libncurses5-dev and build-essential. Since in Gentoo everything is compiled and in Slackware recommended install method is to choose ‘full’ all necessary softwares are already present.

3. Configuring

   For generic compilation, we can start with,
   make mrproper (this was two step in v2.4 kernel as “make dep; make clean“)

   Above step is not essential but when executed cleans-up source and deletes any customization including deleting .config file. So don’t forget to backup a working .config file.

   Then if we already have a working .config file we can use it as safe point or for upgrade.
   make oldconfig

   Actual configuration is started with any of the following commands:

  • make config – text based question and answer type, very minimal, best suited for ultra geeks 🙂
  • make menuconfig – menu driven, ncurses based method, good on any desktop or no desktop. This needs libncurses package
  • make xconfig – graphical method, Qt based, best fits on KDE desktop
  • make gconfig – graphical method, GTK based, best fits on GTK based desktops (GNOME, XFCE).

4. Compiling and Installing

   Compiling is done with just one command:
   make

This is (now) equivalent of ‘make all’ and ‘make bzImage modules vmlinux’ where,

  • vmlinux – uncompressed linux kernel
  • bzImage – compressed linux
  • modules – any modules compiled.

   This will compile linux kernel and create a bzImage under arch/x86/boot/ (assuming we are compiling for x86 or x86_64 platform). We can copy this bzImage file to /boot and update the bootloader. The other method is to run
   make install

   This will install/copy the following to /boot

  • bzImage as vmlinuz-x.y.z
  • .config as config-x.y.z
  • System.map as System.map-x.y.z

   Here,

  • x-major linux version,
  • y-minor version (odd number being development version and even number being stable version) and
  • z-patch version

   If we have configured some features as modules, we can do
   make modules_install

   This will install/copy all the modules to /lib/modules/<kernel-version>/ directory.

   We can then update our bootloaders and reboot. If all has been done right we will have a working system with new kernel. If not necessary troubleshooting has to be done.

   Now we will examine kernel compilation specific to distros.

A) Debian way
   Debian way is to create a .deb package for kernel and modules which can then be installed (and maintained) with dpkg. As mentioned before, configuring and compiling as root is discouraged. Only time root is used is to actually install the new kernel and modules. Debian uses a method called ‘fakeroot’ for this purpose. This simulates the root user. Another script called make-kpkg is used which automates make dep; make clean (or make mrproper), make bzImage, make modules etc.

   The format for make-kpkg is “make-kpkg <options> <target>” where target is kernel image usually called kernel_image. Options include,
–initrd : asking to create an initrd
–append-to-version : our name; avoid generic names like 686, x86, amd64 etc which are usually reserved by distro packaging
–revision : how many times compiled/recreated? changes package name not kernel.

   So, the Debian way will be something like this:

   $ make-kpkg clean : equivalent of make mrproper and perhaps similarly not mandatory.
   $ fakeroot make-kpkg --initrd --revision=custom.1.0 kernel_image

   This step will create .deb packages which can be installed with dpkg.
   # dpkg -i *.deb

B) Ubuntu way
   We obtain kernel source with the following command. However note that we need to execute the following as normal user. Otherwise we will not be able to use fakeroot.
   $ apt-get source linux-image-$(uname -r)

   The necessary packages required for a kernel compilation can be installed in Ubuntu as follows:
   $ sudo apt-get build-dep linux-image-$(uname -r)

   Now do the following:
   $ chmod a+x debian/scripts/*
  $ chmod a+x debian/scripts/misc/*
  $ fakeroot debian/rules clean
  $ fakeroot debian/rules editconfigs

   To build kernel, cd to the root of the kernel source tree
   $ fakeroot debian/rules clean
   $ fakeroot debian/rules binary-headers binary-generic

   If build is successful there will be three deb files above the build root directory.
   $ cd ..
   $ ls *.deb
   $ linux-headers-$(uname -r)_all.deb linux-headers-$(uname -r)_amd64.deb linux-image-$(uname -r)_amd64.deb

Install the kernel with dpkg
   $ sudo dpkg -i linux-*.deb

Advertisements

Minimal ‘wpa_supplicant.conf’ entry for WPA2 connection

I always keep forgetting the entry in wpa_supplicant.conf. So here it is.

#ctrl_interface=/var/run/wpa_supplicant
#ctrl_interface_group=wheel
#OR
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel
#ap_scan=1
#update_config=1
network={
ssid="NameOfSSID"
scan_ssid=1
proto=WPA2
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="password or output of wpa_passphrase here"
}

“Broken sem_open function (bug 496328)” error when compiling python_2.7:

I have installed Gentoo on a Thinkpad T42 laptop. I have problem setting up wireless network but that is for another day. This blog is related to problem I faced during my system upgrade.

When I tried to do system upgrade, python emerge failed with following error message: ‘”Broken sem_open function (bug 496328)” error when compiling python_2.7:’. There were instructions to –rbind /dev from live media. But I had done it. There were instructions to remount /dev/shm on tmpfs and with mode=1777 permission. But trying to mount failed with no such file/directory error. Then I noticed something.

Since, network is not working (currently) on my Gentoo installation, I chroot from linuxmint on this office laptop and do all installtion/upgradation. Mint has /dev/shm pointing to /run/shm which was empty i.e., there is nothing under /run.

I removed /dev/shm link, created a directory /dev/shm and mounted as tmpfs with 777 permission. After this, python emerge went smoothly.

(chroot) mint-t42 / # rm /dev/shm
(chroot) mint-t42 / # mkdir /dev/shm
(chroot) mint-t42 / # mount -t tmpfs -o rw,mode=1777 shm /dev/shm
(chroot) mint-t42 / # ls -l /dev/ | grep -i shm
drwxrwxrwt 2 root root 40 May 25 11:26 shm
(chroot) mint-t42 / # df -h
df: '/sys/fs/cgroup/openrc': No such file or directory
df: '/sys/fs/cgroup/cpuset': No such file or directory
df: '/sys/fs/cgroup/cpu': No such file or directory
df: '/sys/fs/cgroup/cpuacct': No such file or directory
df: '/sys/fs/cgroup/freezer': No such file or directory
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 21G 4.8G 15G 25% /
tmpfs 21G 4.8G 15G 25% /run
udev 10M 0 10M 0% /dev
cgroup_root 4.0K 0 4.0K 0% /sys/fs/cgroup
shm 759M 0 759M 0% /dev/shm
(chroot) mint-t42 / # mount | grep -i shm
shm on /dev/shm type tmpfs (rw,mode=1777)
(chroot) mint-t42 / #

I don’t know how clean the method is but what I tried worked for me. Once I get network working in Gentoo, I don’t have to chroot anyway.

It’s Gentoo season…

I don’t know why, but suddenly I have fallen (madly) in love with Gentoo/Linux. I just completed the process of replacing existing linux on all my computers with Gentoo, except the one used by family. So, most of my next blog entries will be related to my experiences with Gentoo.

All but one of them are running OpenRC. I am running systemd on one, just so I am aware of the technology. So far, both systems are running smoothly. Once I’m more experienced, I will switch to testing branch.

I’m not new to Gentoo but it never stayed for long on a distro-hopper’s computer. Till the season changes again…he we go…or…may be we will end up being pair for life…who knows?! 🙂

Use MDM instead of GDM in openSUSE 13.1

I installed Cinnamon on openSUSE 13.1 installation. I wanted to install MDM instead of GDM. Usual method with systemd systems is ‘systemctl enable *dm.service’. However, I could not find any gdm.service file to disable and any mdm.service to enable.

With some fiddling found there is a graphical.target file which ‘Wants’ display-manager.service. I could not find any such file. However, ‘systemctl status display-manager.service’ showed it is loading /etc/init.d/xdm. Which inturn mentioned that it will execute ‘/etc/sysconfig/displaymanager’. Duh

Changing “DISPLAYMANAGER=gdm” to “DISPLAYMANAGER=mdm” now starts MDM instead of GDM. Issue solved for me. Don’t know if there are any cleaner way of doing it.

However, there is only one MDM theme which is old and I could not find any mdm-themes package to install in openSUSE. It’s okay. I don’t have to deal with ‘raising the curtains’ shit of GDM lockscreen and I’ll not be bored with the (you shall not change) grey GDM theme anymore. 😉