mirror of
https://github.com/mayfrost/guides.git
synced 2024-11-28 02:11:46 +00:00
Update KERNEL.md
This commit is contained in:
parent
e012afee78
commit
8ccbe0f886
80
KERNEL.md
80
KERNEL.md
@ -1,20 +1,27 @@
|
||||
# KERNEL
|
||||
|
||||
Compiling a kernel has the advantage to make it as minimal and featureful as you want, you can test kernel patches and tweaks and optimize your system.
|
||||
* You need the kernel source, build tools, the kernel configuration file (__optional__), and root or sudo privileges for the final stages of the process.
|
||||
* You need the kernel source, build tools, the kernel configuration file (__optional__), and __root__ or __sudo__ privileges for the final stages of the process.
|
||||
* Back up all of your files.
|
||||
* Have a distro in a Live CD or USB at hand just in case.
|
||||
* Give yourself a cup of tea or coffee while you wait to compile.
|
||||
|
||||
## PREPARATIONS
|
||||
* To see which version the new kernel source.
|
||||
* To see which version the new kernel source is.
|
||||
`head /usr/src/linux/Makefile`
|
||||
* To see which version the current kernel.
|
||||
* To see which version the current kernel is.
|
||||
`uname -r`
|
||||
* List hardware and kernel modules in use (take note to know what kernel modules are appropriate).
|
||||
`lspci -k`
|
||||
`lspci -v`
|
||||
`cat /proc/cpuinfo`
|
||||
`cat /proc/meminfo`
|
||||
`lsmod`
|
||||
|
||||
## GETTING THE KERNEL SOURCE
|
||||
|
||||
* __OPTIONAL__: Is standard to download Linux sources under /usr/src/, link the downloaded kernel tree to /usr/src/linux-<VERSION_NUMBER> and work there, but is not a requirement.
|
||||
### OPTIONAL:
|
||||
Is standard to download Linux sources under __/usr/src/__, to link the downloaded kernel tree to __/usr/src/linux-<VERSION_NUMBER>__ and work there, but is not a requirement.
|
||||
`cd /usr/src/`
|
||||
`ln -s linux-<VERSION_NUMBER> linux`
|
||||
|
||||
@ -26,25 +33,27 @@ Compiling a kernel has the advantage to make it as minimal and featureful as you
|
||||
* Enter directory.
|
||||
`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).
|
||||
* Clean the directory (wont touch the config file just remove all compiled files from the kernel tree).
|
||||
`make clean`
|
||||
* Remove compiled files from the kernel tree AND the configuration file if there are any (backup your configuration file before this if you have one in the current directory).
|
||||
`make mrproper`
|
||||
|
||||
|
||||
## GENERATING A CONFIGURATION FILE
|
||||
This process makes a "__.config__" file in the kernel source directory determines which drivers are built and other support. And turn on only the minimal set of options you need.
|
||||
This process makes a "__.config__" file in the kernel source directory determines which drivers are built and other support. There are three options here, turn on only the minimal set of options you need.
|
||||
|
||||
* OPTION 1: Use the config file of another kernel or the current system.
|
||||
* __OPTION 1__: Use the config file of another kernel or the current system.
|
||||
`cp -v /boot/config-$(uname -r) .config`
|
||||
* Or in some distros you can take it from the running kernel.
|
||||
`zcat /proc/config.gz > .config`
|
||||
|
||||
* OPTION 2: Make a default config file (may or may not not have the options you are currently using).
|
||||
* __OPTION 2__: Make a default config file (may or may not not have the options you are currently using).
|
||||
`make defconfig`
|
||||
|
||||
* OPTION 3: Generate a config file disabling all options not loaded by the currently running kernel and will make questions on what kernel options to support when it finds new kernel options. Could have problems with peripherals not in use at that time unless you plug all devices like __USBs__. Attach devices you use or insert modules manually with the insmod command before using this option. Available from kernel version 2.6.32 and up.
|
||||
* __OPTION 3__: Generate a config file disabling all options not loaded by the currently running kernel and will make questions on what kernel options to support when it finds new kernel options. Could have problems with peripherals not in use at that time unless you plug all devices like __USBs__. Attach devices you use or insert modules manually with the insmod command before using this option. Available from kernel version 2.6.32 and up.
|
||||
`make localmodconfig`
|
||||
|
||||
* 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.
|
||||
* __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`
|
||||
|
||||
|
||||
@ -54,42 +63,33 @@ This process makes a "__.config__" file in the kernel source directory determine
|
||||
* The M flag in kernel configuration compiles options as separate modules.
|
||||
* The N (or a blank space in __menuconfig__) flag in kernel configuration will not build selected option.
|
||||
|
||||
|
||||
* List hardware and kernel modules in use.
|
||||
`lspci -k`
|
||||
`lspci -v`
|
||||
`cat /proc/cpuinfo`
|
||||
`cat /proc/meminfo`
|
||||
`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`
|
||||
|
||||
* 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`
|
||||
|
||||
* 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`
|
||||
|
||||
|
||||
## COMPILATION
|
||||
Can take minutes to hours.
|
||||
|
||||
* Clean directory (wont touch the config file just remove all compiled files from the kernel tree).
|
||||
`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__ (__THIS IS OPTIONAL__) you can speed up subsequent compilations by including __CC="ccache gcc"__ after the __-j<X>__ flag.
|
||||
`make -j<X> <OTHER_FLAGS>`
|
||||
And with ccache
|
||||
`make -j<X> CC="ccache gcc" <OTHER_FLAGS>`
|
||||
|
||||
* __OPTION A__: Compile and move everything to its place. The "__all__" flag makes modules AND the __bzImage__ at the same time (replaces "__bzImage__" and "__modules__" flags).
|
||||
For compilation you have two options, __OPTION A__ is the easiest and is a single command. __OPTION B__ is here for teaching purposes.
|
||||
|
||||
### OPTION A: One command
|
||||
Compile and move everything to its place. The "__all__" flag makes modules AND the __bzImage__ at the same time (replaces "__bzImage__" and "__modules__" flags).
|
||||
`make -j<X> all modules_install install`
|
||||
|
||||
* __OPTION B__: One by one
|
||||
|
||||
### OPTION B: One by one
|
||||
* If your configuration does not contain answers for all of the options, especially if they are new and not currently included in your running kernel, you will need to answer the prompts for these options.
|
||||
`make -j<X> bzImage`
|
||||
|
||||
## MOVE KERNEL IMAGE
|
||||
* __OPTION B1__: Copy the new kernel to __/boot__.
|
||||
`cp arch/<YOUR_ARCHITECTURE>/boot/bzImage /boot/vmlinuz`
|
||||
* Not required for booting but some processes need it.
|
||||
@ -99,11 +99,9 @@ __NOTE__: The __-j<X>__ flag, where __<X>__ is the number of cores +1, is __OPTI
|
||||
`make install`
|
||||
|
||||
|
||||
## BUILD MODULES
|
||||
### BUILD MODULES
|
||||
* Compile individual files for each question you answered M during kernel config. The object code is linked against your freshly built kernel. (For questions answered __Y__, these are already part of __vmlinuz__, and for questions answered __N__ they are skipped). Modules end with __.ko__.
|
||||
`make -j<X> modules`
|
||||
|
||||
## MOVE MODULES
|
||||
* Copy generated kernel modules to __/lib/modules/<KERNEL_VERSION>/__.
|
||||
`make modules_install`
|
||||
|
||||
@ -118,7 +116,8 @@ __NOTE__: The __vmlinuz__ can be any name but that exact name has to be added to
|
||||
`update-initramfs -u`
|
||||
|
||||
|
||||
## COMPILE A SINGLE MODULE
|
||||
## MODULES
|
||||
### COMPILE A SINGLE MODULE
|
||||
* Only compile a module.
|
||||
`cd linux-<VERSION_NUMBER>/`
|
||||
* Create files required for compiling external modules.
|
||||
@ -133,7 +132,7 @@ __NOTE__: The __vmlinuz__ can be any name but that exact name has to be added to
|
||||
`depmod -a`
|
||||
|
||||
|
||||
## DKMS
|
||||
### DKMS
|
||||
To update modules automatically when changing a kernel use __DKMS__. Requires the __dkms__ package and the proper module source code.
|
||||
* Create a directory.
|
||||
`mkdir /usr/src/<MODULE>-<MODULE_VERSION>/`
|
||||
@ -163,7 +162,10 @@ You can find patch files on the Linux Kernel Mailing List https://lkml.org/.
|
||||
* Download the patch file there.
|
||||
* Following options assume is __gzipped__.
|
||||
|
||||
* OPTION 1: Git can be used to fallback from the patch and revert to the upatched source.
|
||||
You have threee options to patch the kernel.
|
||||
|
||||
### OPTION 1: Git
|
||||
Git can be used to fallback from the patch and revert to the upatched source.
|
||||
* Uncompress patch file.
|
||||
`gunzip <PATCH_FILE>.gz`
|
||||
* Apply patch.
|
||||
@ -175,14 +177,14 @@ You can find patch files on the Linux Kernel Mailing List https://lkml.org/.
|
||||
* Select the proper number from the first column.
|
||||
`git reset --hard <FIRST_COLUMN_NUMBER>`
|
||||
|
||||
* OPTION 2: Patch command
|
||||
### OPTION 2: Patch command
|
||||
* Uncompress patch file.
|
||||
`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.
|
||||
`patch -p1 < <PATCH_FILE>`
|
||||
|
||||
* OPTION 3: Use patch with __zcat__ to use the uncrompressed file directly.
|
||||
### OPTION 3: Patch with __zcat__ to use the uncrompressed file directly.
|
||||
`zcat <PATCH_FILE>.gz | patch -p1`
|
||||
|
||||
|
||||
* Compile kernel with the patch now included.
|
||||
Compile kernel with the patch now included.
|
||||
|
Loading…
Reference in New Issue
Block a user