Update KERNEL.md

This commit is contained in:
mayfrost 2018-03-03 08:35:27 +00:00 committed by GitHub
parent e63780b710
commit c5718c3b7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

138
KERNEL.md
View File

@ -7,10 +7,10 @@ Compiling a kernel has the advantage to make it as minimal and featureful as you
* Give yourself a cup of tea or coffee while you wait to compile. * Give yourself a cup of tea or coffee while you wait to compile.
## PREPARATIONS ## PREPARATIONS
* To see which version the new kernel source is * To see which version the new kernel source
`head /usr/src/linux/Makefile` `head /usr/src/linux/Makefile`
* To see which version the current kernel is * To see which version the current kernel
`uname -r` `uname -r`
## GETTING THE KERNEL SOURCE ## GETTING THE KERNEL SOURCE
@ -28,7 +28,7 @@ Compiling a kernel has the advantage to make it as minimal and featureful as you
`cd linux-<VERSION_NUMBER>/` `cd linux-<VERSION_NUMBER>/`
* Remove compiled files from the kernel tree AND the configuration file (backup your configuration file before this if you have one in the current directory). * Remove compiled files from the kernel tree AND the configuration file (backup your configuration file before this if you have one in the current directory).
make mrproper `make mrproper`
## GENERATING A CONFIGURATION FILE ## GENERATING A CONFIGURATION FILE
@ -63,20 +63,20 @@ This process makes a .config file in the kernel source directory determines whic
`cat /proc/meminfo` `cat /proc/meminfo`
`lsmod` `lsmod`
* OPTION 1: Start a menu and browse options. Requires curses library but likely is already on your computer. Press "H" or "?" to see help. You can use the space bar to cycle between the available choices or press the appropriate key mentioned above. Pressing "/" to search for keywords * OPTION 1: Start a menu and browse options. Requires curses library but likely is already on your computer. Press "H" or "?" to see help. You can use the space bar to cycle between the available choices or press the appropriate key mentioned above. Pressing "/" to search for keywords.
make menuconfig `make menuconfig`
* OPTION 2: Will make questions on what kernel options to support when it finds new kernel options not marked on an existing config file (takes time and and if you are using a striped down config file it requires you knowledge) * OPTION 2: Will make questions on what kernel options to support when it finds new kernel options not marked on an existing config file (takes time and and if you are using a striped down config file it requires you knowledge).
`make oldconfig` `make oldconfig`
* OPTION 3: Will fill questions with default answers on what kernel options to support beyond your provided config file * OPTION 3: Will fill questions with default answers on what kernel options to support beyond your provided config file.
`make olddefconfig` `make olddefconfig`
## COMPILATION ## COMPILATION
Can take minutes to hours. Can take minutes to hours.
* Clean directory (wont touch the config file just remove all compiled files from the kernel tree) * Clean directory (wont touch the config file just remove all compiled files from the kernel tree).
`make clean` `make clean`
_NOTE_: The "-j<X>" flag, where <X> is the number of cores +1, is OPTIONAL and only goes if you have a processor with multiple cores. If you install ccache (OPTIONAL) you can speed up subsequent compilations by including CC="ccache gcc" after the "-j<X>" flag. _NOTE_: The "-j<X>" flag, where <X> is the number of cores +1, is OPTIONAL and only goes if you have a processor with multiple cores. If you install ccache (OPTIONAL) you can speed up subsequent compilations by including CC="ccache gcc" after the "-j<X>" flag.
@ -91,12 +91,12 @@ _NOTE_: The "-j<X>" flag, where <X> is the number of cores +1, is OPTIONAL and o
`make -j<X> bzImage` `make -j<X> bzImage`
## MOVE KERNEL IMAGE ## MOVE KERNEL IMAGE
* OPTION B1: Copy the new kernel to /boot, create the initrd file and change the GRUB menu * OPTION B1: Copy the new kernel to /boot, create the initrd file and change the GRUB menu.
`cp arch/<YOUR_ARCHITECTURE>/boot/bzImage /boot/vmlinuz` `cp arch/<YOUR_ARCHITECTURE>/boot/bzImage /boot/vmlinuz`
* Not required for booting but some processes need it * Not required for booting but some processes need it.
`cp System.map /boot` `cp System.map /boot`
* OPTION B2: Automatically move kernel to /boot (and in certain distros, symlink the new kernel to /boot/vmlinuz and update the bootloader configuration) * OPTION B2: Automatically move kernel to /boot (and in certain distros, symlink the new kernel to /boot/vmlinuz and update the bootloader configuration).
`make install` `make install`
@ -105,7 +105,7 @@ _NOTE_: The "-j<X>" flag, where <X> is the number of cores +1, is OPTIONAL and o
`make -j<X> modules` `make -j<X> modules`
## MOVE MODULES ## MOVE MODULES
* Copy generated kernel modules to /lib/modules/<KERNEL_VERSION>/ * Copy generated kernel modules to /lib/modules/<KERNEL_VERSION>/.
`make modules_install` `make modules_install`
_NOTE_: The vmlinuz can be any name but that exact name has to be added to the configuration file of your bootloader of choice. Usually a version number is appended to the new kernel image. This has the advantage to avoid replacing a current kernel and having a fallback as backup to boot. You can set to boot from any image in the bootloader once you configure them in the bootloader. _NOTE_: The vmlinuz can be any name but that exact name has to be added to the configuration file of your bootloader of choice. Usually a version number is appended to the new kernel image. This has the advantage to avoid replacing a current kernel and having a fallback as backup to boot. You can set to boot from any image in the bootloader once you configure them in the bootloader.
@ -113,47 +113,47 @@ _NOTE_: The vmlinuz can be any name but that exact name has to be added to the c
## INITRD ## INITRD
* The initrd is used only while booting, unless you compile the kernel with the filesystem it resides on (initfs) * The initrd is used only while booting, unless you compile the kernel with the filesystem it resides on (initfs)
* OPTION 1: Compile the kernel with an initfs. * OPTION 1: Compile the kernel with an initfs.
* OPTION 2: Use mkinitrd * OPTION 2: Use mkinitrd.
`mkinitrd -o /boot/initrd.img` `mkinitrd -o /boot/initrd.img`
* OPTION 3: Use initramfs * OPTION 3: Use initramfs.
`update-initramfs -u` `update-initramfs -u`
## COMPILE A SINGLE MODULE ## COMPILE A SINGLE MODULE
* Only compile a module * Only compile a module.
`cd linux-<VERSION_NUMBER>/` `cd linux-<VERSION_NUMBER>/`
* Create files required for compiling external modules * Create files required for compiling external modules.
`make modules_prepare` `make modules_prepare`
* Compile modules * Compile modules.
`make M=<DIRECTORY_WHERE_MODULE_IS_LOCATED>` `make M=<DIRECTORY_WHERE_MODULE_IS_LOCATED>`
* Move module to <VERSION_NUMBER> * Move module to <VERSION_NUMBER>.
`cp <DIRECTORY_WHERE_MODULE_IS_LOCATED>/<NAME_OF_MODULE>.ko /lib/modules/$(uname -r)/` `cp <DIRECTORY_WHERE_MODULE_IS_LOCATED>/<NAME_OF_MODULE>.ko /lib/modules/$(uname -r)/`
* Or * Or
`cp <DIRECTORY_WHERE_MODULE_IS_LOCATED>/<NAME_OF_MODULE>.ko /lib/modules/` `cp <DIRECTORY_WHERE_MODULE_IS_LOCATED>/<NAME_OF_MODULE>.ko /lib/modules/`
* Update the modules * Update the modules.
`depmod -a` `depmod -a`
## DKMS ## DKMS
To update modules automatically when changing a kernel use DKMS. Requires the dkms package and the module source code. To update modules automatically when changing a kernel use DKMS. Requires the dkms package and the module source code.
* Create a directory * Create a directory.
`mkdir /usr/src/<MODULE>-<MODULE_VERSION>/` `mkdir /usr/src/<MODULE>-<MODULE_VERSION>/`
* Copy the source code of the module * Copy the source code of the module.
`cp -a * <DIRECTORY_WHERE_MODULE_IS_LOCATED>` `cp -a * <DIRECTORY_WHERE_MODULE_IS_LOCATED>`
* Create a dkms.conf file in the directory * Create a dkms.conf file in the directory.
`vi /usr/src/<MODULE>-<MODULE_VERSION>/dkms.conf` `vi /usr/src/<MODULE>-<MODULE_VERSION>/dkms.conf`
* Edit * Edit.
`PACKAGE_NAME="<MODULE>"` `PACKAGE_NAME="<MODULE>"`
`PACKAGE_VERSION="<MODULE_VERSION>"` `PACKAGE_VERSION="<MODULE_VERSION>"`
`BUILT_MODULE_NAME[0]="<MODULE>"` `BUILT_MODULE_NAME[0]="<MODULE>"`
`DEST_MODULE_LOCATION[0]="/kernel/<SECTION>/<MODULE>/"` `DEST_MODULE_LOCATION[0]="/kernel/<SECTION>/<MODULE>/"`
`AUTOINSTALL="yes"` `AUTOINSTALL="yes"`
* Add <MODULE> and <MODULE_VERSION> to DKMS * Add <MODULE> and <MODULE_VERSION> to DKMS.
`dkms add -m <MODULE> -v <MODULE_VERSION>` `dkms add -m <MODULE> -v <MODULE_VERSION>`
* Compile the module with DKMS * Compile the module with DKMS.
`dkms build -m <MODULE> -v <MODULE_VERSION>` `dkms build -m <MODULE> -v <MODULE_VERSION>`
* Install the module with DKMS * Install the module with DKMS.
`dkms install -m <MODULE> -v <MODULE_VERSION>` `dkms install -m <MODULE> -v <MODULE_VERSION>`
@ -161,38 +161,36 @@ To update modules automatically when changing a kernel use DKMS. Requires the dk
You can find patch files on the Linux Kernel Mailing List https://lkml.org/. You can find patch files on the Linux Kernel Mailing List https://lkml.org/.
* Go to kernel source tree * Go to kernel source tree.
`cd /usr/src/linux-<VERSION_NUMBER>` `cd /usr/src/linux-<VERSION_NUMBER>`
* Download the patch file there. * Download the patch file there.
* Following options assume is gzipped. * Following options assume is gzipped.
* OPTION 1: Git can be used to fallback from the patch and revert to the upatched source. * OPTION 1: Git can be used to fallback from the patch and revert to the upatched source.
* Uncompress patch file * Uncompress patch file.
`gunzip <PATCH_FILE>.gz` `gunzip <PATCH_FILE>.gz`
* Apply patch * Apply patch.
`git am <PATCH_FILE>` `git am <PATCH_FILE>`
* To revert a single patch * To revert a single patch.
`git apply -R <PATCH_FILE>` `git apply -R <PATCH_FILE>`
* To revert several patches first see the git log * To revert several patches first see the git log.
`git log --pretty=oneline --abbrev-commit` `git log --pretty=oneline --abbrev-commit`
* Select the proper number from the first column * Select the proper number from the first column.
`git reset --hard <FIRST_COLUMN_NUMBER>` `git reset --hard <FIRST_COLUMN_NUMBER>`
* OPTION 2: Patch command * OPTION 2: Patch command
* Uncompress patch file * Uncompress patch file.
`gunzip <PATCH_FILE>.gz` `gunzip <PATCH_FILE>.gz`
* The -p flag specifies a number of leading directories to remove, location is at the top of the patch file filename and is relative to the current directory. * The -p flag specifies a number of leading directories to remove, location is at the top of the patch file filename and is relative to the current directory.
`patch -p1 < <PATCH_FILE>` `patch -p1 < <PATCH_FILE>`
* OPTION 3: Use patch with zcat to use the uncrompressed file directly * OPTION 3: Use patch with zcat to use the uncrompressed file directly.
`zcat <PATCH_FILE>.gz | patch -p1` `zcat <PATCH_FILE>.gz | patch -p1`
* Compile kernel with the patch now included. * Compile kernel with the patch now included.
`make localmodconfig` `make localmodconfig`
* OPTION 4: Create a minimal kernel config file which necessarily needs to manually enable options afterwards to have a working system. Avaiable from kernel version 3.17-rc1 and up. * OPTION 4: Create a minimal kernel config file which necessarily needs to manually enable options afterwards to have a working system. Available from kernel version 3.17-rc1 and up.
`make tinyconfig` `make tinyconfig`
@ -203,27 +201,27 @@ You can find patch files on the Linux Kernel Mailing List https://lkml.org/.
* The N (or a blank space in menuconfig) flag in kernel configuration will not build selected option. * The N (or a blank space in menuconfig) flag in kernel configuration will not build selected option.
* List hardware and kernel modules in use * List hardware and kernel modules in use.
`lspci -k` `lspci -k`
`lspci -v` `lspci -v`
`cat /proc/cpuinfo` `cat /proc/cpuinfo`
`cat /proc/meminfo` `cat /proc/meminfo`
`lsmod` `lsmod`
* OPTION 1: Start a menu and browse options. Requires curses library but likely is already on your computer. Press "H" or "?" to see help. You can use the space bar to cycle between the available choices or press the appropriate key mentioned above. Pressing "/" to search for keywords * OPTION 1: Start a menu and browse options. Requires curses library but likely is already on your computer. Press "H" or "?" to see help. You can use the space bar to cycle between the available choices or press the appropriate key mentioned above. Pressing "/" to search for keywords.
make menuconfig `make menuconfig`
* OPTION 2: Will make questions on what kernel options to support when it finds new kernel options not marked on an existing config file (takes time and and if you are using a striped down config file it requires you knowledge) * OPTION 2: Will make questions on what kernel options to support when it finds new kernel options not marked on an existing config file (takes time and and if you are using a striped down config file it requires you knowledge).
`make oldconfig` `make oldconfig`
* OPTION 3: Will fill questions with default answers on what kernel options to support beyond your provided config file * OPTION 3: Will fill questions with default answers on what kernel options to support beyond your provided config file.
`make olddefconfig` `make olddefconfig`
## COMPILATION ## COMPILATION
Can take minutes to hours. Can take minutes to hours.
* Clean directory (wont touch the config file just remove all compiled files from the kernel tree) * Clean directory (wont touch the config file just remove all compiled files from the kernel tree).
`make clean` `make clean`
_NOTE_: The "-j<X>" flag, where <X> is the number of cores +1, is OPTIONAL and only goes if you have a processor with multiple cores. If you install ccache (OPTIONAL) you can speed up subsequent compilations by including CC="ccache gcc" after the "-j<X>" flag. _NOTE_: The "-j<X>" flag, where <X> is the number of cores +1, is OPTIONAL and only goes if you have a processor with multiple cores. If you install ccache (OPTIONAL) you can speed up subsequent compilations by including CC="ccache gcc" after the "-j<X>" flag.
@ -238,12 +236,12 @@ _NOTE_: The "-j<X>" flag, where <X> is the number of cores +1, is OPTIONAL and o
`make -j<X> bzImage` `make -j<X> bzImage`
## MOVE KERNEL IMAGE ## MOVE KERNEL IMAGE
* OPTION B1: Copy the new kernel to /boot, create the initrd file and change the GRUB menu * OPTION B1: Copy the new kernel to /boot, create the initrd file and change the GRUB menu.
`cp arch/<YOUR_ARCHITECTURE>/boot/bzImage /boot/vmlinuz` `cp arch/<YOUR_ARCHITECTURE>/boot/bzImage /boot/vmlinuz`
* Not required for booting but some processes need it * Not required for booting but some processes need it.
`cp System.map /boot` `cp System.map /boot`
* OPTION B2: Automatically move kernel to /boot (and in certain distros, symlink the new kernel to /boot/vmlinuz and update the bootloader configuration) * OPTION B2: Automatically move kernel to /boot (and in certain distros, symlink the new kernel to /boot/vmlinuz and update the bootloader configuration).
`make install` `make install`
@ -252,7 +250,7 @@ _NOTE_: The "-j<X>" flag, where <X> is the number of cores +1, is OPTIONAL and o
`make -j<X> modules` `make -j<X> modules`
## MOVE MODULES ## MOVE MODULES
* Copy generated kernel modules to /lib/modules/<KERNEL_VERSION>/ * Copy generated kernel modules to /lib/modules/<KERNEL_VERSION>/.
`make modules_install` `make modules_install`
_NOTE_: The vmlinuz can be any name but that exact name has to be added to the configuration file of your bootloader of choice. Usually a version number is appended to the new kernel image. This has the advantage to avoid replacing a current kernel and having a fallback as backup to boot. You can set to boot from any image in the bootloader once you configure them in the bootloader. _NOTE_: The vmlinuz can be any name but that exact name has to be added to the configuration file of your bootloader of choice. Usually a version number is appended to the new kernel image. This has the advantage to avoid replacing a current kernel and having a fallback as backup to boot. You can set to boot from any image in the bootloader once you configure them in the bootloader.
@ -260,47 +258,47 @@ _NOTE_: The vmlinuz can be any name but that exact name has to be added to the c
## INITRD ## INITRD
* The initrd is used only while booting, unless you compile the kernel with the filesystem it resides on (initfs) * The initrd is used only while booting, unless you compile the kernel with the filesystem it resides on (initfs)
* OPTION 1: Compile the kernel with an initfs. * OPTION 1: Compile the kernel with an initfs.
* OPTION 2: Use mkinitrd * OPTION 2: Use mkinitrd.
`mkinitrd -o /boot/initrd.img` `mkinitrd -o /boot/initrd.img`
* OPTION 3: Use initramfs * OPTION 3: Use initramfs.
`update-initramfs -u` `update-initramfs -u`
## COMPILE A SINGLE MODULE ## COMPILE A SINGLE MODULE
* Only compile a module * Only compile a module.
`cd linux-<VERSION_NUMBER>/` `cd linux-<VERSION_NUMBER>/`
* Create files required for compiling external modules * Create files required for compiling external modules.
`make modules_prepare` `make modules_prepare`
* Compile modules * Compile modules.
`make M=<DIRECTORY_WHERE_MODULE_IS_LOCATED>` `make M=<DIRECTORY_WHERE_MODULE_IS_LOCATED>`
* Move module to <VERSION_NUMBER> * Move module to <VERSION_NUMBER>.
`cp <DIRECTORY_WHERE_MODULE_IS_LOCATED>/<NAME_OF_MODULE>.ko /lib/modules/\`uname -r\`/` `cp <DIRECTORY_WHERE_MODULE_IS_LOCATED>/<NAME_OF_MODULE>.ko /lib/modules/$(uname -r)/`
* Or * Or
`cp <DIRECTORY_WHERE_MODULE_IS_LOCATED>/<NAME_OF_MODULE>.ko /lib/modules/` `cp <DIRECTORY_WHERE_MODULE_IS_LOCATED>/<NAME_OF_MODULE>.ko /lib/modules/`
* Update the modules * Update the modules.
`depmod -a` `depmod -a`
## DKMS ## DKMS
To update modules automatically when changing a kernel use DKMS. Requires the dkms package and the module source code. To update modules automatically when changing a kernel use DKMS. Requires the dkms package and the module source code.
* Create a directory * Create a directory.
`mkdir /usr/src/<MODULE>-<MODULE_VERSION>/` `mkdir /usr/src/<MODULE>-<MODULE_VERSION>/`
* Copy the source code of the module * Copy the source code of the module.
`cp -a * <DIRECTORY_WHERE_MODULE_IS_LOCATED>` `cp -a * <DIRECTORY_WHERE_MODULE_IS_LOCATED>`
* Create a dkms.conf file in the directory * Create a dkms.conf file in the directory.
`vi /usr/src/<MODULE>-<MODULE_VERSION>/dkms.conf` `vi /usr/src/<MODULE>-<MODULE_VERSION>/dkms.conf`
* Edit * Edit.
`PACKAGE_NAME="<MODULE>"` `PACKAGE_NAME="<MODULE>"`
`PACKAGE_VERSION="<MODULE_VERSION>"` `PACKAGE_VERSION="<MODULE_VERSION>"`
`BUILT_MODULE_NAME[0]="<MODULE>"` `BUILT_MODULE_NAME[0]="<MODULE>"`
`DEST_MODULE_LOCATION[0]="/kernel/<SECTION>/<MODULE>/"` `DEST_MODULE_LOCATION[0]="/kernel/<SECTION>/<MODULE>/"`
`AUTOINSTALL="yes"` `AUTOINSTALL="yes"`
* Add <MODULE> and <MODULE_VERSION> to DKMS * Add <MODULE> and <MODULE_VERSION> to DKMS.
`dkms add -m <MODULE> -v <MODULE_VERSION>` `dkms add -m <MODULE> -v <MODULE_VERSION>`
* Compile the module with DKMS * Compile the module with DKMS.
`dkms build -m <MODULE> -v <MODULE_VERSION>` `dkms build -m <MODULE> -v <MODULE_VERSION>`
* Install the module with DKMS * Install the module with DKMS.
`dkms install -m <MODULE> -v <MODULE_VERSION>` `dkms install -m <MODULE> -v <MODULE_VERSION>`
@ -308,30 +306,30 @@ To update modules automatically when changing a kernel use DKMS. Requires the dk
You can find patch files on the Linux Kernel Mailing List https://lkml.org/. You can find patch files on the Linux Kernel Mailing List https://lkml.org/.
* Go to kernel source tree * Go to kernel source tree.
`cd /usr/src/linux-<VERSION_NUMBER>` `cd /usr/src/linux-<VERSION_NUMBER>`
* Download the patch file there. * Download the patch file there.
* Following options assume is gzipped. * Following options assume is gzipped.
* OPTION 1: Git can be used to fallback from the patch and revert to the upatched source. * OPTION 1: Git can be used to fallback from the patch and revert to the upatched source.
* Uncompress patch file * Uncompress patch file.
`gunzip <PATCH_FILE>.gz` `gunzip <PATCH_FILE>.gz`
* Apply patch * Apply patch.
`git am <PATCH_FILE>` `git am <PATCH_FILE>`
* To revert a single patch * To revert a single patch.
`git apply -R <PATCH_FILE>` `git apply -R <PATCH_FILE>`
* To revert several patches first see the git log * To revert several patches first see the git log.
`git log --pretty=oneline --abbrev-commit` `git log --pretty=oneline --abbrev-commit`
* Select the proper number from the first column * Select the proper number from the first column.
`git reset --hard <FIRST_COLUMN_NUMBER>` `git reset --hard <FIRST_COLUMN_NUMBER>`
* OPTION 2: Patch command * OPTION 2: Patch command
* Uncompress patch file * Uncompress patch file.
`gunzip <PATCH_FILE>.gz` `gunzip <PATCH_FILE>.gz`
* The -p flag specifies a number of leading directories to remove, location is at the top of the patch file filename and is relative to the current directory. * The -p flag specifies a number of leading directories to remove, location is at the top of the patch file filename and is relative to the current directory.
`patch -p1 < <PATCH_FILE>` `patch -p1 < <PATCH_FILE>`
* OPTION 3: Use patch with zcat to use the uncrompressed file directly * OPTION 3: Use patch with zcat to use the uncrompressed file directly.
`zcat <PATCH_FILE>.gz | patch -p1` `zcat <PATCH_FILE>.gz | patch -p1`