Configure the Kernel

From gr0x0rd
Jump to navigation Jump to search

Installing Gentoo - Configure the Kernel

Configuring the Linux kernel is the most difficult part of performing a Gentoo installation.

The components of the Linux kernel can either be built-in or compiled as modules which can be loaded or unloaded. Most Linux distributions will provide you with a generic kernel image with most of the hardware drivers and other components available as modules. The advantage of this method is that another piece of software can probe the system, determine the hardware components, and load the appropriate modules at startup, much in the same way that your Gentoo installation CD did. The disadvantage is that certain parts of the kernel and most of the modules will never be used. Our goal is to create the smallest, fastest, most efficient kernel possible for your target environment.

Thankfully, most of the hard part has already been done for you. Some time ago, an advocate by the name of Pappy McFae blessed us with "kernel seeds" for a number of different architectures which are freely available at his website, kernel-seeds.org. His goal was to provide starting kernel configurations, geared towards everyday use, but with the unnecessary components removed. Using of of Pappy's kernel seeds, all you need do is add in the drivers for your specific hardware and any other components you may require. Personally, I noticed a performance of around 20% using one of Pappy's kernel seeds as compared to the default kernel configuration provided by the Gentoo devs.


Downloading a kernel seed

We'll start by determining the correct kernel seed config file for our architecture (x86_64 for 64-bit systems or x86 for 32-bit systems). Given the example chosen above, the path to the kernel seed configuration file for a 64-bit system using 2.6.34-gentoo-r12 is http://kernel-seeds.org/seeds/64_bit/gentoo/2.6.34-gentoo-r12-x86_64-07.config . We'll use wget to download the seed and use it as our starting configuration.

# cd /usr/src/linux
# wget http://kernel-seeds.org/seeds/64_bit/gentoo/2.6.34-gentoo-r12-x86_64-07.config

The freshly downloaded file will have the same target file name as its source, so let's make a copy we'll use for our actual config while keeping the original file as a backup should we need to start over.

# cp 2.6.34-gentoo-r12-x86_64-07.config .config


Identifying hardware components

To identify the hardware components in our system, we'll use a tool called lspci, which is part of the pciutils package.

# lspci -v | more

Previously, when configuring the kernel, you'd have to make note of each hardware device, and hunt through the "Device Drivers" section of the kernel to try to enable the necessary drivers for your hardware. Thanks to the work of Pappy and others, this process is easier now. As explained on the kernel-seeds website, you can use pciutils to return the numeric ID's for your hardware.

# lspci -n

Copy the results it's given you and paste them into the form at http://kmuto.jp/debian/hcl/ . It will return a table containing the kernel modules needed for your hardware. For example, here is the results of lspic -n for my system:

00:00.0 0600: 8086:d131 (rev 11)
00:03.0 0604: 8086:d138 (rev 11)
00:08.0 0880: 8086:d155 (rev 11)
00:08.1 0880: 8086:d156 (rev 11)
00:08.2 0880: 8086:d157 (rev 11)
00:08.3 0880: 8086:d158 (rev 11)
00:10.0 0880: 8086:d150 (rev 11)
00:10.1 0880: 8086:d151 (rev 11)
00:1a.0 0c03: 8086:3b3c (rev 05)
00:1b.0 0403: 8086:3b56 (rev 05)
00:1c.0 0604: 8086:3b42 (rev 05)
00:1c.4 0604: 8086:3b4a (rev 05)
00:1c.5 0604: 8086:3b4c (rev 05)
00:1c.6 0604: 8086:3b4e (rev 05)
00:1c.7 0604: 8086:3b50 (rev 05)
00:1d.0 0c03: 8086:3b34 (rev 05)
00:1e.0 0604: 8086:244e (rev a5)
00:1f.0 0601: 8086:3b02 (rev 05)
00:1f.2 0101: 8086:3b20 (rev 05)
00:1f.3 0c05: 8086:3b30 (rev 05)
00:1f.5 0101: 8086:3b26 (rev 05)
01:00.0 0300: 10de:05e2 (rev a1)
02:00.0 0200: 10ec:8168 (rev 03)
03:00.0 0106: 197b:2363 (rev 03)
03:00.1 0101: 197b:2363 (rev 03)
07:01.0 0200: 168c:0013 (rev 01)
07:03.0 0c00: 1106:3044 (rev c0)

Here is what is returned. The specific module / driver information we need is in bold.

