grub2是grub的公升級版,增加了很多特性,用法與grub相似,語法有些差異,以下列出一些常用命令。
官方命令手冊:
注意使用命令時,要先插入模組,除非在生成grub2時已經加入了該模組,insmod預設加入。
一般模組與命令名一致,極少數不一致,會特殊說明。
grub2常用命令 命令
描述示例
insmod
插入模組
insmod ntfs
lsmod
顯示已經載入的模組
lsmode
rmmod
移除模組
rmmod ntfs
echo
顯示echo "hello"
set設定
root-設定根目錄
default-設定預設選單
timeout-設定超時
還可以設定變數
set root=(hd0,msdos1),注意磁碟從0開始,分割槽從1開始
set default=0
set timeout=5
set prefix=(hd0,msdos1)/efi/grub,使用$prefix
chainloader
鏈載入,載入當前分割槽啟動或者從檔案啟動,可直接啟動efi檔案
chainloader +1
chainloader /efi/boot.efi
menuentry
選單menuentrytitle [--class=class …] [--users=users] [--unrestricted] [--hotkey=key] [--id=id] [arg …]
熱鍵為乙個字元,或者別名例如『backspace』, 『tab』, 『delete』
menuentry "win7" --class windows --class os
submenu
將menuentry分組顯示
submenutitle [--class=class …] [--users=users] [--unrestricted] [--hotkey=key] [--id=id]
submenu aaa
menuentry b2{}
terminal_output
選擇輸出的終端
terminal_output gfxterm
root
根目錄set root=(hd0,msdos2)
boot
啟動cat
顯示檔案內容
cat /1.txt
background_color
背景顏色,支援三種寫法
1、16進製制rgb,#rrggbb
2、10進製rgb,128,128,255
3、svg 1.0顏色名稱,cornflowerblue
set background_color=gray
background_image
模組:gfxterm_background
背景,background_image[[--mode 『stretch』|『normal』] file]
預設為stretch模式,除非設定normal模
僅在terminal output設定為gfxterm時可以更改
清除螢幕
clear
source
將其它檔案選單載入到本選單
source /grub.cfg
configfile
載入其它選單檔案
configfile /grub.cfg
gettext
轉換字串為當前語言
halt
關機reboot
重啟help
幫助linux
載入linux核心
linux /vmlinux
linux16
載入16位模式下的linux核心
initrd
載入初始化ram資料模組
initrd /initrd.gz
initrd16
載入初始化16位模式ram資料模組
loadfont
模組font
設定字型
loadfont "$prefix/unicode.pf2"
lsfonts
顯示已經載入的字型
ls顯示檔案和資料夾
search
搜尋,search[--file|--label|--fs-uuid] [--set [var]] [--no-floppy] name
search.file等同於 search --file
search.file /efi/grub/x64.cfg root #搜尋檔案,並設定檔案所在分割槽為根目錄
loopback
載入映象,通常用於載入iso檔案
sleeploopback loop0 /path/to/image
ls (loop0)/
休眠秒數
sleep 5
以下為範例:
Grub2 在優盤中安裝Grub2
下面介紹linux下將優盤。安裝mbr有兩種方式,一種是安裝到磁碟,即mbr,一種是安裝到分割槽,也就成了pbr。mbr會被bios識別,pbr要通過mbr來引導進入。首先使用fdisk查詢到對應分割槽,例如 dev sdb2 mount dev sdb2 mnt grub2 install roo...
Grub2 製作UEFI版本Grub2引導
首先要從grub官網下在grub2,grub2中包含所有grub2相關的命令,可以用來生成grub2引導,這裡著重介紹製作uefi版本的grub2 uefi啟動是fat fat32分割槽 efi boot bootia32.efi或者 efi boot bootx64.efi,然後程序由uefi交給...
grub2崩潰恢復
grub2在mbr下,向後占用了大約50個扇區,實現了乙個小的resume 命令列,這個命令列,可以列各分割槽的檔案目錄,載入擴充套件命令模組,當grub2不能找到 boot grub 的檔案時,就會進入這個 resume 命令列狀態,booting from hard disk.grub load...