grub制作USB启动盘
grub制作USB启动盘
一、使用 GParted 分区U盘:
第一个分区 500M , 并且设置标识 boot esp , fat32格式
第二个分区剩余全部,ntfs格式(可以读写大于4G的文件)
终端输入命令fdisk -l
查看结果:
终端输入命令blkid
查看结果:
二、扇区末尾1M空间使用命令 gdisk
打上标记 bios_grub
,格式化方式——未格式化
wmx@wmx-ubuntu:~$ sudo gdisk /dev/sdb <=========== 1步骤
[sudo] wmx 的密码:
GPT fdisk (gdisk) version 1.0.1Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: presentFound valid GPT with protective MBR; using GPT.Command (? for help): n <=========== 2步骤
Partition number (3-128, default 3): <=========== 3步骤 ,回车
First sector (34-30605278, default = 30603264) or {+-}size{KMGTP}: <=========== 回车
Last sector (30603264-30605278, default = 30605278) or {+-}size{KMGTP}: <=========== 回车
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): EF02 <=========== 4步骤
Changed type of partition to 'BIOS boot partition'Command (? for help): p <=========== 5步骤
Disk /dev/sdb: 30605312 sectors, 14.6 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 961A84D4-79FF-47F1-990A-885ED8AD66AE
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 30605278
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)Number Start (sector) End (sector) Size Code Name1 2048 1026047 500.0 MiB EF00 2 1026048 30603263 14.1 GiB 0700 3 30603264 30605278 1007.5 KiB EF02 BIOS boot partitionCommand (? for help): w <=========== 6步骤 Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!Do you want to proceed? (Y/N): y <=========== 7步骤
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
使用GParted
查看结果
boot esp
标记支持 EFI 启动
bios_grub
标记支持 BIOS 启动
三、安装grub到U盘
1 挂载U盘分区 /dev/sdb1
到 /mnt
:
sudo mount /dev/sdb1 /mnt
2 grub安装到MBR
sudo grub-install --target=i386-pc --recheck --boot-directory=/mnt/boot /dev/sdb
3 grub安装到ESP,特别注意--removable
参数,安装到移动设备上一定要用这个参数
sudo grub-install --target x86_64-efi --efi-directory /mnt --boot-directory=/mnt/boot --removable
特别注意:
- Ubuntu的grub默认的target是i386-pc,这个target包含在grub-pc这个包,如果你的系统使用BIOS+MBR安装,这个包默认是存在的。x86_64-efi这个target包含在grub-efi这个包,只有你的系统使用UEFI+GPT方式安装这个包才会存在。如果某个target报错,错误信息类似于grub-install: error: /usr/lib/grub/x86_64-efi/modinfo.sh doesn’t exist. Please specify --target or --directory. 这样的话,就需要安装grub-pc或grub-efi之后再试。
- 安装到ESP要加–removable这个参数 这个参数专门针对于可移动设备,一定要加
- bios_grub标记的分区 如果按照上面的分区过程操作了,增加了这个标记的分区,安装grub的时候会自动识别这个标记的分区并成功安装grub,否则报错:
Installing for i386-pc platform.
grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible.
grub-install: warning: 无法嵌入。在此次安装中 GRUB 只能通过使用块列表安装。但是块列表是不可信赖的,不推荐使用。.
grub-install:错误: will not proceed with blocklists.
四、添加grub菜单
sudo grub-mkconfig -o /mnt/boot/grub/grub.cfg
然后基于你自己的电脑和U盘修改 /mnt/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 ]; thenset have_grubenv=trueload_env
fiif [ "${next_entry}" ] ; thenset default="${next_entry}"set next_entry=save_env next_entryset boot_once=true
elseset default="0"
fiif [ x"${feature_menuentry_id}" = xy ]; thenmenuentry_id_option="--id"
elsemenuentry_id_option=""
fiexport menuentry_id_optionif [ "${prev_saved_entry}" ]; thenset saved_entry="${prev_saved_entry}"save_env saved_entryset prev_saved_entry=save_env prev_saved_entryset boot_once=true
fifunction savedefault {if [ -z "${boot_once}" ]; thensaved_entry="${chosen}"save_env saved_entryfi
}###记录错误
function recordfail {set recordfail=1if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}### 加载显示模块
function load_video {if [ x$feature_all_video_module = xy ]; theninsmod all_videoelseinsmod efi_gopinsmod efi_ugainsmod ieee1275_fbinsmod vbeinsmod vgainsmod video_bochsinsmod video_cirrusfi
}### 查找字体
if [ x$feature_default_font_path = xy ] ; thenfont=unicode
else
insmod part_gpt
insmod ext2
set root='hd0,gpt4'
if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt4 --hint-efi=hd0,gpt4 --hint-baremetal=ahci0,gpt4 7195511a-452c-42f9-82d1-e6806399e90f
elsesearch --no-floppy --fs-uuid --set=root 7195511a-452c-42f9-82d1-e6806399e90f
fifont="/usr/share/grub/unicode.pf2"
fi### 加载字体
if loadfont $font ; thenset gfxmode=autoload_videoinsmod gfxtermset locale_dir=$prefix/localeset lang=zh_CNinsmod gettext
fi### 输出显示
terminal_output gfxterm### 设置超时显示
if [ "${recordfail}" = 1 ] ; thenset timeout=30
elseif [ x$feature_timeout_style = xy ] ; thenset timeout_style=menuset timeout=10# Fallback normal timeout code in case the timeout_style feature is# unavailable.elseset timeout=10fi
fi### END /etc/grub.d/00_header ###### 设置菜单外观
### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
if background_color 44,0,30,0; thenclear
fi
### END /etc/grub.d/05_debian_theme ###### BEGIN /etc/grub.d/10_linux ######设置分辨率
function gfxmode {set gfxpayload="${1}"if [ "${1}" = "keep" ]; thenset vt_handoff=vt.handoff=7elseset vt_handoff=fi
}### 根据配置,导出显示模式
if [ "${recordfail}" != 1 ]; thenif [ -e ${prefix}/gfxblacklist.txt ]; thenif hwmatch ${prefix}/gfxblacklist.txt 3; thenif [ ${match} = 0 ]; thenset linux_gfx_mode=keepelseset linux_gfx_mode=textfielseset linux_gfx_mode=textfielseset linux_gfx_mode=keepfi
elseset linux_gfx_mode=text
fiexport linux_gfx_modemenuentry 'Ubuntu 16.04 boot from usb' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-7195511a-452c-42f9-82d1-e6806399e90f' {### 记录错误recordfail### 加载显示驱动load_video### 配置显示模式gfxmode $linux_gfx_mode###insmod gzioif [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi### 加载文件系统支持insmod part_gptinsmod ext2### 设置 /boot 位置set root='hd0,gpt2'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 936d36cb-f60a-4f19-a357-ca02dd506de1elsesearch --no-floppy --fs-uuid --set=root 936d36cb-f60a-4f19-a357-ca02dd506de1fi### 加载内核 ,指定root(根位置 / )linux /vmlinuz-4.15.0-50-generic root=UUID=7195511a-452c-42f9-82d1-e6806399e90f ro quiet splash $vt_handoff### 初始化 RAMinitrd /initrd.img-4.15.0-50-generic
}submenu 'Ubuntu 高级选项' $menuentry_id_option 'gnulinux-advanced-7195511a-452c-42f9-82d1-e6806399e90f' {menuentry 'Ubuntu,Linux 4.15.0-50-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-50-generic-advanced-7195511a-452c-42f9-82d1-e6806399e90f' {recordfailload_videogfxmode $linux_gfx_modeinsmod gzioif [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fiinsmod part_gptinsmod ext2set root='hd0,gpt2'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 936d36cb-f60a-4f19-a357-ca02dd506de1elsesearch --no-floppy --fs-uuid --set=root 936d36cb-f60a-4f19-a357-ca02dd506de1fiecho '载入 Linux 4.15.0-50-generic ...'linux /vmlinuz-4.15.0-50-generic root=UUID=7195511a-452c-42f9-82d1-e6806399e90f ro quiet splash $vt_handoffecho '载入初始化内存盘...'initrd /initrd.img-4.15.0-50-generic}menuentry 'Ubuntu, with Linux 4.15.0-50-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-50-generic-init-upstart-7195511a-452c-42f9-82d1-e6806399e90f' {recordfailload_videogfxmode $linux_gfx_modeinsmod gzioif [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fiinsmod part_gptinsmod ext2set root='hd0,gpt2'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 936d36cb-f60a-4f19-a357-ca02dd506de1elsesearch --no-floppy --fs-uuid --set=root 936d36cb-f60a-4f19-a357-ca02dd506de1fiecho '载入 Linux 4.15.0-50-generic ...'linux /vmlinuz-4.15.0-50-generic root=UUID=7195511a-452c-42f9-82d1-e6806399e90f ro quiet splash $vt_handoff init=/sbin/upstartecho '载入初始化内存盘...'initrd /initrd.img-4.15.0-50-generic}menuentry 'Ubuntu, with Linux 4.15.0-50-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-50-generic-recovery-7195511a-452c-42f9-82d1-e6806399e90f' {recordfailload_videoinsmod gzioif [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fiinsmod part_gptinsmod ext2set root='hd0,gpt2'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 936d36cb-f60a-4f19-a357-ca02dd506de1elsesearch --no-floppy --fs-uuid --set=root 936d36cb-f60a-4f19-a357-ca02dd506de1fiecho '载入 Linux 4.15.0-50-generic ...'linux /vmlinuz-4.15.0-50-generic root=UUID=7195511a-452c-42f9-82d1-e6806399e90f ro recovery nomodeset echo '载入初始化内存盘...'initrd /initrd.img-4.15.0-50-generic}}### END /etc/grub.d/10_linux ###### BEGIN /etc/grub.d/20_linux_xen ###### END /etc/grub.d/20_linux_xen ###### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry 'Memory test (memtest86+)' {insmod part_gptinsmod ext2set root='hd0,gpt2'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 936d36cb-f60a-4f19-a357-ca02dd506de1elsesearch --no-floppy --fs-uuid --set=root 936d36cb-f60a-4f19-a357-ca02dd506de1fiknetbsd /memtest86+.elf
}
menuentry 'Memory test (memtest86+, serial console 115200)' {insmod part_gptinsmod ext2set root='hd0,gpt2'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2 936d36cb-f60a-4f19-a357-ca02dd506de1elsesearch --no-floppy --fs-uuid --set=root 936d36cb-f60a-4f19-a357-ca02dd506de1filinux16 /memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###### BEGIN /etc/grub.d/30_uefi-firmware ###
### END /etc/grub.d/30_uefi-firmware ###### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.###
menuentry "usb ubuntu.iso" {recordfailload_videogfxmode $linux_gfx_modeinsmod gzioif [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fiinsmod part_gptinsmod ext2search --no-floppy --fs-uuid --set=root 14993B1124BAFEAAloopback loop ($root)/ubuntu.isoecho '载入 vmlinuz ubuntu.iso ...'linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=($root)/ubuntu.iso noeject noprompt quiet splash locale=zh_CN.UTF-8echo '载入初始化内存盘...'initrd (loop)/casper/initrd.lz
}menuentry "USB Try Ubuntu without installing" {### 记录错误recordfail### 加载显示驱动load_video### 配置显示模式gfxmode $linux_gfx_mode###insmod gzioif [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi### 加载文件系统支持insmod part_gptinsmod ext2search --no-floppy --fs-uuid --set=root 14993B1124BAFEAAset gfxpayload=keeplinux ($root)/casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash ---initrd ($root)/casper/initrd.lz
}###### END /etc/grub.d/40_custom ###### BEGIN /etc/grub.d/41_custom ###
if [ -f ${config_directory}/custom.cfg ]; thensource ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; thensource $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
五、提取ubuntu16.04lts.iso 镜像到 /dev/sdb2
然后重启电脑,选择U盘启动,大功告成
grub制作USB启动盘相关推荐
- linux initrd usb热插拔,linux技术之制作USB启动盘
linux技术之制作USB启动盘 USB闪存存储装置(优盘)由于具有轻巧精致.使用方便.便于携带等优点,特别是对比软盘具有容量较大.安全可靠.读取速度较快等特性,越来越多人 使用这种装置取代了软驱与软 ...
- 【Ubuntu】制作usb启动盘安装ubuntu18.04时报错:“failed to load ldlinux.c32”
1.问题描述 使用UltraISO制作ubuntu18.04操作系统的usb启动盘后,按照时报错: failed to load ldlinux.c32 ubuntu16.04.ubuntu14.04 ...
- mac 制作usb启动盘_如何使用Mac制作Windows 10 USB-从Mac终端构建可启动的ISO
mac 制作usb启动盘 Most new PCs don't come with DVD drives anymore. So it can be a pain to install Windows ...
- Rufus制作USB启动盘工具 重装系统
Rufus制作USB启动盘工具 最重要的一步:制作U盘启动盘 首先准备一个U盘,建议8G大小的 然后准备好系统镜像 接着就需要开始直接启动盘了,制作启动盘这里就介绍一款制作工具:Rufus 先来说一下 ...
- 如何免费快速制作USB启动盘,how to create USB bootable from ISO file
Windows越来越大,光盘刻录,保管都不是很方便,这里分享一个利用开源工具Rufus如何快速制作USB启动盘的方法. 1. 下载Windows ISO 文件,我准备的是Win10企业版 2. 利用开 ...
- Linux 服务器(二)-linux安装方法之Centos安装介绍——Windows中制作USB启动盘 MacOS中制作USB启动盘
Linux 服务器(二)-linux安装方法之Centos安装介绍--Windows中制作USB启动盘 & MacOS中制作USB启动盘 安装方法 Centos安装方法: 下载镜像 按需选择下 ...
- 制作USB启动盘(U盘安装ubuntu20.04)
文章目录 制作USB启动盘(U盘安装ubuntu20.04) 制作USB启动盘的工具 ubuntu20.04系统安装u盘制作 进入bios 制作USB启动盘(U盘安装ubuntu20.04) 制作US ...
- ubuntu系统制作usb启动盘
最近在做usb系统启动盘,发现在ubuntu下制作太简单了,两行命令搞定,比win下制作还快,不用安装任何软件,实在太方便了,分享给大家. 1.usb启动盘格式化 2.制作启动盘 # find dis ...
- Ubuntu系统下制作USB启动盘
在Linux系统下制作系统启动盘有两种方法: 用dd命令 用Linux自带的图形界面工具 Startup Disk Creator 1. dd命令 查看挂载的U盘的设备名称 sudo fdisk -l ...
最新文章
- 基于Smiles2vec预测化合物物理性质
- 智能车竞赛创意组别对应的FQA
- python opencv 检测特定颜色
- MySQL小表join大表的正确使用姿势(straight_join 关键字的使用)
- 我的Go语言学习之旅二:入门初体验 Hello World
- 7月1日 cf总结
- 算法(5)-leetcode-explore-learn-数据结构-字符串
- Problem I: 函数---判断某年某月某日是这一年中的第几天
- mysql 查询语句 过滤_MySQL全面瓦解7:查询的过滤条件
- spring boot定时任务解析
- 开发新概念:代码管理(代码框架)
- 编写xml文件不当时会出现R文件找不到情况
- 搜索效果和搜索动画效果
- aspen稳态导出动态_Aspen Dynamic 针对精馏塔的模拟设计过程详解 | APP技术稿第1期...
- python教学计划_2017从零开始数据分析学习计划
- 51单片机蜂鸣器操作
- html制作统计期末成绩,如何用Excel制作学生成绩统计表
- 计算机属性高级是灰色的,Win10文件夹属性隐藏选项为灰色不可勾选怎么办?
- C++算法:最大回文子串---动态规划-----夹逼法----中心扩展法
- LeetCode哈希表(哈希集合,哈希映射)