## blog @ bjerck.net

#### Compiling an upstream kernel on ubuntu.

by: tom
##### Introduction

After downloading the source from kernel.org or any of the mirrors, you have at least two options for how to compile the source for a ubuntu system. First you can just do it the traditional way and just use the Makefile that comes with the source directly. A second and more convenient and safer way to do this is to make a deb package, and let apt handle the installation and later eventually the removal of the kernel when it is no longer needed. Also making a deb will make sure that any installation scripts in the /etc/kernel directory is executed. These scripts currently updates the initramfs image, updates grub config and recompiles any third party modules. These scripts can not be part of the kernel package since they are dependent of the target system.

##### Compiling using the make deb-pkg target in the Linux kernel source Makefile

I didn't know this until recently, but the kernel Makefile has a deb-pkg target. It's the functionality used for compiling a new kernel documented in the Debian Kernel Handbook chapter 4. Se the scripts/package/builddeb file in the Linux source to see what this build target does. If you have a multi core cpu, you may use make's -j<num jobs> option, to speed things up.

##### Compiling using kernel-package

You should install the following packages:
kernel-package fakeroot build-essential

###### Relevant documentation:

man make-kpkg
man kernel-package
man make
Debian Kernel Handbook
wiki.ubuntu.com/KernelTeam/GitKernelBuild
/usr/share/doc/kernel-package/README.gz
/usr/share/doc/kernel-package/Kernel.htm
man gpg
man wget
www.kernel.org/signature.html
kernelnewbies.org/FAQ/KernelCompilation

###### Versions

There are three version labels:

1. The stable upstream kernel versions at kernel.org whose format are three numbers separated by dots, like 3.4.6.
2. The deb package of the kernel has it's own version; usually composed of the upstream version numbers and local revision numbers.
3. Then there is a third versioning labeling the locally configured and compiled kernel. This version number is the output of uname -r.
The last version label mentioned above is used to name the Linux kernel image file, and also to name the directory where it's modules are installed under /lib/modules. It's important that these names are unique for each new kernel installed on the system in order to have binary compatibility between the kernel image and it's modules and prevent previously installed kernels and modules from being overwritten.

In the following I'll download and unpack the source code for the 3.4.6 version of the upstream Linux kernel. I'll also download the gpg signature file and use it to verify the download. Using wget:
wget "https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.4.6.tar.xz"
wget "https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.4.6.tar.sign"
The compressed tar file needs to be decompressed before gpg verification:
xz -d "linux-3.4.6.tar.xz"
Use gpg to verify:
gpg --verify "linux-3.4.6.tar.sign"
If you get an error message about a missing key, you need to import the signing key from a keyserver:
gpg --recv-keys <key id>
And then run the gpg verify command again. You should then get a message proclaming "Good signature". If you get a message stating "Bad signature" something is wrong. If this step goes well, continue and untar the archive:
tar xf "linux-3.4.6.tar"
This should extract a directory named linux-3.4.6. Make this your working directory:
cd linux-3.4.6

###### Configure the kernel

You now need to configure the kernel. If you want base the new configuration on the old config that was used when building your currently running kernel, you just copy it from the /boot directory like this:
cp /boot/config-$(uname -r) .config The new kernel will likely have new configuration options not present in the config for the old kernel. Therefore you now need to run one of the several utilities supplied with the kernel source for editing the configuration. For a terminal user interface you can use menuconfig which you start by giving the command make menuconfig in the root directory of the source. ###### Use make-kpkg to compile the source created: 2012-07-20 15:38:14. Permalink #### Lenovo Thinkpad Edge S430 on Linux - First impressions by: tom A few days ago I received my new Thinkpad Edge S430, and so far I'm satisfied with it. I've upgraded to 16GB memory, and changed to a 128GB ssd from Samsung (830 series 2.5"). If you plan on buying one of these laptops and install a ssd, you should know that it needs to have a maximum height of 7mm to fit. And remember to enable TRIM with the "discard" mount option in /etc/fstab. This was not done automaticalle by the Ubuntu installer. The system seems really fast and responsive with Ubuntu. (This is with 16GB memory and the Samsung ssd; I never ran Ubuntu with the original configuration.) Pros: • Low weight. (1.8kg) • Good screen resolution (1600x900) • Low price. • Anti Glare • Comfortable keyboard • Aesthetics Cons: • Battery won't last more that 3½ - 4 hours with max backlight, general browsing and writing code in vim. And you will want to use max backlight in daylight. According to Lenovo the screen brightness is 250 nits. • TN LCD means low viewing angles. But what can you expect at this price? • The lid is a bit flexible. ###### Ubuntu 12.04 Installation of Ubuntu 12.04 went smoothly. Everything works; most notably WiFi, suspend and keyboard keys for backlight brightness, the thinklight, volume and media keys. However, I have not tested the dvd drive, fingerprint reader, thunderbolt, nor the hdmi port. There have been some stability issues where the system freezes completely every few hours, and there is nothing else to do than force a cold reboot using the power button. This seems to be an issue with Ivy Bridge: [IVB]12.04 64 bit System freezes (mouse, keyboard). A new kernel is in "proposed" which purportedly solves the freezes, and should be released within the next week. However I'm not patient enough to wait for that, so I've compiled and installed the latest stable release from kernel.org (3.4.6). This version is rock solid. ###### nVidia Optimus This laptop has a graphics chip from nVidia in addition to the integrated chip in the Intel Core i5 CPU. nVidia Optimus technology is used on Windows to switch this chip on and off automatically to save battery. nVidia has not supported this functionality on Linux, something everybody should know by now after a Finnish student asked Linus Torvalds about his views on nVidias lack of support to open source developers for this crucial functionality which doesn't exist in their binary drivers, and he replied that nVidia was the singel worst company they had ever worked with. Se Phoronix article and nVidias response. The BIOS has a choice between integrated graphics and nVidia Optimus. Since I don't want the nVidia chip to be switched on and draw battery, and because of the lack of Linux support I disabled the nVidia Optimus chip in BIOS before installing Ubuntu. There is of course the Bumblebee project: http://bumblebee-project.org/. ###### Output from lscpi tom@edge:~$ lspci
00:00.0 Host bridge: Intel Corporation Ivy Bridge DRAM Controller (rev 09)
00:02.0 VGA compatible controller: Intel Corporation Ivy Bridge Graphics Controller (rev 09)
00:14.0 USB controller: Intel Corporation Panther Point USB xHCI Host Controller (rev 04)
00:16.0 Communication controller: Intel Corporation Panther Point MEI Controller #1 (rev 04)
00:1a.0 USB controller: Intel Corporation Panther Point USB Enhanced Host Controller #2 (rev 04)
00:1b.0 Audio device: Intel Corporation Panther Point High Definition Audio Controller (rev 04)
00:1c.0 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 1 (rev c4)
00:1c.1 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 2 (rev c4)
00:1c.3 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 4 (rev c4)
00:1c.4 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 5 (rev c4)
00:1d.0 USB controller: Intel Corporation Panther Point USB Enhanced Host Controller #1 (rev 04)
00:1f.0 ISA bridge: Intel Corporation Panther Point LPC Controller (rev 04)
00:1f.2 SATA controller: Intel Corporation Panther Point 6 port SATA Controller [AHCI mode] (rev 04)
00:1f.3 SMBus: Intel Corporation Panther Point SMBus Controller (rev 04)
02:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. Device 5229 (rev 01)
03:00.0 Network controller: Intel Corporation Centrino Wireless-N 2230 (rev c4)
04:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 07)


