grub.cfg マルチブートの例

2019年5月29日

マルチブート

grub用パーティションの /boot/grub/grub.cfg に下記の「### BEGIN /etc/grub.d/40_custom」以下を差し替えて使う。
メニューを変更時は /boot/grub/grub.cfg を直接変更する。

サンプル

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="${saved_entry}"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}
function recordfail {
  set recordfail=1
  if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_msdos
insmod ext2
set root='hd0,msdos5'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  493df875-d628-40f2-8d78-838afbae6cf1
else
  search --no-floppy --fs-uuid --set=root 493df875-d628-40f2-8d78-838afbae6cf1
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=640x480
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=ja_JP
  insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ] ; then
# mati jikan
  set timeout=16
else
  if [ x$feature_timeout_style = xy ] ; then
    set timeout_style=hidden
    set timeout=15
  # Fallback hidden-timeout code in case the timeout_style feature is
  # unavailable.
  elif sleep --interruptible 15 ; then
    set timeout=0
  fi
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.


menuentry "sda5 Lubuntu" {
    saved_entry="${chosen}"
    save_env saved_entry
    insmod chain
    set root=(hd0,5)
    chainloader +1
}

menuentry "sda6 openSUSE" {
    saved_entry="${chosen}"
    save_env saved_entry
    insmod chain
    set root=(hd0,6)
    chainloader +1
}

menuentry "sda7 Ubuntu" {
    saved_entry="${chosen}"
    save_env saved_entry
    insmod chain
    set root=(hd0,7)
    chainloader +1
}

menuentry "sda8 ArchLinux" {
    saved_entry="${chosen}"
    save_env saved_entry
    insmod chain
    set root=(hd0,8)
    chainloader +1
}

menuentry "sda9 Debian" {
    saved_entry="${chosen}"
    save_env saved_entry
    insmod chain
    set root=(hd0,9)
    chainloader +1
}

### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###