內核的命令行參數

    內核將內核命令行的參數解析爲“-‌-”。如果內核不識別參數,也不包含“.”,那麼參數會被傳遞給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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章