LoginSignup
15
17

More than 3 years have passed since last update.

CentOS7 ブートローダ周り

Last updated at Posted at 2018-11-11

CentOS7 ブートローダー GRUB2

基本設定ファイル

/etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

GRUB_TIMEOUT:GRUB2メニューが表示される時間(秒)
GRUB_DISTRIBUTOR:ディストリビューター名(デフォルト値:CentOS Linux)
GRUB_DEFAULT:タイムアウト時に起動するkernelを指定
※/boot/grub2/grub.cfgにおいてmenuentryから始まるkernel群が、最初を0として上から順番に数える(例:GRUB_DEFAULT=1)
※GRUB_DEFAULT=savedと記載すると、デフォルトのメニューエントリーがsaveされたものとなる
 saveされているエントリーは以下で確認可能
 head -2 /boot/grub2/grubenv又は
 grub2-editenv list
 変更する場合はgrub2-set-default 2
 また、GRUB_SAVEDEFAULT=trueを追記すると、前回選択エントリーがsaveされる
GRUB_DISABLE_SUBMENU:複数のカーネルをインストールしている場合、デフォルトでカーネルをサブメニューにグループ化するため、サブメニューにまとめて欲しくなくシングルメニューに戻したい場合に指定
GRUB_TERMINAL_OUTPUT:表示出力先を指定
GRUB_CMDLINE_LINUX:起動時にコマンドラインオプションへ追加したいオプションを指定
GRUB_DISABLE_RECOVERY:リカバリーモードのエントリー作成有無を指定

/etc/default/grubファイルを編集した場合は、grub2-mkconfigコマンドによって、設定ファイルの再生成が必要
・BIOSマシン
grub2-mkconfig -o /boot/grub2/grub.cfg
・UEFIマシン
grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

GRUB_CMDLINE_LINUXの変更が適用されているかは、以下コマンドで確認可能
cat /proc/cmdline

ブートメニューエントリ

/boot/grub2/grub.cfgファイル

独自のブートメニューエントリを追加したい場合は、/etc/grub.d/40_customファイルを使用する。
/boot/grub2/grub.cfgファイルにならい、以下のように記述する。

/etc/grub.d/40_custom
menuentry 'Custom CentOS Linux (3.10.0-862.11.6.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_64-advanced-e4857c18-abfd-4b6a-86a2-ae9e7fd09a00' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  343ddce6-1dee-4552-a0c8-090f9d275c92
        else
          search --no-floppy --fs-uuid --set=root 343ddce6-1dee-4552-a0c8-090f9d275c92
        fi
        linux16 /vmlinuz-3.10.0-862.11.6.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
        initrd16 /initramfs-3.10.0-862.11.6.el7.x86_64.img
}

このままだと/boot/grub2/grub.cfgへ反映されず、起動時に選ぶことができない。
反映のために以下を実行する。
・BIOSの場合
grub2-mkconfig -o /boot/grub2/grub.cfg
・UEFIの場合
grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

15
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
17