8086d131     Intel Corporation       Core Processor DMI        
8086d138     Intel Corporation       Core Processor PCI Express Root Port 1        
8086d155     Intel Corporation       Core Processor System Management Registers        
8086d156     Intel Corporation       Core Processor Semaphore and Scratchpad Registers        
8086d157     Intel Corporation       Core Processor System Control and Status Registers        
8086d158     Intel Corporation       Core Processor Miscellaneous Registers        
8086d150     Intel Corporation       Core Processor QPI Link        
8086d151     Intel Corporation       Core Processor QPI Routing and Protocol Registers        
80863b3c     Intel Corporation       5 Series/3400 Series Chipset USB2 Enhanced Host Controller        
80863b56 Yes Intel Corporation       5 Series/3400 Series Chipset High Definition Audio         snd-hda-intel v2.6.27-
80863b42     Intel Corporation       5 Series/3400 Series Chipset PCI Express Root Port 1        
80863b4a     Intel Corporation       5 Series/3400 Series Chipset PCI Express Root Port 5        
80863b4c     Intel Corporation       5 Series/3400 Series Chipset PCI Express Root Port 6        
80863b4e     Intel Corporation       5 Series/3400 Series Chipset PCI Express Root Port 7        
80863b50     Intel Corporation       5 Series/3400 Series Chipset PCI Express Root Port 8        
80863b34     Intel Corporation       5 Series/3400 Series Chipset USB2 Enhanced Host Controller        
8086244e Yes Intel Corporation       82801 PCI Bridge                                           i810_rng    
80863b02 Yes Intel Corporation       5 Series Chipset LPC Interface Controller                  iTCO_wdt      v2.6.33-
80863b20 Yes Intel Corporation       5 Series/3400 Series Chipset 4 port SATA IDE Controller    ata_piix      v2.6.27-
80863b30 Yes Intel Corporation       5 Series/3400 Series Chipset SMBus Controller              i2c-i801      v2.6.28-
80863b26 Yes Intel Corporation       5 Series/3400 Series Chipset 2 port SATA IDE Controller    ata_piix      v2.6.27-
10de05e2     nVidia Corporation      GT200 [GeForce GTX 260]        
10ec8168 Yes Realtek Semiconductor   RTL8111/8168B PCI Express Gigabit Ethernet controller      r8169         v2.6.25-
197b2363 Yes JMicron Technology Corp JMB362/JMB363 Serial ATA Controller                        jmicron   
197b2363 Yes JMicron Technology Corp JMB362/JMB363 Serial ATA Controller                        jmicron    
168c0013 Yes Atheros Communications  Atheros AR5001X+ Wireless Network Adapter                  ath5k         v2.6.25-
11063044 Yes VIA Technologies, Inc.  VT6306/7/8 [Fire II(M)] IEEE 1394 OHCI Controller          ohci1394

Setting kernel values using menuconfig

Most of the non-numeric options in the kernel configuration can have three settings: [*], which means compiled into the kernel itself, [M], which means compiled as a module, and [ ], which means not used. Our goal is to have as many [ ] values as possible, and only enable the specific values needed for the kernel to access the hardware on the system we're empowering with Gentoo.



Note: I have not yet found a way to easily translate the module names into what they relate to in the kernel .config files! Doing so would drastically simplify the driver configuration portion of the kernel config. If anyone knows how to do this, please let me know.



We're now ready to use the menu configuration editor to set up the kernel.

# make menuconfig

Use the arrow keys to navigate through the options.


Configure hardware drivers

To enable the drivers for your hardware, go down to the Device Drivers section. The first item in the table above is snd-hda-intel. We can see that this is an Intel Corporation 5 Series/3400 Series Chipset High Definition Audio device. The relevant section in the kernel configuration would be

Device Drivers  ---> 
 <*> Sound card support  --->
  <*>   Advanced Linux Sound Architecture  --->
   [*]   PCI sound devices  --->
    <*>   Intel HD Audio  --->
     ...

This isn't the best example to start with, since the driver is actually nested under the Advanced Linux Sound Architecture (ALSA) section, and chances are you don't know what ALSA or OSS are yet. This is explained in greater detail later in the Configure sound section. For now, we will continue with the next item, i810_rng, which is required by the Intel Corporation 82801 PCI Bridge device. After some googling, we uncover that rng is an abbreviation for random number generator, which is a character device. (This is another terrible example- sorry.)

Device Drivers  ---> 
 Character devices  --->
  <*>   Intel HW Random Number Generator support

Next is another terrible example: iTCO_wdt, needed for the Intel Corporation 5 Series Chipset LPC Interface Controller. Some more googling shows that wdt is an acronym for watchdog timer. After some exploration in our Device Drivers section we find a match.

Device Drivers  --->
 [*] Watchdog Timer Support  --->  
  <*>   Intel TCO Timer/Watchdog

At long last, we have a good example: ata_piix, which is needed for the Intel Corporation 5 Series/3400 Series Chipset 4 port SATA IDE Controller. This is the driver which will allow the operating system to interface with our hard disk drives. Let's enable the appropriate driver.

