如何在 Fedora 30 中设置内核命令行参数
内核
![](/data/attachment/album/201904/12/113338zsp8y9agsj8jyhja.jpg)


在调试或试验内核时，向内核命令行添加选项是一项常见任务。即将发布的 Fedora 30 版本改为使用 Bootloader 规范（[BLS](https://fedoraproject.org/wiki/Changes/BootLoaderSpecByDefault)）。根据你修改内核命令行选项的方式，你的工作流可能会更改。继续阅读获取更多信息。


要确定你的系统是使用 BLS 还是旧的规范，请查看文件：



```
/etc/default/grub
```

如果你看到：



```
GRUB_ENABLE_BLSCFG=true
```

看到这个，你运行的是 BLS，你可能需要更改设置内核命令行参数的方式。


如果你只想修改单个内核条目（例如，暂时解决显示问题），可以使用 `grubby` 命令：



```
$ grubby --update-kernel /boot/vmlinuz-5.0.1-300.fc30.x86_64 --args="amdgpu.dc=0"
```

要删除内核参数，可以传递 `--remove-args` 参数给 `grubby`：



```
$ grubby --update-kernel /boot/vmlinuz-5.0.1-300.fc30.x86_64 --remove-args="amdgpu.dc=0"
```

如果有应该添加到每个内核命令行的选项（例如，你希望禁用 `rdrand` 指令生成随机数），则可以运行 `grubby` 命令：



```
$ grubby --update-kernel=ALL --args="nordrand"
```

这将更新所有内核条目的命令行，并保存作为将来条目的命令行选项。


如果你想要从所有内核中删除该选项，则可以再次使用 `--remove-args` 和 `--update-kernel=ALL`：



```
$ grubby --update-kernel=ALL --remove-args="nordrand"
```



---


via: <https://fedoramagazine.org/setting-kernel-command-line-arguments-with-fedora-30/>


作者：[Laura Abbott](https://fedoramagazine.org/makes-fedora-kernel/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Adding options to the kernel command line is a common task when debugging or experimenting with the kernel. The upcoming Fedora 30 release made a change to use Bootloader Spec ([BLS](https://fedoraproject.org/wiki/Changes/BootLoaderSpecByDefault)). Depending on how you are used to modifying kernel command line options, your workflow may now change. Read on for more information.

To determine if your system is running with BLS or the older layout, look in the file

If you only want to modify a single kernel entry (for example, to temporarily work around a display problem) you can use a grubby command

$ grubby --update-kernel /boot/vmlinuz-5.0.1-300.fc30.x86_64 --args="amdgpu.dc=0"

To remove a kernel argument, you can use the

argument to grubby

$ grubby --update-kernel /boot/vmlinuz-5.0.1-300.fc30.x86_64 --remove-args="amdgpu.dc=0"

If there is an option that should be added to every kernel command line (for example, you always want to disable the use of the rdrand instruction for random number generation) you can run a grubby command:

$ grubby --update-kernel=ALL --args="nordrand"

This will update the command line of all kernel entries and save the option to the saved kernel command line for future entries.

If you later want to remove the option from all kernels, you can again use

$ grubby --update-kernel=ALL --remove-args="nordrand"

## Michal Konečný

Thanks for the article. Nice to know about BLS.

## gnu

Thanks for the tip. I would like to not change my habits about the sensitive kernel commands to avoid waste of time and big risks. Should I set GRUB_ENABLE_BLSCFG to false to work as usual?

## Colin Walters

FWIW this only applies to traditional Fedora Server/Workstation etc. today – for rpm-ostree based systems like Fedora CoreOS and Silverblue, you need to use

because kernel commandline changes are part of the general OSTree transaction system. At some point we’ll likely wrap

to tell you to do this instead.

(Ultimately this ends up writing a BLS fragment though)

## svsv sarma

When ever kernel update is involved, i invariably get the error “failed to start load kernel modules………..” at boot time and i had to resort to dracut after boot up. With the recent kernel 5 update even dracut is not working as i get the alert permanently. Any help from kernel wizards?

## dac.override

In the early BLS-day’s I manually edited grubenv to append kernel options because grub2-mkconfig was not doing it. This was later addressed. I kept getting environment blocks too big and too small messages on kernel updates. This blog post inspired me to look into this.

It turns out the the environment block messages were due to me editing grubenv manually. I set out to fix this and ran into a bugzilla. There it was suggested one run grub2-editenv clear. I did this. Then i ran grubby –update-kernel=ALL –args=”mykernelopt” and i rebooted. I selected one of my kernel entries from the grub menu and the boot process hung. I then tried again and edited the kernel entry in the grub menu to get it to boot. Turned out it has left out some important bits and pieces.

Once i was able to boot into the system I ran grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg. This fixed things. I found it somewhat ironic that I had to use grub2-mkconfig to fix my grub entries.

## A Seda

Why on earth do they want to complicate things? Just a text file or two was working fine. Now is a new “tool” to modify a bunch of files with instructions we cant understand, making this difficult to diagnose.

## Sebastiaan Franken

As far as I know this is based on working with systemd’s boot commands (which is a pure EFI bootloader). The “pure” systemd approach is pretty minimal and easy, but for some reason Fedora had to make it complicated by using grub as well… I’m confused as well, but I’m sure Fedora devs have their reasons.

## Yazan Al Monshed

Great Article. Big Thanks

## Sebastiaan

It would have been good to cover the ‘why?’ this new way has been implemented.

## Steven Snow

The why is covered pretty extensively in the BLS link provided in the article. Specifically WRT systemd “TL;DR: Currently there’s no common boot scheme across architectures and platforms for open-source operating systems. There’s also little cooperation between multiple distributions in dual-boot (or triple, … multi-boot) setups. We’d like to improve this situation by getting everybody to commit to a single boot configuration format that is based on drop-in files, and thus is robust, simple, works without rewriting configuration files and is free of namespace clashes.”

## Justin W. Flory

Thanks for the simple explanation! I was wondering the same thing.

## Carl Bennett

So how would someone boot to single user mode from the grub menu using this new “BLS” configuration?

## Ben

That’s still the same just add an s to get to single user mode.

## Justin W. Flory

It is unclear to me how

is used. Is this from the grub CLI or from a logged-in user’s Bash shell? I was wondering how someone, for example, battling graphics drivers might debug their system if they are unable to log into their system to change kernel boot parameters.

## Joe Giles

What if I want to just add something quick to the kernel line before boot or after an install…

For example, I have an ASUS laptop with integrated Intel and Nvidia, so I have to add nouveau.modeset=0 and acpi_osi=Linux to handle some drivers correctly and it doesnt boot to a black screen cause the OS doesnt know what GPU to use.

Can we just add this to the kernel command still and boot or is this process changing too?

Joe

## Steven Snow

Grubby is being used at the command line in a terminal likely using bash for the shell. If you follow the link above, then further to this page https://systemd.io/BOOT_LOADER_SPECIFICATION you can get the whole scope pretty much.