User Tools

Site Tools


linux:compiling-the-linux-kernel

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
linux:compiling-the-linux-kernel [2017/03/07 14:07]
127.0.0.1 external edit
linux:compiling-the-linux-kernel [2019/01/21 11:11] (current)
seanburns
Line 1: Line 1:
-====== Compiling ​the Linux Kernel ======+<​markdown>​ 
 +## Preparing to modify ​the Linux kernel:
  
-**date: 2016-09-27 09:46:31-04:00**+Clone your Fedora VM 
 +Update your machine:
  
-ompiling the Linux Kernel ======+``$ sudo dnf check-update ; sudo dnf update``
  
-**date2016-09-27 09:46:31-04:00**+- Install the following: 
 + 
 +``$ sudo dnf install ncurses-devel bison elfutils-libelf-devel`` 
 + 
 +``$ sudo dnf install openssl-devel`` 
 + 
 +- Install the following groups of packages: 
 + 
 +``$ sudo dnf groupinstall '​Development Tools'​ 
 + 
 +``$ sudo dnf groupinstall 'C Development Tools and Libraries'​`` 
 + 
 +- Download the latest, stable release of the Linux kernel from 
 +kernel.org. The kernel is about 100MBs large, and this needs 
 +to be done ahead of time. Use *wgetto download the kernel: 
 + 
 +``$ wget https://​cdn.kernel.org/​pub/​linux/​kernel/​v4.x/​linux-4.18.8.tar.xz``
  
 Here are some notes on the basics of compiling a Linux kernel. We're following Here are some notes on the basics of compiling a Linux kernel. We're following
-the text by Soyinka ​ +the text by [Soyinka][1], which means we're downloading the most recent kernel
-((https://​www.amazon.com/​Linux-Administration-Beginner%E2%80%99s-Guide-Seventh/​dp/​0071845364/​)) +
-which means we're downloading the most recent kernel+
 source tree, enabling NTFS support as a module, and then re-compiling. We're source tree, enabling NTFS support as a module, and then re-compiling. We're
 recompiling a kernel for a Fedora 23 system that's running in VirtualBox. recompiling a kernel for a Fedora 23 system that's running in VirtualBox.
  
-**Note** about the code snippets:+**Note** about code snippets:
  
-  ​- Lines beginning with a ''​$'' ​sign signify normal user prompt +- Lines beginning with a "$" ​sign signify normal user prompt 
-  - Lines beginning with a ''​%'' ​sign signify root prompt +- Lines beginning with a "%" ​sign signify root prompt 
-  - Lines beginning with a ''​#'' ​sign signify comments in Bash +- Lines beginning with a "#" ​sign signify comments in Bash 
-  - Lines w/o any initial sign signify standard output+- Lines w/o any initial sign signify standard output
  
-We can identify the current kernel by using ''​uname''​+We can identify the current kernel by using <​code>​uname</​code>​
  
-<code bash> +    ​$ uname -a 
-$ uname -a +    4.7.4-100.fc23.x86_64
-4.7.4-100.fc23.x86_64 +
-</​code>​+
  
 This is also the latest kernel at kernel.org, but we'll recompile it to see how This is also the latest kernel at kernel.org, but we'll recompile it to see how
Line 32: Line 46:
  
 First, let's download the source code for the latest release (as of this First, let's download the source code for the latest release (as of this
-writing), and unpack it in ''​/usr/src''​:+writing), and unpack it in */usr/src*:
  
-<code bash> +    ​$ su root 
-$ su root +    % cd /usr/src 
-% cd /usr/src +    % wget  
-% wget https://www.kernel.org/​pub/​linux/​kernel/​v4.x/​linux-4.7.4.tar.xz +    ​https://cdn.kernel.org/​pub/​linux/​kernel/​v4.x/​linux-4.18.8.tar.xz 
-% tar xvJf linux-4.7.4.tar.xz +    % tar xvJf linux-4.7.4.tar.xz
-</​code>​+
  
-Now let's begin to configure the source for our particular machine.+Now let's begin to configure the source for our particular ​virtual ​machine.
  
 As an aside, sometimes we re-compile kernels to eliminate support for hardware As an aside, sometimes we re-compile kernels to eliminate support for hardware
 we don't have, for enabling hardware that we need, or for patching kernels with we don't have, for enabling hardware that we need, or for patching kernels with
-security updates. There are more use-cases, but regarding ​hardware, we can use +security updates. There are more use-cases, but regarding ​harwdware, we can use 
-''​lspci'' ​and ''​lshw'' ​to list PCI devices and other hardware+<​code>​lspci</​code> ​and <​code>​lshw</​code> ​to list PCI devices and other hardware
 on the system. This is what my virtual system thinks it has: on the system. This is what my virtual system thinks it has:
  
-<code bash> +    ​% lspci 
-% lspci +    00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) 
-00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) +    00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/​Triton II] 
-00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/​Triton II] +    00:01.1 IDE interface: Intel Corporation 82371AB/​EB/​MB PIIX4 IDE (rev 01) 
-00:01.1 IDE interface: Intel Corporation 82371AB/​EB/​MB PIIX4 IDE (rev 01) +    00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter 
-00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox ​ +    00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02) 
-Graphics Adapter +    00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service 
-00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet ​ +    00:05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio Controller (rev 01) 
-Controller (rev 02) +    00:06.0 USB controller: Apple Inc. KeyLargo/​Intrepid USB 
-00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service +    00:07.0 Bridge: Intel Corporation 82371AB/​EB/​MB PIIX4 ACPI (rev 08) 
-00:05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio  +    00:0d.0 SATA controller: Intel Corporation 82801HM/HEM (ICH8M/​ICH8M-E) SATA Controller [AHCI mode] (rev 02)
-Controller (rev 01) +
-00:06.0 USB controller: Apple Inc. KeyLargo/​Intrepid USB +
-00:07.0 Bridge: Intel Corporation 82371AB/​EB/​MB PIIX4 ACPI (rev 08) +
-00:0d.0 SATA controller: Intel Corporation 82801HM/HEM (ICH8M/​ICH8M-E) SATA  +
-Controller [AHCI mode] (rev 02) +
-</​code>​+
  