Device Drivers  --->
 <*> Serial ATA and Parallel ATA drivers  --->
  <*>     Intel ESB, ICH, PIIX3, PIIX4 PATA/SATA support

On to the next item, i2c-i801, for the Intel Corporation 5 Series/3400 Series Chipset SMBus Controller. Having noticed a section called I2C support while exploring the Device Drivers section, we know where to enable this device.

Device Drivers  --->
 -*- I2C support  --->
  I2C Hardware Bus support  --->
   <*> Intel 82801 (ICH/PCH) 

The r8169 needed for the Realtek Semiconductor RTL8111/8168B PCI Express Gigabit Ethernet controller is possibly the most straightforward example. We know this is a gigabit network adapter, and that it PCI express. We find the setting in the Network Devices section. Since this is a network adapter, we will compile it as a module. There is no particular reason for this, just personal preference.

Device Drivers  --->
 [*] Network device support  --->
  [*]   Ethernet (1000 Mbit)  --->
   <M>   Realtek 8169 gigabit ethernet support

The JMicron Technology Corp JMB362/JMB363 Serial ATA Controller needs the jmicron setting. As with the Intel ATA driver needed above, we can find this in the Serial ATA and Parallel ATA drivers section.

Device Drivers  --->
 <*> Serial ATA and Parallel ATA drivers  --->
  <*>     JMicron PATA support

The Atheros Communications Atheros AR5001X+ Wireless Network Adapter is an extra PCI card I installed in order to connect to another wireless network in addition to my own. It requires the ath5k setting, located in the Network device support section, which we will also build as a module.

Device Drivers  --->
 [*] Network device support  --->
  [*]   Wireless LAN  --->
   <*>   Atheros Wireless Cards  --->
    <M>   Atheros 5xxx wireless cards support

Finally, the VIA Technologies VT6306/7/8 [Fire II(M)] IEEE 1394 OHCI Controller, or Firewire card, needs the ohci1394 setting. Thankfully, this setting is fairly obvious.

Device Drivers  --->
 IEEE 1394 (FireWire) support  --->
  <*>   OHCI-1394 controllers

We have now enabled the kernel drivers needed for our system's hardware. As mentioned at the beginning of this section, this is the most difficult part of the Gentoo Linux installation, especially for first timers. Chances are you will get stuck when booting into your new kernel for the first time, which is why there is a step-by-step guide in the Troubleshooting section.

Optional: RAID

If you are using RAID, you'll need to build support into the kernel.

Device Drivers  --->
 Multi-device support (RAID and LVM)  --->
   [*] Multiple devices driver support (RAID and LVM)
     <*>   RAID support
       <*>     RAID-0 (striping) mode
       <*>     RAID-1 (mirroring) mode
       <*>     RAID-4/RAID5/RAID6 mode
     <*>   Device mapper support

Configure Processor Type and Features

You can determine the type of processor in your system using the following command

# cat /proc/cpuinfo

This should produce a result something like the following:

processor    : 0
vendor_id    : GenuineIntel
cpu family    : 6
model        : 30
model name    : Intel(R) Core(TM) i5 CPU         750  @ 2.67GHz
stepping    : 5
cpu MHz        : 2668.000
cache size    : 8192 KB
physical id    : 0
siblings    : 4
core id        : 0
cpu cores    : 4
apicid        : 0
initial apicid    : 0
fdiv_bug    : no
hlt_bug        : no
f00f_bug    : no
coma_bug    : no
fpu        : yes
fpu_exception    : yes
cpuid level    : 11
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx rdtscp lm
constant_tsc arch_perfmon pebs bts xtopology nonstop_tsc aperfmperf pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2  
popcnt lahf_lm ida tpr_shadow vnmi flexpriority ept vpid
bogomips    : 5350.38
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 48 bits virtual
power management:
...

The model name field in the information above is the key piece of information here: this system has an Intel Core i5 CPU. Be sure to set your processor type in the kernel configuration using the example below.

Processor type and features  --->
 Processor family ()  --->
  ( ) 386                                                     
  ( ) 486                                                     
  ( ) 586/K5/5x86/6x86/6x86MX                                
  ( ) Pentium-Classic                                         
  ( ) Pentium-MMX                                             
  ( ) Pentium-Pro 
  ( ) Pentium-II/Celeron(pre-Coppermine)                      
  ( ) Pentium-III/Celeron(Coppermine)/Pentium-III Xeon        
  ( ) Pentium M                                              
  ( ) Pentium-4/Celeron(P4-based)/Pentium-4 M/older Xeon     
  ( ) K6/K6-II/K6-III                                         
  ( ) Athlon/Duron/K7 
  ( ) Opteron/Athlon64/Hammer/K8                             
  ( ) Crusoe                                                  
  ( ) Efficeon                                               
  ( ) Winchip-C6                                              
  ( ) Winchip-2/Winchip-2A/Winchip-3                         
  ( ) GeodeGX1  
  ( ) Geode GX/LX                                            
  ( ) CyrixIII/VIA-C3                                       
  ( ) VIA C3-2 (Nehemiah)                                   
  ( ) VIA C7                                                  
  (X) Core 2/newer Xeon                                       
  ( ) Intel Atom

