
Ubuntu日本語フォーラム
ログインしていません。
11.10上でのGRUBの設定に困っており、こちらに投稿致しました。
現在、/etc/default/grubには以下のようなエントリが記述されております。
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
#GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
当方、Windows VistaとUbuntuをデュアルブート運用しており、
デフォルトから少し編集して
「通常はOS選択画面を表示せず、即座にデフォルトに選択されたOSを起動。その際起動するOSは前回起動したものを記憶しておく。」
という動作を狙ったのですが、
意図に反して
「常にOS選択画面を表示、5秒後にタイムアウトしてデフォルトのOSを起動。その際起動するOSはリストの1番上にエントリされたUbuntu。」
という動作をしてしまいます。
編集箇所は以下の通りです。
・"GRUB_DEFAULT=0"を、"GRUB_DEFAULT=saved"に編集
・"GRUB_SAVEDEFAULT=true"を追加
(この2つの設定で「前回起動したOSを記憶」が動く…はずでした。)
・"GRUB_TIMEOUT=10"の先頭にハッシュマークを追加してコメントアウト
・"GRUB_HIDDEN_TIMEOUT=0"の先頭に付いているハッシュマークを削除してアンコメント
(この2つの設定で「通常はOS選択画面を表示せず、デフォルトのOSを起動」が動く…はずでした。)
公式のドキュメントを読んでもこれで動くように思えるのですが、何故か狙いとは全く違う動きを見せていて困惑しております。
原因としては/etc/default/grubの記法に誤りがあるというのが濃厚な気がするので、こちらの有志の方々に診ていただこうと思い投稿致しました。
何卒ご教授願いますようお願い致します。
オフライン
/etc/default/grubの内容に誤りはなく動作内容は現状に於ける仕様どおりと思います。
前回起動したOSをデフォルトにするには、/etc/grub.d/00_headerの46行目を変更してgrubenvへの正しいパスになるようにします。
マルチブートでOS選択画面を表示しないようにするには、/etc/grub.d/30_os-proberの、found_other_os=1をfound_othe_os=に変更し28行目からのmake_timeout () {...}が処理されるようにします。
grub.cfgの該当個所は
### BEGIN /etc/grub.d/00_header ###
if [ -s /boot/grub/grubenv ]; then
....
### BEGIN /etc/grub.d/30_os-prober ###
...
if [ "x${timeout}" != "x-1" ]; then
if keystatus; then
if keystatus --shift; then
set timeout=-1
else
set timeout=0
fi
else
if sleep --interruptible 3 ; then
set timeout=0
fi
fi
fi
### END /etc/grub.d/30_os-prober ###
になります。
オフライン
返信ありがとうございます。
基本的なことで申し訳ないのですが、
私の理解では
/etc/default/grubを編集→sudo update-grubを実行→/boot/grub/grub.cfgが自動作成されて設定完了
だと思っていたんですが、jackalopeさんに教えていただいたように他のファイルを編集しなければいけないものなのでしょうか?
現状、
「/etc/grub.d/00_headerの46行目」のパスは
"\$prefix/grubenv"に、
「/etc/grub.d/30_os-proberの、found_other_os=1をfound_othe_os=に変更し」の部分は恐らく26行目のことでしょうか?
その部分は"found_othe_os="になっていました。
オフライン
自レスです。
「前回起動したOSを自動選択する」
が動かなかった原因が判明致しましたのでご報告致します。
それは
「GRUB_HIDDEN_TIMEOUTを有効化している」事でした。
こちらのチュートリアルのGRUB_HIDDEN_TIMEOUTの説明部分に
「複数のOSが認識された場合、
GRUB_HIDDEN_TIMEOUTで設定されたタイムアウトまでの値は無視され、ブートメニュー表示にShiftキー押下を要する設定も無視されます。」
というような但し書きがありました。
つまり、私のようなマルチブート環境でこれを有効化すると
「エントリ0番のOSをデフォルトに、タイムアウトは5秒。」
というオプションを何も設定しなかった場合のデフォルトが無条件で適用されるようです。
そこで、
"GRUB_HIDDEN_TIMEOUT=0"
"GRUB_HIDDEN_TIMEOUT_QUIET=true"
の2つをコメントアウトし、
"GRUB_TIMEOUT=10"
を再びアンコメントして有効化してみたところ、無事に「前回起動したOSを自動選択する」機能が動きました。
上記したチュートリアルでは、
マルチブート環境でメニューを非表示にする方法としてこちらのスレッドを参照するよう勧められていたので、
そちらの方法を試してみてまたご報告致します。
オフライン
自レスその2です。
先ほどのレスで最後に貼ったUbuntu Forumのスレッドにある方法で、
「OS選択メニューを非表示にする」も無事に動作したのでその手順などをご報告致します。
そのスレッドには、
「/etc/grub.d/30_os-proberにあるGRUB_HIDDEN_TIMEOUTが無効化される条件を1つクリアして、マルチブート環境でも動作するようにする。」
方法と
「GRUB_FORCE_HIDDEN_MENUという設定値を/etc/default/grubに追加して、それに対応した条件を/etc/grub.d/30_os-proberに追加する。」
という2つの方法が紹介されておリ、
後者の方法のほうがより「エレガント」らしいのですが…11.10で後者の方法を取るとupdate-grubで別パーティションにあるOSを検出できなくなりました。
なので、前者の
「/etc/grub.d/30_os-proberにあるGRUB_HIDDEN_TIMEOUTが無効化される条件を1つクリアして、マルチブート環境でも動作するようにする。」
方法を試しました。
以下はそのスレッドにあった手順のコピペのようなものですが、一応書いておきます。
まず、/etc/default/grubを以下のように編集します。
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
GRUB_HIDDEN_TIMEOUT=0←アンコメント
GRUB_HIDDEN_TIMEOUT_QUIET=true←アンコメント
#GRUB_TIMEOUT=10←コメントアウト
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
これで、
「Shiftキーを押していない場合はブートメニューをスキップして即座にデフォルトのOSを起動」
になるのですが、先ほどのレスにあるようにマルチブート環境では無効化されてしまい動作しません。
そこで今度は、無効化される条件をクリアしてマルチブート環境でも動作するようにします。
/etc/grub.d/30_os-proberを以下のように編集します。
#! /bin/sh
set -e
# grub-mkconfig helper script.
# Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
. ${libdir}/grub/grub-mkconfig_lib
found_other_os=
make_timeout () {
# if [ "x${found_other_os}" = "x" ] ; then←コメントアウト
if [ "x${1}" != "x" ] ; then
if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
verbose=
else
verbose=" --verbose"
fi
if [ "x${1}" = "x0" ] ; then
cat <<EOF
if [ "x\${timeout}" != "x-1" ]; then
if keystatus; then
if keystatus --shift; then
set timeout=-1
else
set timeout=0
fi
else
if sleep$verbose --interruptible 3 ; then
set timeout=0
fi
fi
fi
EOF
else
cat << EOF
if [ "x\${timeout}" != "x-1" ]; then
if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT} ; then
set timeout=0
fi
fi
EOF
fi
fi
# fi←コメントアウト
}
adjust_timeout () {
if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
cat <<EOF
if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
EOF
make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}"
echo else
make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}"
echo fi
else
make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}"
fi
}
if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
adjust_timeout
exit 0
fi
if [ -z "`which os-prober 2> /dev/null`" -o -z "`which linux-boot-prober 2> /dev/null`" ] ; then
# missing os-prober and/or linux-boot-prober
adjust_timeout
exit 0
fi
OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
if [ -z "${OSPROBED}" ] ; then
# empty os-prober output, nothing doing
adjust_timeout
exit 0
fi
osx_entry() {
found_other_os=1
cat << EOF
menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" --class osx --class darwin --class os {
EOF
save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
cat << EOF
load_video
set do_resume=0
if [ /var/vm/sleepimage -nt10 / ]; then
if xnu_resume /var/vm/sleepimage; then
set do_resume=1
fi
fi
if [ \$do_resume = 0 ]; then
xnu_uuid ${OSXUUID} uuid
if [ -f /Extra/DSDT.aml ]; then
acpi -e /Extra/DSDT.aml
fi
$1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
xnu_mkext /System/Library/Extensions.mkext
else
xnu_kextdir /System/Library/Extensions
fi
if [ -f /Extra/Extensions.mkext ]; then
xnu_mkext /Extra/Extensions.mkext
fi
if [ -d /Extra/Extensions ]; then
xnu_kextdir /Extra/Extensions
fi
if [ -f /Extra/devprop.bin ]; then
xnu_devprop_load /Extra/devprop.bin
fi
if [ -f /Extra/splash.jpg ]; then
insmod jpeg
xnu_splash /Extra/splash.jpg
fi
if [ -f /Extra/splash.png ]; then
insmod png
xnu_splash /Extra/splash.png
fi
if [ -f /Extra/splash.tga ]; then
insmod tga
xnu_splash /Extra/splash.tga
fi
fi
}
EOF
}
wubi=
for OS in ${OSPROBED} ; do
DEVICE="`echo ${OS} | cut -d ':' -f 1`"
LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
BOOT="`echo ${OS} | cut -d ':' -f 4`"
if [ -z "${LONGNAME}" ] ; then
LONGNAME="${LABEL}"
fi
echo "Found ${LONGNAME} on ${DEVICE}" >&2
case ${BOOT} in
chain)
case ${LONGNAME} in
Windows*)
if [ -z "$wubi" ]; then
if [ -x /usr/share/lupin-support/grub-mkimage ] && \
/usr/share/lupin-support/grub-mkimage --test; then
wubi=yes
else
wubi=no
fi
fi
if [ "$wubi" = yes ]; then
echo "Skipping ${LONGNAME} on Wubi system" >&2
continue
fi
;;
esac
found_other_os=1
cat << EOF
menuentry "${LONGNAME} (on ${DEVICE})" --class windows --class os {
EOF
save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
case ${LONGNAME} in
Windows\ Vista*|Windows\ 7*|Windows\ Server\ 2008*)
;;
*)
cat << EOF
drivemap -s (hd0) \${root}
EOF
;;
esac
cat <<EOF
chainloader +1
}
EOF
;;
linux)
LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
prepare_boot_cache=
for LINUX in ${LINUXPROBED} ; do
LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`"
LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"
LINITRD="`echo ${LINUX} | cut -d ':' -f 5`"
LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`"
if [ -z "${LLABEL}" ] ; then
LLABEL="${LONGNAME}"
fi
if [ "${LROOT}" != "${LBOOT}" ]; then
LKERNEL="${LKERNEL#/boot}"
LINITRD="${LINITRD#/boot}"
fi
found_other_os=1
cat << EOF
menuentry "${LLABEL} (on ${DEVICE})" --class gnu-linux --class gnu --class os {
EOF
save_default_entry | sed -e "s/^/\t/"
if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")"
fi
printf '%s\n' "${prepare_boot_cache}"
cat << EOF
linux ${LKERNEL} ${LPARAMS}
EOF
if [ -n "${LINITRD}" ] ; then
cat << EOF
initrd ${LINITRD}
EOF
fi
cat << EOF
}
EOF
done
;;
macosx)
OSXUUID="`grub-probe --target=fs_uuid --device ${DEVICE} 2> /dev/null`"
osx_entry xnu_kernel 32
osx_entry xnu_kernel64 64
;;
hurd)
found_other_os=1
cat << EOF
menuentry "${LONGNAME} (on ${DEVICE})" --class hurd --class gnu --class os {
EOF
save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
grub_device="`${grub_probe} --device ${DEVICE} --target=drive`"
mach_device="`echo "${grub_device}" | sed -e 's/(\(hd.*\),msdos\(.*\))/\1s\2/'`"
grub_fs="`${grub_probe} --device ${DEVICE} --target=fs`"
case "${grub_fs}" in
*fs) hurd_fs="${grub_fs}" ;;
*) hurd_fs="${grub_fs}fs" ;;
esac
cat << EOF
multiboot /boot/gnumach.gz root=device:${mach_device}
module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
--multiboot-command-line='\${kernel-command-line}' \\
--host-priv-port='\${host-port}' \\
--device-master-port='\${device-port}' \\
--exec-server-task='\${exec-task}' -T typed '\${root}' \\
'\$(task-create)' '\$(task-resume)'
module /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)'
}
EOF
;;
*)
echo " ${LONGNAME} is not yet supported by grub-mkconfig." >&2
;;
esac
done
adjust_timeout
これで、
「マルチブート環境ではGRUB_HIDDEN_TIMEOUTを無効化する」
という条件をクリアできます。(コメントアウトした部分を削除してしまってもいいのですが、もし元に戻したくなった場合に困ると思いこうしました。)
以上の設定を行うことで
「Shiftキーを押さない限りブートメニューはスキップ、デフォルトのOSが自動起動。その際に起動するのはGRUBにエントリされた中で前回起動したOS。」
という、当初目指していた動作を実現することができました。
PS.設定を変更したあとはsudo update-grubをお忘れなく^^
オフライン
この設定、
毎回Ubuntuを入れる際に行なっていながら「grub.d触るのってどうよ…」と思っていたのですが、
どうやら/etc/default/grubに「GRUB_DISABLE_OS_PROBER=true」という設定を行うと、
update-grubしても他のパーティションのOSを探しに行かなくなるらしく、
諸々が上手く解決することをここ(https://forums.ubuntulinux.jp/viewtopic.php?pid=43082 )を見て知りました。
ちゃんと読めよって感じですね………
オフライン
※追記※
現在、
マシンがこのスレッドを投稿した当時使っていたVAIO(SZ)ではなくMacBook Airになっており、
マルチブートでの起動OS選択にはMacのEFIブートセレクタを使っているので、
GRUBで他のOSを発見・ブートする必要がなくなった、という事を書き忘れていました。
というか、GRUBではOS XやBoot Campを使って入れたWindowsを、
「見つけて、エントリに追加できるけど、起動できない」のでアレでして…
オフライン