1,310 瀏覽數

Linux – GRUB2

以前的 GRUB 很簡單,透過修改 /boot/grub/grub.conf 或是 /boot/grub/menu.lst ( http://benjr.tw/134 )就可以搞定,但是 GRUB2 (版本為 1.98 或更新版) 變得很不一樣.

如果你去手動編輯 /boot/grub/grub.cfg 會發現怎麼變成 shell script ,不知道要怎麼修改, GRUB2 也不建議修改這個檔案.

root@ben-VirtualBox:~# cat /boot/grub/grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### 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="0"
....略

現在建議直接看 /etc/default/grub,修改這邊的設定即可.下面是 Ubuntu 14.04 的 GRUB2

root@ben-VirtualBox:~# cat /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=0
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"

關於設定內容可以直接參考 GRUB2中文指南第二版(上)

額外增加參數,GRUB 開機參數則可以從 /etc/default/grub 內的 GRUB_CMDLINE_LINUX

root@ben-VirtualBox:~# cat /etc/default/grub | grep -i GRUB_CMDLINE_LINUX
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 
root@ben-VirtualBox:~# grub2-mkconfig

GRUB 有提供一些相對應的指令可以來使用.如 #grub-set-default 可以用來設定開機選項.

root@ben-VirtualBox:~# grub-set-default 1

後面參數代表選單的位置,第一筆是由 0 開始算起.
當然手動修改 /etc/default/grub 的設定也是可以的.

root@ben-VirtualBox:~# vi /etc/default/grub
....略
GRUB_DEFAULT=saved

saved 代表會以上次所選的開機選項為預設選項.

如果不習慣還可以去下載圖形介面的 #grub-customizer ( https://launchpad.net/grub-customizer ) 來使用.

root@ben-VirtualBox:~# add-apt-repository ppa:danielrichter2007/grub-customizer
root@ben-VirtualBox:~# apt-get update
root@ben-VirtualBox:~# apt-get install grub-customizer
root@ben-VirtualBox:~# gksudo grub-customizer

GRUB201

2 個網友的想法 “Linux – GRUB2

  1. 自動參照通知: Linux – Biosdevname & net.ifnames – Benjr.tw

  2. 自動參照通知: Linux file – /proc/cmdline – Benjr.tw

發表迴響