Most new processors have hardware monitoring enabled. Let's enable the temperature sensor for the i5 chip in this example.

Device Drivers  ---> 
 <*> Hardware Monitoring support  --->
  <*>   Intel Core/Core2/Atom temperature sensor


Configure additional peripherals

For udev, and support for hotplugging devices such as usb thumb drives and automounting cdroms, you'll need the following kernel options for udev.

-> General setup
 -> Auditing support 
   [*] Enable system-call auditing support

-> Power management and ACPI options
  [*] Run-time PM core functionality  

-> Device Drivers
  [ ] ATA/ATAPI/MFM/RLL support (DEPRECATED)
  -> USB support 
     -> Support for Host-side USB 
            [*]    USB runtime power management

If your system has a wireless device, you'll want to make sure you've enabled the wireless networking options.

[*] Networking support  --->
 [*]   Wireless  --->
  <*>   cfg80211 - wireless configuration API
  <*>   Generic IEEE 802.11 Networking Stack (mac80211) 

If you use a joystick or gamepad, you'll want to enable the joystick interface.

Device Drivers  ---> 
 Input device support  ---> 
  <*>   Joystick interface

Other Recommended Options

There are a number of other configuration options you should be sure to set for a desktop, laptop or even server system.

To enable CPU frequency scaling, which will allow your system to throttle your CPU if it's not in use, set the options below. This is especially useful in laptops, since less power consumption means less draw on your battery and longer battery life. Be sure to select the appropriate driver based on your CPU type.

Power management and ACPI options  --->
  [*] Suspend to RAM and standby                                              
  [*] Hibernation (aka 'suspend to disk')
 CPU Frequency scaling  --->
  [*] CPU Frequency scaling
  ...
  <*>   'powersave' governor
  <*>   'userspace' governor
  <*>   'ondemand' cpufreq policy governor
  ...
  <*>   ACPI Processor P-States driver
  ...
  <*>   Intel Speedstep on ICH-M chipsets (ioport interface)      
  <*>   Intel SpeedStep on 440BX/ZX/MX chipsets (SMI interface)

To ensure compatibility with as many devices as possible, including Windows drives, we need to configure support for a number of different filesystem types.

File systems  ---> 
 <*> Second extended fs support
 ...
 <*> Ext3 journalling file system support
 ...
 CD-ROM/DVD Filesystems  ---> 
  <*> ISO 9660 CDROM file system support                           
  [*]   Microsoft Joliet CDROM extensions   
  [*]   Transparent decompression extension        
  <*> UDF file system support 
 DOS/FAT/NT Filesystems  --->
  <*> MSDOS fs support                                              
  <*> VFAT (Windows-95) fs support                               
  ,,,
  <*> NTFS file system support
 [*] Network File Systems  --->
  <*>   NFS client support 
  [*]     NFS client support for NFS version 3 
  ...
  <*>   NFS server support                                         
  [*]     NFS server support for NFS version 3
  ...
  <*>   CIFS support (advanced network filesystem, SMBFS successor)

If you need to connect to a pptp vpn at your workplace you'll need to enable networking ppp options.

Device Drivers  --->
 [*] Network device support  --->
  <*>   Universal TUN/TAP device driver support
  <*>   PPP (point-to-point protocol) support                      
  [ ]     PPP multilink support (EXPERIMENTAL) (NEW)               
  [ ]     PPP filtering (NEW)                                      
  <*>     PPP support for async serial ports                       
  <*>     PPP support for sync tty ports                           
  <*>     PPP Deflate compression                                  
  <*>     PPP BSD-Compress compression                             
  <*>     PPP MPPE compression (encryption) (EXPERIMENTAL)

Building the Kernel

Once you are happy with your kernel configuration, choose to Exit the configuration editor and agree to save your config. The next step will be to compile and build the kernel.

# make && make modules_install

The kernel image file will be located in the path corresponding to your system's architecture: arch/x86_64/boot/bzImage for 64-bit systems and arch/x86/boot/bzImage for 32-bit systems. Once the kernel has finished compiling, you'll need to copy it to your boot partition. Since you mounted dev/sda1 to /boot in a previous step, this is fairly easy.

# cp arch/x86_64/boot/bzImage /boot/kernel

Now that the kernel is configured, compiled, and copied to the boot partition, we can move on to Configure fstab.