-We need to install ​''​lshw''​. Then:+We need to install ​<​code>​lshw</​code>​. Then:
  
-<code bash> +    ​% dnf install lshw 
-% dnf install lshw +    % lshw | less
-% lshw | less +
-</​code>​+
  
 (Output too long to show.) (Output too long to show.)
  
-We're going to run ''​make menuconfig''​, but before we do so, we'​ll +We're going to run <​code>​make menuconfig</​code>​, but before we do so, we'​ll 
-first run ''​make mrproper'' ​to clean up the build environment. First,+first run <​code>​make mrproper</​code> ​to clean up the build environment. First,
 install the development tools, then change into the kernel tree directory, and install the development tools, then change into the kernel tree directory, and
 run mkproper. run mkproper.
  
-<code bash> +    ​# need the tools to build the kernel 
-# need the tools to build the kernel +    % dnf install @development-tools 
-% dnf install @development-tools +    # alternatively,​ this is supposed to work: dnf groupinstall "​Development Tools"​ 
-# alternatively,​ this is supposed to work: dnf groupinstall "​Development Tools"​ +    % cd /​usr/​src/​linux-4.7.4 
-% cd /​usr/​src/​linux-4.7.4 +    % make mrproper 
-% make mrproper +    # copy the current ​kernel'​s ​config file to $PWD 
-# copy the current config file to $PWD +    % cp /​boot/​config-`uname -r` .config 
-% cp /​boot/​config-`uname -r` .config +    # alternatively:​ cp /​boot/​config-$(uname -r) .config 
-# alternatively:​ cp /​boot/​config-$(uname -r) .config +    # run menuconfig 
-# run menuconfig +    % make menuconfig 
-% make menuconfig +    # received an error about a missing ncurses header file, so: 
-# received an error about a missing ncurses header file, so: +    % dnf install ncurses-devel.x86_64 
-% dnf install ncurses-devel.x86_64 +    # now re-run menuconfig 
-# now re-run menuconfig +    % make menuconfig
-% make menuconfig +
-</​code>​+
  
