自定义GRUB

注意
更改 GRUB 后不要忘记重新生成 grub.cfg

pling 下载主题压缩包, 比如 Vimix, 解压后运行 install.sh 自动安装;

更推荐自定义主题后手动安装:

  1. 将主题文件夹放入 /usr/share/grub/themes/ 路径下。

  2. 编辑 /etc/default/grub 指定主题路径, 比如:

    1
    
    GRUB_THEME="/usr/share/grub/themes/vimix/theme.txt"
    
  3. 重新生成 grub.cfg:

    1
    
    grub-mkconfig -o /boot/grub/grub.cfg
    

下面是 Vimix 主题的 theme.txt 文件, 被我稍微改动了一些, 可供参考:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# GRUB2 gfxmenu Linux theme
# Designed for any resolution

# Global Property
title-text: ""
desktop-image: "background.jpg"
desktop-color: "#000000"
terminal-font: "Sarasa Mono SC Regular 16"
terminal-box: "terminal_box_*.png"
terminal-left: "0"
terminal-top: "0"
terminal-width: "100%"
terminal-height: "100%"
terminal-border: "0"

# Show the boot menu
+ boot_menu {
left = 34%
top = 25%
width = 32%
height = 50%
item_font = "Sarasa Mono SC Regular 22"
item_color = "#cccccc"
selected_item_color = "#ffffff"
icon_width = 32
icon_height = 32
item_icon_space = 10
item_height = 50
item_padding = 5
item_spacing = 10
selected_item_pixmap_style = "select_*.png"
}

# Show a countdown message using the label component
+ label {
top = 80%
left = 35%
width = 30%
align = "center"
id = "__timeout__"
text = "将在 %d 秒钟后启动"
color = "#cccccc"
font = "Sarasa Mono SC Regular 16"
}

有些主题使用默认的 Unifont 字体, 即 /usr/share/grub/unicode.pf2, 它是 grub 包自带的 pf2 文件, 使用 pacman -Ql grub | grep pf2 可以查找更多。

  1. 转换 ttf 格式为 pf2 格式以供 GRUB 使用:

    1
    
    grub-mkfont -s 16 -o 输出文件.pf2 源文件.ttf
    

    -s 参数指定字号大小。需要为要使用的字号分别生成相应的文件。

  2. 将生成的 pf2 字体文件放入主题文件夹下。

  3. 编辑 theme.txt 文件内的字体选项:

    1
    2
    3
    4
    5
    6
    7
    
    ...
    terminal-font: "Sarasa Mono SC Regular 16"
    ...
    item_font = "Sarasa Mono SC Regular 22"
    ...
    font = "Sarasa Mono SC Regular 16"
    ...
    
注意
字体文件的名称不是字体的名称。

编辑 /etc/default/grub, 设置以下选项:

1
2
3
GRUB_DEFAULT=saved
...
GRUB_SAVEDEFAULT=true

如果使用了 多内核, 可以取消显示子菜单, 方便选择。编辑 /etc/default/grub, 设置以下选项:

1
GRUB_DISABLE_SUBMENU=y

更多自定义参考 GRUBGRUB/Tips_and_tricks