【Grub2】常见命令

版权声明:本文为博主原创文章,转载注明出处 https://blog.csdn.net/u010875635/article/details/82686852

Grub2是Grub的升级版,增加了很多特性,用法与grub相似,语法有些差异,以下列出一些常用命令。

官方命令手册:https://www.gnu.org/software/grub/manual/grub/html_node/Commands.html#Commands

注意使用命令时,要先插入模块,除非在生成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

菜单

menuentry title [--class=class …] [--users=users] [--unrestricted] [--hotkey=key] [--id=id] [arg …] { command; … }

热键为一个字符,或者别名例如‘backspace’, ‘tab’,  ‘delete’

menuentry "Win7" --class windows --class os {
    insmod ntfs
    insmod chain
    set root=(hd0,msdos2)
    echo "Start Windows"
    chainloader +1
}
submenu

将menuentry分组显示

submenu title [--class=class …] [--users=users] [--unrestricted] [--hotkey=key] [--id=id] { menu entries … }

submenu aaa{

        menuentry b1{}

        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时可以更改

background_image /home/background.jpg
clear 清除屏幕 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文件
loopback loop0 /path/to/image
ls (loop0)/
sleep 休眠秒数

sleep 5

以下为范例:

insmod part_msdos
insmod font
insmod all_video
insmod gfxterm

terminal_output gfxterm

set font="$prefix/unicode.pf2"
loadfont $font

insmod jpeg
insmod gfxterm_background
background_image $prefix/background.jpg

set default=0

set timeout_style=menu
set timeout=5

menuentry "Grub Menu" --class winpe {
	insmod ntldr
	ntldr /BIOS/grub/grldr
}

menuentry "Slitaz" --class linux {
	insmod linux
	linux /BIOS/IMGS/BZIMAGE root=/dev/null autologin
	initrd /BIOS/IMGS/ROOTFS.GZ
}

menuentry "Install XUbuntu18.04" --class ubuntu --class os {
	insmod ext2
	insmod linux
	insmod loopback
	insmod ntfs
	insmod echo
	search.file /OS/udiskflag root
	loopback loop0 /OS/Linux/xubuntu-18.04-desktop-amd64.iso
	linux (loop0)/casper/vmlinuz ro boot=casper iso-scan/filename=/OS/Linux/xubuntu-18.04-desktop-amd64.iso ro splash
	initrd (loop0)/casper/initrd.lz
	echo "Install XUbuntu 18.04"
}


menuentry "CloneZilla" --class backup {
	configfile /BIOS/grub2/CloneZilla.cfg
}

menuentry "-------------------" --class ubuntu --class os{
	set root=(hd0,gpt1)
}


menuentry "reboot" --class windows --class os{
	insmod reboot
	reboot
}

menuentry "halt" --class windows --class os{
	insmod halt
	halt
}

猜你喜欢

转载自blog.csdn.net/u010875635/article/details/82686852
今日推荐