-We're following the text by Soyinka, and enabling support for NTFS as a +We're following the text by [Soyinka][1], and enabling support for NTFS as a 
-module. I'm skipping her description here, but the changes ​to we've made to+module. I'm skipping her description here, but the changes we've made to
 .config include: .config include:
  
-<code bash> +    ​% grep -i ntfs .config 
-% grep -i ntfs .config +    CONFIG_NTFS_FS=m 
-CONFIG_NTFS_FS=m +    CONFIG_NTFS_DEBUG=y 
-CONFIG_NTFS_DEBUG=y +    CONFIG_NTFS_RW=y
-CONFIG_NTFS_RW=y +
-</​code>​+
  
-Next open the Makefile and add ''​-custom'' ​to the EXTRAVERSION variable, and  +Next open the Makefile and add *-customto the EXTRAVERSION variable, and then
-then+
 run: run:
  
-<code bash> +    ​% make kernelversion 
-% make kernelversion +    4.7.4-custom
-4.7.4-custom +
-</​code>​+
  
-After running ​''​make''​, I found I still needed to install some more development+After running ​*make*, I found I still needed to install some more development
 files. Here we go: files. Here we go:
  
-<code bash> +    ​% dnf -y group install 'C Development Tools and Libraries'​
-% dnf -y group install 'C Development Tools and Libraries'​ +
-</​code>​+
  
 Woops, another error. We also need to install: Woops, another error. We also need to install:
  
-<code bash> +    ​% dnf install openssl-devel 
-% dnf install openssl-devel +    % make
-% make +
-</​code>​+
  
 And it's compiling. Takes about an hour on the virtual system w/ only 1 CPU. If And it's compiling. Takes about an hour on the virtual system w/ only 1 CPU. If
Line 136: Line 130:
 our VB settings. our VB settings.
  
-Now we need to install the modules and the then run ''​make'' ​again.+Now we need to install the modules and then run <​code>​make</​code> ​again.
  
-<code bash> +    ​% make modules_install
-% make modules_install +
-</​code>​+
  
-More compiling. (Next time run run ''​time'' ​to get a report on how+More compiling. (Next time run <​code>​time</​code>​ command ​to get a report on how
 long.) long.)
  
 Next, copy and rename the kernel image to /boot, as well as System.map: Next, copy and rename the kernel image to /boot, as well as System.map:
  
-<code bash> +    ​% cp /​usr/​src/​linux-4.7.4/​arch/​x86_64/​boot/​bzImage /​boot/​vmlinux-4.7.4-custom 
-% cp /​usr/​src/​linux-4.7.4/​arch/​x86_64/​boot/​bzImage /​boot/​vmlinux-4.7.4-custom +    % cp /​usr/​src/​linux-4.7.4/​System.map /​boot/​System.map-4.7.4-custom
-% cp /​usr/​src/​linux-4.7.4/​System.map /​boot/​System.map-4.7.4-custom +
-</​code>​+
  
 Finally, create the RAM file system image, create list of module dependences,​ Finally, create the RAM file system image, create list of module dependences,​
 and update the boot loader config. Before rebooting, check and update the boot loader config. Before rebooting, check
-''​/​boot/​grub2/​grub.cfg'' ​to see if the boot config was updated, and+<​code>​/​boot/​grub2/​grub.cfg</​code> ​to see if the boot config was updated, and
 then reboot. then reboot.
  
-<code bash> +    ​% new-kernel-pkg --mkinitrd --dracut --depmod --install 4.7.4-custom 
-% new-kernel-pkg --mkinitrd --dracut --depmod --install 4.7.4-custom +    % reboot
-% reboot +
-</​code>​+
  
 After reboot and selecting the new image from grub: After reboot and selecting the new image from grub:
  
