本文主要是介绍【Grub2】常见命令,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Grub2是Grub的升级版,增加了很多特性,用法与grub相似,语法有些差异,以下列出一些常用命令。
官方命令手册:https://www.gnu.org/software/grub/manual/grub/html_node/Commands.html#Commands
注意使用命令时,要先插入模块,除非在生成grub2时已经加入了该模块,insmod默认加入。
一般模块与命令名一致,极少数不一致,会特殊说明。
命令 | 描述 | 示例 |
---|---|---|
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文件 | |
sleep | 休眠秒数 | sleep 5 |
以下为范例:
insmod part_msdos
insmod font
insmod all_video
insmod gfxtermterminal_output gfxtermset font="$prefix/unicode.pf2"
loadfont $fontinsmod jpeg
insmod gfxterm_background
background_image $prefix/background.jpgset default=0set timeout_style=menu
set timeout=5menuentry "Grub Menu" --class winpe {insmod ntldrntldr /BIOS/grub/grldr
}menuentry "Slitaz" --class linux {insmod linuxlinux /BIOS/IMGS/BZIMAGE root=/dev/null autologininitrd /BIOS/IMGS/ROOTFS.GZ
}menuentry "Install XUbuntu18.04" --class ubuntu --class os {insmod ext2insmod linuxinsmod loopbackinsmod ntfsinsmod echosearch.file /OS/udiskflag rootloopback loop0 /OS/Linux/xubuntu-18.04-desktop-amd64.isolinux (loop0)/casper/vmlinuz ro boot=casper iso-scan/filename=/OS/Linux/xubuntu-18.04-desktop-amd64.iso ro splashinitrd (loop0)/casper/initrd.lzecho "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 rebootreboot
}menuentry "halt" --class windows --class os{insmod halthalt
}
这篇关于【Grub2】常见命令的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!