內核參數

出自 Arch Linux 中文维基

本文內容或本節內容已經過期。

原因: 需要更新同步翻譯英文 (在Talk:內核參數討論)

共有三種辦法向內核傳遞參數以控制其行為:

  1. 在編譯內核時:在內核的 config 文件中。詳見內核#編譯
  2. 在內核啟動時:通過命令行參數(通常通過啟動管理器設置)。
  3. 在運行時:通過 /proc/sys/(參見 sysctl)和 /sys/ 中的文件。
提示:可加載模塊的選項可通過 /etc/modprobe.d/ 中的 .conf 文件設置。參見 Kernel module#Using files in /etc/modprobe.d/

不同的方式有不同的命令名稱、是否可見以及設置方式。本文僅說明第二種方式(內核命令行),並記錄適用 Arch linux 內核的常用參數。

大部分參數和某個子系統相關,需要在編譯或加載時加入子系統,而且相關硬件需要存在。

內核命令行參數的格式為 parameterparameter=value

注意: 內核參數均區分大小寫。

配置[編輯 | 編輯原始碼]

注意:
  • 通過 cat /proc/cmdline 可以查看當前適用的命令行參數,驗證修改是否生效。
  • Arch Linux 安裝鏡像BIOS 系統上使用 Syslinux, 在 UEFI 系統上使用 GRUB.

內核參數可以在啟動時臨時修改,也可以永久性寫到啟動管理器的配置文件中,永遠起作用。

下面示例:把參數quietsplash 加到啟動管理器 Syslinux, GRUB, GRUB LegacyLILO中.

Syslinux[編輯 | 編輯原始碼]

  • 當出現啟動選擇菜單的時候,按 Tab 進入修改模式:
linux /boot/vmlinuz-linux root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3 rw initrd=/boot/initramfs-linux.img quiet splash
Enter 鍵以當前設置啟動.
  • 要將設置永久生效,編輯 /boot/syslinux/syslinux.cfg 並添加 APPEND 行:
APPEND root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3 rw quiet splash

更多詳情請見Syslinux

systemd-boot[編輯 | 編輯原始碼]

  • 當啟動菜單出現時 按 e進入編輯界面:
initrd=\initramfs-linux.img root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3 rw quiet splash
Enter 即可按照輸入的參數啟動。
注意:
  • 如果沒有設置顯示啟動菜單, 你需要按住Space啟動電腦來進入啟動菜單 。
  • 如果不能夠從啟動菜單上進行編輯,修改 /boot/loader/loader.conf 加入 editor 1 來開啟編輯功能。
  • 如果想永久加入參數,編輯 /boot/loader/entries/arch.conf (假設你已經設置好了 EFI system partition) 的options 行:
options root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3 rw quiet splash

更多信息請參見 systemd-boot .

GRUB[編輯 | 編輯原始碼]

  • 在菜單出現後按 e 然後將它們添加至 linux 行:
linux /boot/vmlinuz-linux root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3 rw quiet splash
b 以便用這些參數啟動。
  • 要使改變在重啟後仍生效,您可以手動編輯 /boot/grub/grub.cfg 中的如上內容。對於初學者,建議:
編輯 /etc/default/grub 並將您的內核選項添加至 GRUB_CMDLINE_LINUX_DEFAULT 行:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
然後重新生成 grub.cfg 文件:
# grub-mkconfig -o /boot/grub/grub.cfg

有關配置GRUB的更多信息,請參閱 GRUB

GRUB Legacy[編輯 | 編輯原始碼]

  • Press e when the menu shows up and add them on the kernel line:
kernel /boot/vmlinuz-linux root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3 rw quiet splash
Press b to boot with these parameters.
  • To make the change persistent after reboot, edit /boot/grub/menu.lst and add them to the kernel line, exactly like above.

For more information on configuring GRUB Legacy, see the GRUB Legacy article.

LILO[編輯 | 編輯原始碼]

  • Add them to /etc/lilo.conf:
image=/boot/vmlinuz-linux
        ...
        quiet splash

For more information on configuring LILO, see the LILO article.

rEFInd[編輯 | 編輯原始碼]

  • Press +, F2, or Insert on the desired menu entry and press it again on the submenu entry. Add kernel parameters at the end of the string:
root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3 rw initrd=\boot\initramfs-linux.img quiet splash
Press Enter to boot with these parameters.
  • To make the change persistent after reboot, edit /boot/refind_linux.conf and append them between the quotes in all required lines, for example
"Boot using default options"   "root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3 rw quiet splash"
  • If you have disabled auto-detection of OSes in rEFInd and are defining OS stanzas instead in esp/EFI/refind/refind.conf to load your OSes, you can edit it like:
menuentry "Arch Linux" {
	...
	options  "root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3 rw quiet splash"
	...
}

For more information on configuring rEFInd, see the rEFInd article.

EFISTUB[編輯 | 編輯原始碼]

參閱 EFISTUB#Using UEFI directly.

dracut[編輯 | 編輯原始碼]

dracut 可以將內核參數嵌入 initramfs, 跳過啟動加載器的配置,參考: dracut#Kernel command line options.

Hijacking cmdline[編輯 | 編輯原始碼]

Even without access to your bootloader it is possible to change your kernel parameters to enable debugging (if you have root access). This can be accomplished by overwriting /proc/cmdline which stores the kernel parameters. However /proc/cmdline is not writable even as root, so this hack is accomplished by using a bind mount to mask the path.

First create a file containing the desired kernel parameters

/root/cmdline
root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3 ro console=tty1 logo.nologo debug

Then use a bind mount to overwrite the parameters

# mount -n --bind -o ro /root/cmdline /proc/cmdline

The -n option skips adding the mount to /etc/mtab, so it will work even if root is mounted read-only. You can cat /proc/cmdline to confirm that your change was successful.

參數列表[編輯 | 編輯原始碼]

本表並不完整。所有選項的完整列表請參見內核文檔

參數 描述
init Run specified binary instead of /sbin/init as init process. The systemd-sysvcompat package symlinks /sbin/init to /usr/lib/systemd/systemd to use systemd. Set it to /bin/sh to boot to the shell.
initrd Specify the location of the initial ramdisk. For UEFI boot managers and EFISTUB, the path must be specified using backslashes (\) as path separators.
cryptdevice Specify the location of a dm-crypt-encrypted partition plus a device mapper name.
debug Enable kernel debugging (events log level).
lsm Set the initialisation order of the Linux security modules, used to enable AppArmor, SELinux or TOMOYO.
maxcpus Maximum number of processors that an SMP kernel will bring up during bootup.
mem Force usage of a specific amount of memory to be used.
netdev Network devices parameters.
nomodeset Disable Kernel mode setting.
panic Time before automatic reboot on kernel panic.
resume Specify a swap device to use when waking from hibernation.
ro Mount root device read-only on boot (default1).
root Root filesystem. See init/do_mounts.c for kernel's supported device name formats. Note that an initramfs with udev supports more name formats.
rootflags Root filesystem mount options. Useful for setting options that cannot be applied by remounting (i.e. by systemd-remount-fs.service(8)). For example, the discard option of an XFS root volume.
rw Mount root device read-write on boot.
systemd.unit Boot to a specified target.
video Override framebuffer video defaults.

1 mkinitcpio uses ro as default value when neither rw or ro is set by the boot loader. Boot loaders may set the value to use, for example GRUB uses rw by default (see FS#36275 as a reference).

參見[編輯 | 編輯原始碼]