-<code bash> +    ​$ uname -r 
-$ uname -r +    4.7.4-custom
-4.7.4-custom +
-</​code>​ +
- +
-Reboot didn't automatically reboot with the custom kernel, although it's an +
-option in the grub startup. After inspecting ''/​boot'',​ I noticed that +
-the new vmlinuz image is not executable. So: +
- +
-<code bash> +
-% chmod 755 /​boot/​vmlinuz-4.7.4-custom +
-</​code>​ +
- +
-That didn't work -- so must investigate later---probably have to edit grub.cfg. +
- +
---- +
- +
-Here I'm simply playing around and am disabling lots in the kernel. Renaming +
-kernel to ''​-custom2''​ in the Makefile and trimming the kernel to the +
-barebones (in quite a random way). +
- +
-<code bash> +
-% time make +
-real    44m18.458s +
-user    31m30.742s +
-sys      4m31.457s +
-% make modules_install +
-% cp /​usr/​src/​linux-4.7.4/​arch/​x86_64/​boot/​bzImage /​boot/​vmlinuz-4.7.4-custom2 +
-% cp /​usr/​src/​linux-4.7.4/​System.map /​boot/​System.map-4.7.4-custom2 +
-% new-kernel-pkg --mkinitrd --dracut --depmod --install 4.7.4-custom2 +
-</​code>​ +
- +
-Then reboot. But.... the new kernel doesn'​t work. So, I must have disabled +
-something important! Still, this is a good learning experience. +
- +
-//Support removed, not thoroughly documented//​ +
- +
-  - Remove multimedia support +
-  - Remove sound card support +
-  - Remove Macintosh device drivers +
-  - Remove Normal floppy disk support +
-  - Remove Packet writing on CD/DVD media +
-  - Remove a slew of ATA support +
-  - Remove Fusin MPT device support +
-  - Remove FireWire driver stack +
-  - Remove PPP (point-to-point protocol) support +
-  - Remove SLIP (serial line) support +
-  - Remove USB Network Adapters +
-  - Remove Wireless LAN +
-  - Remove ISDN support +
-  - Remove SPI support +
-  - Remove Dallas'​s 1-wire support +
-  - Remove Hardware Monitoring support +
-  - Remove Watchdog Timer Support +
-  - Remove Graphics support +
-  - Remove USB support +
-  - Remove Ultra Wideband devices +
-  - Remove MMC/SD/SDIO card support +
-  - Remove Sony MemoryStick card support +
-  - Remove LED support +
-  - Remove Accessibility support +
-  - Remove InfiniBand support +
-  - Remove DMA Engine support +
-  - Remove Auxiliary Display support +
-  - Remove aspects of Userspace I/O drivers +
-  - Remove Platform support for Chrome hardware +
-  - Remove Enable software triggers support under Industrial I/O support +
-  - Remove Pulse-Width Modulation (PWM) Support +
-  - Remove FMC support +
-  - Remove PHY Subsystem +
-  - Remove Thunderbolt support for Apple devices +
-  - Remove Reiserfs support +
-  - Remove XFS filesystem support +
-  - Remove GFS2 file system support +
-  - Remove OCFS2 file system support +
-  - Remove NILFS2 file system support +
-  - Remove F2FS filesystem support +
-  - Remove Miscellaneous filesystems support +
-  - Remove Network File Systems support +
-  - Remove various Native language support +
-  - Remove various Power management and ACPI options+
  
-===== References ​=====+### References
  
-Soyinka, Wale. (2015). ​//Linux administration:​ A beginner'​s guide//. New York:+Soyinka, Wale. (2015). ​*Linux administration:​ A beginner'​s guide*. New York:
 MacGraw Hill Education. MacGraw Hill Education.
  
 +[1]: https://​www.amazon.com/​Linux-Administration-Beginner%E2%80%99s-Guide-Seventh/​dp/​0071845364/​
 +</​markdown>​
linux/compiling-the-linux-kernel.txt · Last modified: 2019/01/21 11:11 by seanburns