2024/01/18

grub.cfgのエントリをリスト表示するpythonスクリプト

grub.cfgのエントリをリスト表示する (github.com)

動作確認環境

  • Ubuntu23.10
  • python3.11.1

必要ライブラリ

  • pyparsing

出力例:
0        Ubuntu
1        Advanced options for Ubuntu
1>0    Ubuntu, with Linux 6.5.0-14-generic
1>1    Ubuntu, with Linux 6.5.0-14-generic (recovery mode)
1>2    Ubuntu, with Linux 6.5.0-10-generic
1>3    Ubuntu, with Linux 6.5.0-10-generic (recovery mode)
2        Memory test (memtest86+x64.efi)
3        Memory test (memtest86+x64.efi, serial console)
4        Windows Boot Manager (on /dev/sda1)
5        UEFI Firmware Settings

左の番号はgrub-rebootコマンドの引数に使えます。
$sudo grub-reboot "1>2"
→次回ブート時に"Ubuntu, with Linux 6.5.0-10-generic"が選択されます。
pyparsingライブラリをテキストの解析に使用しています。