Relevant man pages are xinput, evdev and synaptics. I used xinput --list to find the names of the trackpad and trackpoint:

tom@edge:~$xinput --list ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ SynPS/2 Synaptics TouchPad id=11 [slave pointer (2)] ⎜ ↳ TPPS/2 IBM TrackPoint id=12 [slave pointer (2)] ⎣ Virtual core keyboard id=3 [master keyboard (2)] ↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)] ↳ Power Button id=6 [slave keyboard (3)] ↳ Video Bus id=7 [slave keyboard (3)] ↳ Power Button id=8 [slave keyboard (3)] ↳ Integrated Camera id=9 [slave keyboard (3)] ↳ AT Translated Set 2 keyboard id=10 [slave keyboard (3)] ↳ ThinkPad Extra Buttons id=13 [slave keyboard (3)]  As can be seen, the relevant names are SynPS/2 Synaptics TouchPad and TPPS/2 IBM TrackPoint To turn the trackpad off, issue this command: xinput --set-prop --type=int "SynPS/2 Synaptics TouchPad" "Synaptics Off" 1 By default the middle button of the trackpoint has a wheel emulation timeout of 200 milliseconds. This means that the driver issues a click event if the time between press and release is less than this value. If the time is larger, it issues scrolling events when used in combination with the trackpoint. This is really nice, but 200ms is too short for me, and I find it really difficult to issue clicks with this timeout. To increase this, issue the following command (on a single line): xinput --set-prop --type=int "TPPS/2 IBM TrackPoint" "Evdev Wheel Emulation Timeout" 300 This sets the timeout to 300ms. Of course whenever the X server is restarted these commands must be issued again. One way to do this is to put these commands in ~/.xsessionrc. Se man Xsession. Another thing you may want to change is the sensitivity and speed of the trackpoint. In order to do this you need to change the contents of two files in the /sys virtual file system: /sys/devices/platform/i8042/serio1/serio2/sensitivity /sys/devices/platform/i8042/serio1/serio2/speed This can be done as root this way: echo -n 200 >/sys/devices/platform/i8042/serio1/serio2/sensitivity echo -n 150 >/sys/devices/platform/i8042/serio1/serio2/speed You may experiment with different numbers between 0 and 255. If you reboot you need to issue these commands again. I used to put these commands in /etc/rc.local, but this doesn't work any more. I've also written udev rules, but that didn't work either. What worked was to put these commands in an upstart script. I put the following upstart file in /etc/init: description "Trackpoint settings." env TPDIR=/sys/devices/platform/i8042/serio1/serio2 start on virtual-filesystems task script while [ ! -f$TPDIR/sensitivity ]; do
sleep 1
done
echo -n 200 > $TPDIR/sensitivity echo -n 150 >$TPDIR/speed
end script


###### Update 2012-07-25

I can confirm that with 3.4.6, the instabilities of the stock Ubuntu kernel are gone. A patched 3.2 kernel is released from Ubuntu, but I haven't tested it. However, if you use nfs, you are likely to hit this bug in the nfs idmap code. A temporary solution is to use the new idmap code as described in the mailing list. Also, if you use Compiz (which is the default on Ubuntu) and suspend, you are likely to run across this bug. The temporary solution is to choose Unity 2D from the login manager. But then you will likely experience tearing while watching videos. If you still want to use Compiz, it is a good idea to save any open files before going to suspend.