内核将内核命令行的参数解析为“--”。如果内核不识别参数,也不包含“.”,那么参数会被传递给init:带“=”的参数会被传递给init环境,其他会作为命令行参数传递给init。“ -- ”之后的所有内容都作为参数被传递给init。
可以通过两种方式指定模块参数:通过带有模块名称前缀的内核命令行,或通过modprobe,例如:
(kernel command line) usbcore.blinkenlights=1
(modprobe command line) modprobe usbcore blinkenlights=1
内置在内核中的模块的参数需要在内核命令行上明确规定。modprobe查看内核命令行(/proc/cmdline)并在加载模块时收集模块参数,因此内核命令行也可用于可加载模块。
参数名称中的连字符(破折号)和下划线相同,因此:
log_buf_len=1M print-fatal-signals=1
也可以输入为:
log-buf-len=1M print_fatal_signals=1
双引号可用于保护值中的空格,例如:
param="spaces in here"
CPU列表
一些内核参数将CPU列表作为值,例如isolcpus,nohz_full,irqaffinity,rcu_nocbs。该列表的格式为:
<cpu number>,…,<cpu number>
或者
<cpu number>-<cpu number> (必须为升序)
或混合起来:
<cpu number>,…,<cpu number>-<cpu number>
请注意,对于某个范围的特殊情况,可以将该范围拆分为大小相等的组,对于每个组,使用该组开头的某个量:
<cpu number>-cpu number>:<used size>/<group size>
例如,可以将以下参数添加到命令行:
isolcpus=1,2,10-20,100-2000:2/25
其中最后一项代表CPU 100,101,125,126,150,151 …
命令“modinfo -p ${modulename}”显示可加载模块的所有参数的当前列表。可加载模块加载到正在运行的内核后,还会在 /sys/module/${modulename}/parameters/ 显示其参数。其中一些参数可以在运行时通过 echo -n ${value} > /sys/module/${modulename}/parameters/${parm} 命令更改。
示例:
# modinfo -p loop
max_loop:Maximum number of loop devices (int)
max_part:Maximum number of partitions per loop device (int)
# modinfo -p lp
parport: (array of charp)
reset: (bool)
# modinfo -p acpi
acpi_pstate_strict:value 0 or non-zero. non-zero -> strict ACPI checks are performed during frequency changes. (uint)
# modinfo -p kvm
ignore_msrs: (bool)
min_timer_period_us: (uint)
kvmclock_periodic_sync: (bool)
tsc_tolerance_ppm: (uint)
lapic_timer_advance_ns: (uint)
vector_hashing: (bool)
halt_poll_ns: (uint)
halt_poll_ns_grow: (uint)
halt_poll_ns_shrink: (uint)
以下列出的参数仅在启用了某些内核构建选项且存在相应硬件的情况下才有效。每个描述开头方括号中的文本说明了参数适用的限制。
ACPI ACPI support is enabled.
AGP AGP (Accelerated Graphics Port) is enabled.
ALSA ALSA sound support is enabled.
APIC APIC support is enabled.
APM Advanced Power Management support is enabled.
ARM ARM architecture is enabled.
ARM64 ARM64 architecture is enabled.
AX25 Appropriate AX.25 support is enabled.
CLK Common clock infrastructure is enabled.
CMA Contiguous Memory Area support is enabled.
DRM Direct Rendering Management support is enabled.
DYNAMIC_DEBUG Build in debug messages and enable them at runtime
EDD BIOS Enhanced Disk Drive Services (EDD) is enabled
EFI EFI Partitioning (GPT) is enabled
EIDE EIDE/ATAPI support is enabled.
EVM Extended Verification Module
FB The frame buffer device is enabled.
FTRACE Function tracing enabled.
GCOV GCOV profiling is enabled.
HW Appropriate hardware is enabled.
IA-64 IA-64 architecture is enabled.
IMA Integrity measurement architecture is enabled.
IOSCHED More than one I/O scheduler is enabled.
IP_PNP IP DHCP, BOOTP, or RARP is enabled.
IPV6 IPv6 support is enabled.
ISAPNP ISA PnP code is enabled.
ISDN Appropriate ISDN support is enabled.
ISOL CPU Isolation is enabled.
JOY Appropriate joystick support is enabled.
KGDB Kernel debugger support is enabled.
KVM Kernel Virtual Machine support is enabled.
LIBATA Libata driver is enabled
LP Printer support is enabled.
LOOP Loopback device support is enabled.
M68k M68k architecture is enabled.
These options have more detailed description inside of
Documentation/m68k/kernel-options.rst.
MDA MDA console support is enabled.
MIPS MIPS architecture is enabled.
MOUSE Appropriate mouse support is enabled.
MSI Message Signaled Interrupts (PCI).
MTD MTD (Memory Technology Device) support is enabled.
NET Appropriate network support is enabled.
NUMA NUMA support is enabled.
NFS Appropriate NFS support is enabled.
OF Devicetree is enabled.
OSS OSS sound support is enabled.
PV_OPS A paravirtualized kernel is enabled.
PARIDE The ParIDE (parallel port IDE) subsystem is enabled.
PARISC The PA-RISC architecture is enabled.
PCI PCI bus support is enabled.
PCIE PCI Express support is enabled.
PCMCIA The PCMCIA subsystem is enabled.
PNP Plug & Play support is enabled.
PPC PowerPC architecture is enabled.
PPT Parallel port support is enabled.
PS2 Appropriate PS/2 support is enabled.
RAM RAM disk support is enabled.
RDT Intel Resource Director Technology.
S390 S390 architecture is enabled.
SCSI Appropriate SCSI support is enabled.
A lot of drivers have their options described inside
the Documentation/scsi/ sub-directory.
SECURITY Different security models are enabled.
SELINUX SELinux support is enabled.
APPARMOR AppArmor support is enabled.
SERIAL Serial support is enabled.
SH SuperH architecture is enabled.
SMP The kernel is an SMP kernel.
SPARC Sparc architecture is enabled.
SWSUSP Software suspend (hibernation) is enabled.
SUSPEND System suspend states are enabled.
TPM TPM drivers are enabled.
TS Appropriate touchscreen support is enabled.
UMS USB Mass Storage support is enabled.
USB USB support is enabled.
USBHID USB Human Interface Device support is enabled.
V4L Video For Linux support is enabled.
VMMIO Driver for memory mapped virtio devices is enabled.
VGA The VGA console has been enabled.
VT Virtual terminal support is enabled.
WDT Watchdog support is enabled.
XT IBM PC/XT MFM hard disk support is enabled.
X86-32 X86-32, aka i386 architecture is enabled.
X86-64 X86-64 architecture is enabled.
More X86-64 boot options can be found in
Documentation/x86/x86_64/boot-options.rst.
X86 Either 32-bit or 64-bit x86 (same as X86-32+X86-64)
X86_UV SGI UV support is enabled.
XEN Xen support is enabled
此外,下面的文本表示该选项:
BUGS= Relates to possible processor bugs on the said processor.
KNL Is a kernel start-up parameter.
BOOT Is a boot loader parameter.
用BOOT表示的参数实际上是由引导加载程序解释的,对内核没有直接意义。在没有特殊需要或参考<Documentation/x86/boot.rst>的情况下,不要修改引导加载程序参数的语法。
示例:
cachesize= [BUGS=X86-32] Override level 2 CPU cache size detection.
Sometimes CPU hardware bugs make them report the cache
size incorrectly. The kernel will attempt work arounds
to fix known problems, but for some CPUs it is not
possible to determine what the correct size should be.
This option provides an override for these situations.
在x86 32位架构下,有时CPU硬件错误会使它们错误地报告二级缓存大小。通过设置cachesize参数,覆盖错误的缓存大小。
init= [KNL]
Format: <full_path>
Run specified binary instead of /sbin/init as init
process.
init参数是内核启动时加载的。表示运行指定的二进制文件而不是/sbin/init作为init进程。
initrd= [BOOT] Specify the location of the initial ramdisk
initrd参数指定初始ramdisk的位置。
还有一些特定于arch的内核参数在这里没有记录。
请注意,下面列出的所有内核参数都是区分大小写的,任何参数名称后尾随=表示该参数将作为环境变量输入,而如果没有该参数,则表示该参数将作为内核参数显示,在系统启动后由运行的程序通过/proc/cmdline读取。
内核参数的数量不受限制,但完整命令行的长度(包括空格等参数)被限制为固定的字符数。此限制取决于体系结构,介于256到4096个字符之间。它在文件./include/asm/setup.h中被定义为 COMMAND_LINE_SIZE 。
示例:
# cat /usr/include/asm-generic/setup.h
#ifndef __ASM_GENERIC_SETUP_H
#define __ASM_GENERIC_SETUP_H
#define COMMAND_LINE_SIZE 512
#endif /* __ASM_GENERIC_SETUP_H */
最后,[KMG]后缀通常在许多内核参数值之后出现。这些“ K”,“ M”和“ G”字母代表二进制乘数“ Kilo”,“ Mega”和“ Giga”,分别等于2^10 、 2^20 和 2^30个字节。这样的字母后缀也可以完全省略。
内核的命令行参数太多了,我不翻译了。
参考文档
https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html