Linux kernel in a nutshell

Advices
-------node

1. Don't configure or build your kernel with superuser permission enabled.linux

2. Most user space applications are not affected by the version of the kernel.
   However, there's a small number of programs for which the kernel version is
   important. These packages should also be upgraded if your kernel is upgraded
   to a different version.
   util-linux
   module-init-tools
   File-system Specific Tools
       -- e2fsprogs
       -- reiserfsck
       -- quotas
       -- nfs-utils
   udev
   process tools (procps, for example)git

   Also, for some devices to work properly, some specific packages may need to
   be installed.ubuntu

3. Configure the kernel
   make config
   make defconfig
   make menuconfigapi

4. Build the kernel
   make -jN
   make path/to/dir/
   make M=path/to/dir
   make path/to/module.ko
   make O=path/to/output/app

5. Build the kernel in a cross-compiled manner
   make ARCH=x86_64 defconfig
   make ARCH=arm CROSS_COMPILE=/path/to/toolchain/arm-linux-
   make CC="ccache gcc"
   make CC="ccache distcc"less

6. Install the kernel
   make modules_install [install built modules under /lib/modules/ directory]
   make install
       [This step does a lot of things.]
       -- verify the kernel has been successfully built
       -- install the kernel into the /boot directory, together with System.map
       -- automatically create the initial ramdisk
       -- notify the bootloader program of the new kernel
   rebootide

7. Example of using a built kernel module
   $ sudo insmod aufs.ko
   [sudo] password for chenqi:
   $ cat /proc/filesystems | grep -i aufs
   nodev       aufs
   $ pwd
   /lib/modules/3.2.0-35-generic/kernel/ubuntu/aufsfetch

8. ubuntu kernel development using git
   Use the following command to check your ubuntu version:
       lsb_release -a
   git clone git://kernel.ubuntu.com/ubuntu/ubuntu-oneiric.git (11.10)
   git clone git://kernel.ubuntu.com/ubuntu/ubuntu-precise.git (12.04)
   http://en.wikipedia.org/wiki/List_of_Ubuntu_releases
   https://wiki.ubuntu.com/Kernel/Dev/KernelGitGuide
   git fetch
   git reset --hard origin/master
   or
   git rebase --onto origin/master origin/master@{1}
   git commit -s -F debian/commit-templates/patch -e
   Mailing List: kernel-team@lists.ubuntu.comui

9. Upgrading a kernel
   -- Back the configuration file which works fine for the current kernel
      -- cp /path/to/.config /place/for/confs/config-[s|d]-<kernelversion>
   -- Get the new kernel source
      [This would be easy with git.]
   -- make oldconfig
      [Please make sure you understand the configuration.]
   -- make silentoldconfig
      [This is the preferred way to use an existing .config file.]

10. Kernel customization
    Principle of thumb: don't disable an option unless you're sure about it.

11. To figure out which driver controls a new device, just build all drivers of
    that type as modules, and let the udev startup process to match the driver
    to the device. Once this happens, we work backwards to determine the proper
    driver needed.
    [Determine the module from a distribution kernel]

12. [Determine the module from scratch]
    In case the above method doesn't work out well, we need to figure out the
    correct modules to build in order to get some devices work.
    Example: PCI device
    -- find the PCI bus ID of the device using lspci
    -- Go to the /sys/bus/pci/devices/0000:bus_id directory
    -- find out the vendor and the device ID
    -- move back to kernel source tree, looking for the IDs
    -- determine the driver by matching the IDs in source code
    -- search Kernel Makefiles to determine which CONFIG_ option to enable
    -- enable that option in the kernel configuration system

13. Root Filesystem
    [Two key components: disk controller and filesytem]
    If your newly configured kernel dies at boot time with an error such as:
        VFS: Cannot open root device hda2 (03:02)
        Please append a correct "root=" boot option
        Kernal panic: VFS: Unable to mount root fs on 03:02
    then the root filesystem wasn’t found. If you are not using a ramdisk image
    at boot time, it is usually recommended that you build both the filesystem
    that you use for your root partition, and the disk controller for that disk,
    into the kernel, instead of having it as a module. If you use a ramdisk at
    boot time, you should be safe building these portions as modules.


Q & A
-----

Q) Why is the initial ramdisk needed to boot a kernel?
   Why is it different from the original ramdisk for the old kernel?
   Is it closely related to kernel configuration or kernel version?

Q) How to find out what driver is needed to control what piece of hardware?
A) method 1:
   Use sysfs to examine the relationships between devices and drivers.
   method 2:
   Retrieve module information from the /proc/modules interface.
   method 3:
   Retrieve module information from /sys/module/.

Q) How to examine the modules currently active in system?
A) lsmod
   cat /proc/modules

Causion
-------

