Download presentation
Presentation is loading. Please wait.
Published byAubrie Joseph Modified over 8 years ago
1
Using and configuring the Linux 2.6 kernel, and building it “The Debian Way” Presented April 2, 2008 by Chris Knadle Files related to the talk maintained at: ftp://ftp.coredump.us/kernel-talk_04-02-2008 or on the MHVLUG page for the meeting at: http://mhvlug.org/MonthlyMeetings/2008/04
2
** Outline / overview – 28 slides total ● Tour of interacting with the Linux kernel ● Bootup diagrams -- 11 ● Configuration strategies -- 17 ● Building Linux and external drivers -- 23 ● diff, patch, quilt, and git -- 26 ● Specific CONFIG_ options of interest -- 28 1
3
** The main functions of the kernel 1. Memory management 2. Process management 3. File system management 4. I/O management 5. “Blue Black Screen Of Death !” :-) i.e. if something goes horribly wrong and a kernel panic occurs, try to give a clue as to why [ level of detail depends on debugging options ] 2
4
** Whirlwind tour of interacting w/ the kernel (1) ● boot parameters can be for drivers or to change boot behavior GRUB: kenrel /vmlinuz... root=/dev/hda3 ro vga=1 ● insmod loads a single driver built as a module ● modprobe loads a driver built as a module (which initializes hardware) + loads driver dependencies Module parameters can be specified in an alias in /etc/modprobe.conf, /etc/modprobe.d/*, or (deprecated) /etc/modules.conf 3
5
** Whirlwind tour of interacting w/ the kernel (2) ● rmmod removes a module ● /etc/modules modules to load at boot that are not auto-detected ● /sbin/modinfo as well as the documentation on the driver explain parameters a module offers and where the module is ● Text output from driver load is output to the kernel ring buffer; available for examination in /var/log/dmesg or by running the ' dmesg ' command 4
6
** Whirlwind tour of interacting w/ the kernel (3) ● In /proc/sys/ there are kernel settings that can be viewed and changed on-the-fly. Example: $ cat /proc/sys/net/ipv4/ip_forward 0 $ echo “1” > /proc/sys/net/ipv4/ip_forward ● Making settings in /proc/sys/ permanent can be accomplished by modifying /etc/sysctl.conf, changing ' / ' characters to '. ', and stripping off the initial /proc/sys/ portion. Using previous Ex: net.ipv4.ip_forward = 1 5
7
** Whirlwind tour of interacting w/ the kernel (4) ● But developers are moving items from /proc/sys/ to /sys/ and /etc/sysctl.conf is hardcoded to adjust items in /proc/sys/ Example: $ cat /sys/block/hda/queue/scheduler noop anticipatory deadline [cfq] $ echo “deadline” > /sys/block/hda/queue/scheduler ● The sysfsutils package includes /etc/sysfs.conf which will set kernel parameters in /sys/ at boot time; has a different syntax than /etc/sysctl.conf block/hda/queue/scheduler = deadline 6
8
** Reasons to compile your own kernel Because you can ● Because you can “Use the source!” ● New hardware support ● Quirky, old, or non-generic hardware ● Experimentation, development, bug fixes ● Configuration for a particular desire (security, preemption, embedded applications, remove the need of an initrd image, remove unwanted functionality, custom fixes, etc) 7
9
** Reasons NOT to compile your own kernel ● It's likely to get it “wrong” at first. [ won't compile, can't find init, missing drivers, etc ] ● Some software vendors refuse to give support if you are running a custom kernel ● In some cases software may break even if you get it “right” due to expecting kernel to be built in a particular way [Missing driver, a script designed to load a module when instead the driver is built-in, etc] 8
10
** Minimum requirements for kernel building For Linux 2.6.18: = 3.2 [and I recommend gcc < 4.3] ● binutils >= 2.12 ● make >= 3.79.1 ● util-linux >= 2.10 ● module-init-tools >= 0.9.10 ● e2fsprogs >= 1.29 (if ext2/3/4 used) ● udev >= 081 ● procps >= 3.2.0 ● A “computer”; 128 MB of RAM is definitely more than enough, need 500 MB to 1 GB of dedicated storage space 9
11
** Bootup for the Linux kernel (simplified) Power on, CMOS MBR BOOT LOADER LINUX initrd.im g run /sbin/init run initrd /init mount / POSIX shell script ELF binary executable Boot Options mount / init rd? Yes No load internal drivers load driver modules load initrd driver modules 10
12
** Decide what Linux source to start with (1) 1. Download a Linux kernel source tarball wget http://www.kernel.org/.../?.tar.bz2 ~56 MiB download for full image, patch sizes vary Expands to an additional ~308 MiB 2. Install as a package from the distribution apt-get install linux-source- yum install kernel-devel. Size varies 3. Download from a Git repository git clone git://git.kernel.org/pub/... ~176 MiB packed in.git + ~308 MiB expanded, updates are space efficient 11
13
** Decide what Linux source to start with (2) http://www.kernel.org/pub/linux/kernel/v2.6/ Downloading the latest stable full image; or visit: http://www.kernel.org/pub/linux/kernel/v2.6/ PATCH FULL 12
14
** Configuration of the Linux kernel (1) ● Don't start from scratch; copy one of the working config files from /boot/config- to the local Linux source directory as the filename “.config ” These ship with every distribution. ● Make one of: ' menuconfig ', ' xconfig ', ' gconfig' Customize the configuration for your needs; ' xconfig ', ' menuconfig ', etc, can also be used as a visualizer for looking at a config file ● Read the help on the configuration options If you're in a rush, pay close attention to: If in doubt, say “_” 13
15
** Configuration of the Linux kernel (2) menuconfig 14
16
** Configuration of the Linux kernel (3) xconfig 15
17
** Configuration of the Linux kernel (4) gconfig 16
18
** Linux configuration strategies (1) ● Generic, all drivers built as a module, initrd ● Targetted built-in drivers, all other drivers built as a module ● Minimal drivers all built-in, no module support at all ● Drivers can be built-in (choosing “Y), as a module (choosing “M”), or not built at all (choosing “N). “N” -- driver / feature not available at all “Y” -- loaded with kernel, cannot be unloaded, cannot specify options using aliases “M” -- modularized, might be loaded with initrd 17
19
“M” = module “Y” = built-in ** Linux configuration strategies (2) Power on, CMOS MBR BOOT LOADER LINUX initrd.im g run /sbin/init run initrd /init mount / Boot Options mount / init rd? Yes No load internal drivers load driver modules load initrd driver modules “M” + req'd for boot 18
20
** Linux configuration strategies (3) ● Generic, all drivers built as a module, initrd Build drivers as modules, specify ' --initrd ' during the build. Easiest starting method ● Targeted built-in drivers ● Use 'lsmod' to list the modules your machine ● uses, look in the help for ● “module will be called...... ” ● can also use '/sbin/modinfo' for hints ● find + build-in the most required parts of the list ● Minimal drivers all built-in, no module support at all Build-in dependencies, remove all nonessentials 19
21
** Installing the required tools ● Required: kernel-package fakeroot bzip2 and other packages are required depending on which configuration ' make ' target you want to build: For ' menuconfig ': libncurses5-dev For ' xconfig ': libqt3-mt-dev g++ For ' gconfig ': libgtk2.0-dev libglade2-dev ● fakeroot is a shell script specifically designed to allow making files that have root ownership, which is required to make Debian packages. It does not give a user elevated privilages. 20
22
package ** Reasons to build + install Linux as a package rather than installation via “make install” ● Makes life easier: installing / removing package updates the boot menu automatically ● Can transfer the package to another box for installation, alleviating the need for installing a development environment on servers ● Can also build external modules in packaged sources maintained outside of the kernel tree ● Because... is there a good reason not to? 21
23
** But isn't making a package more work? Let's see! This is without making a package: make menuconfig make clean time nice make bzimage modules su make modules_install install cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.24.3-686-initrd-crk1 cp System.map /boot/System.map-2.6.24.3-686-initrd-crk1 cp.config /boot/config-2.6.24.3-686-initrd-crk1 mkinitramfs 2.6.24.3-686-initrd-crk1 update-grub With making a package: make menuconfig fakeroot make-kpkg clean time nice fakeroot make-kpkg --revision=2.6.24.3+686+initrd+crk1 \ --initrd kernel_image cd.. sudo dpkg -i *.deb 22
24
** Making packages saves you work ● Sources for external modules can be installed, which install tarballs into /usr/src/ make-kpkg looks for these in /usr/src/modules by default, behavior can be changed by modifying the MODULES_LOC parameter of kernel-pkg.conf ● With making kernel + external module packages: make menuconfig fakeroot make-kpkg modules_clean fakeroot make-kpkg clean time nice fakeroot make-kpkg \ --revision=2.6.24.3+686+initrd+crk1 \ --initrd kernel_image modules_image cd.. sudo dpkg -i *.deb 23
25
** How the boot manager gets updated ● /etc/kernel-img.conf sets behavior for when a new kernel is installed; runs update-grub by default ● menu.lst “comments” used by update-grub # Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST ### BEGIN AUTOMAGIC KERNELS LIST ## lines between the AUTOMAGIC KERNELS LIST markers will be modified ## by the debian update-grub script except for the default options ## below ## DO NOT UNCOMMENT THEM, Just edit them to your needs... # kopt=root=/dev/hde3 ro vga=1 This is not simply a comment -- this a setting used by update-grub when re-making the boot entries 24
26
** diff, patch, quilt, and git (1) ● diff -- outputs the differences between files or directories; ' diff -u ' has a nicer looking output ● patch – apply a diff to file(s) patch -p1 <../patch-2.6.24.1 ● quilt – handles a series of patches; uses a directory ' patches ' to create or use a series of diffs The ' series ' file lists the order to apply a set of patches. Apply all patches of a quilt patchset with quilt push -a 25
27
** diff, patch, quilt, and git (2) ● git -- a full Source Control Management system [package name is ' git-core '] git-clone -- download a repository git-pull -- update a repository git-branch -- make a new branch git-branch -D -- delete a branch (uncond.) git-checkout -- switch working branches git-add -- add a file to be tracked git-commit -a -- commit differences to tracked files git-status -- check working tree status vs repository 26
28
** CONFIG options of interest for 2.6.24 “General setup” section: CONFIG_FAIR_GROUP_SCHED → For desktop, Say N CONFIG_PREEMPT_VOLUNTARY → For desktop, Say Y “Processor type and features” section: CONFIG_NO_HZ → tickless kernel, interesting idea “Kernel hacking” section: CONFIG_MAGIC_SYSRQ → Say Y, and read sysrq.txt CONFIG_DEBUG_KERNEL → Say Y “Device Drivers -> General Driver Options” CONFIG_UEVENT_HELPER_PATH → set to “” (i.e. empty) unless your system is old and actually uses /sbin/hotplug (the default) 27
29
** Additional resources ● Things to look for in the Linux /Documentation area: HOWTO -- lists starting points and relevant text files kernel-parameters.txt -- lists the many available boot parameters kernel-doc.txt -- lists lots of free online books /networking/* -- network drivers documentation Linux Kernel In A Nutshell [free pdf download] by Greg Kroah-Hartman: http://www.kroah.com/lkn/ 28
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.