内核参数

来自 Arch Linux 中文维基
(重定向自Kernel parameter

本文内容或本节内容已经过期。

原因: 需要更新同步翻译英文 (在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).

参见[编辑 | 编辑源代码]