本文将分享grub初级用法的一些经验与心得。

background

强烈建议阅读An introduction to GRUB2 configuration for your Linux machine

个人notes:

  • The grub.cfg file is the GRUB configuration file. Try vim /boot/grub/grub.cfg to see your own grub.cfg.
  • The grub.cfg file is generated by the grub-mkconfig program using a set of primary configuration files and the grub default file as a source for user configuration specifications.

    • grub configuration files: the main set of configuration files for grub.cfg is located in the /etc/grub.d directory.
    • grub default file: the /etc/default/grub
  • 在grub2配置中,grub.cfg目录:/boot/grub2/grub.cfg,有些命令也有区别,例如grub2-mkconfig,注意差异即可

GRUB configuration files

The main set of configuration files for grub.cfg is located in the /etc/grub.d directory. Each of the files in that directory contains GRUB code that is collected into the final grub.cfg file. The numbering scheme used in the names of these configuration files is designed to provide ordering so that the final grub.cfg file is assembled into the correct sequence. Each of these files has a comment to denote the beginning and end of the section, and those comments are also part of the final grub.cfg file so that it is possible to see from which file each section is generated. The delimiting comments look like this:

1
2
3
### BEGIN /etc/grub.d/10_linux ###

### END /etc/grub.d/10_linux ###

These files should not be modified unless you are a GRUB expert and understand what the changes will do. Even then you should always keep a backup copy of the original, working grub.cfg file. The specific files, 40_custom and 41_custom are intended to be used to generate user modifications to the GRUB configuration. You should still be aware of the consequences of any changes you make to these files and maintain a backup of the original grub.cfg file.

GRUB defaults file

The /etc/default/grub file is very simple. The grub defaults file has a number of valid key/value pairs listed already. You can simply change the values of existing keys or add other keys that are not already in the file.

spec:Simple configuration handling

misc