Each distribution may create its own ramdisk differently. Module                  Size  Used by usb_storage            53295  1 USB_STORAGE=y (USB Mass Storage support) [100%] bnep                   18294  2 BT_BNEP=y (Bluetooth BNEP protocal support) [100%] pci_stub               12622  1 PCI_STUB=y (PCI stub driver) [100%] vboxpci                23200  0 vboxnetadp             13382  0 vboxnetflt             23441  0 vboxdrv               282548  3 vboxpci,vboxnetadp,vboxnetflt kvm_intel              60830  0 KVM_INTEL=y (KVM support for intel processors) [100%] kvm                   375381  1 kvm_intel KVM=y (Kernel-based virtual machine support) [100%] parport_pc             36784  0 PARPORT_PC=y, PARPORT=y (Parallel port support, PC-style hardware) [100%] nfsd                  318936  13 NFSD=y (NFS server support) [100%] ppdev                  17030  0 PPDEV=y (Support for user-space parallel port device drivers) [100%] nfs                   334019  0 NETWORK_FILESYSTEM=y [100%] lockd                  85235  2 nfsd,nfs LOCKD=y [100%] fscache                61069  1 nfs FSCACHE=y (General filesystem local caching manager) [100%] auth_rpcgss            52923  2 nfsd,nfs SUNRPC_GSS=y [100%] nfs_acl                12837  2 nfsd,nfs NFS_ACL_SUPPORT=y [100%] sunrpc                238645  19 nfsd,nfs,lockd,auth_rpcgss,nfs_acl SUNRPC=y [100%] binfmt_misc            17431  1 BINFMT_MISC=y (Kernel support misc binaries) [100%] arc4                   12529  2 CRYPTO_ARC4=y [100%] ath9k                 121377  0 ATH9K=y (Atheros 802.11n wireless cards support) [100%] mac80211              452164  1 ath9k [100%] nouveau               722417  0 DRM_NOUVEAU=y (nouveau card support) [100%] snd_hda_codec_hdmi     31706  1 SND_HDA_CODEC_HDMI=y (Build HDMI/DisplayPort HD-audio support) [100%] ath9k_common           13839  1 ath9k [100%] ath9k_hw              304879  2 ath9k,ath9k_common [100%] snd_hda_intel          32910  2 SND_HDA_INTEL=y [100%] snd_hda_codec         103933  2 snd_hda_codec_hdmi,snd_hda_intel [100%] snd_hwdep              13563  1 snd_hda_codec SND_HWDEP=y [100%] snd_pcm                95859  3 snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec SND_PCM=y [100%] i915                  565127  2 DRM_I915=y (Intel xxx graphics) [100%] snd_seq_midi           13324  0 snd_rawmidi            30368  1 snd_seq_midi ttm                    76163  1 nouveau DRM_TTM=y [100%] uvcvideo               71531  0 ath                    23780  2 ath9k,ath9k_hw ATH_CARDS=y (Atheros wireless cards support) [100%] videodev               92609  1 uvcvideo VIDEO_DEV=y [100%] snd_seq_midi_event     14899  1 snd_seq_midi rfcomm                 47004  8 BT_RFCOMM=y [100%] snd_seq                61520  2 snd_seq_midi,snd_seq_midi_event btusb                  18600  2 BT_HCIBTUSB=y [100%] v4l2_compat_ioctl32    16692  1 videodev cfg80211              198140  3 ath9k,mac80211,ath CFG80211=y (wireless configuration api) [100%] bluetooth             159177  23 bnep,rfcomm,btusb [100%] drm_kms_helper         42205  2 nouveau,i915 [100%] snd_timer              29533  2 snd_pcm,snd_seq [100%] drm                   235135  5 nouveau,i915,ttm,drm_kms_helper DRM=y [100%] snd_seq_device         14497  3 snd_seq_midi,snd_rawmidi,snd_seq psmouse                72891  0 MOUSE_PS2=y [100%] snd                    67877  13 snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_rawmidi,snd_seq,snd_timer,snd_seq_device SND=y [100%] dell_wmi               12681  0 DELL_WMI=y (x86 platform specific drivers, dell wmi extras) [100%] serio_raw              13166  0 mei                    40611  0 INTEL_MEI=y (Intel Management Engine Interface) [100%] sparse_keymap          13890  1 dell_wmi soundcore              12680  1 snd snd_page_alloc         18484  2 snd_hda_intel,snd_pcm mxm_wmi                12979  1 nouveau MXM_WMI=y (WMI support for MXM Laptop graphics) [100%] i2c_algo_bit           13272  2 nouveau,i915 I2C_ALGOBIT=y [100%] dell_laptop            13831  0 DELL_LAPTOP=y (Dell laptop extras) [100%] dcdbas                 14438  1 dell_laptop DCDBAS=y (Dell Systems Management Base Dirver) [100%] wmi                    19070  2 dell_wmi,mxm_wmi WMI=y [100%] video                  19337  2 nouveau,i915 lp                     17759  0 parport                46354  3 parport_pc,ppdev,lp PARPORT=y (Parallel port support) [100%] usbhid                 46738  0 USB_HID=y (USB HID transport layer) [100%] hid                    95027  1 usbhid HID=y [100%] ahci                   25854  1 SATA_AHCI=y (sata ahci support) [100%] libahci                26659  1 ahci r8169                  56504  0 R8169=y (Realtek R8169 gigabit ethernet support) [100%]

相關文章
相關標籤/搜索