制作 WinPE/Linux 多启动U盘
参考:【2017.12.25】deepin安装U盘制作,支持 BIOS+UEFI,deepin_Recovery+Win PE
2018.4.28 更新
使用configfile代替了chainloader,避免重新载入grub,并且大幅减少了代码量
#########################
# 06_pc.cfg
# UEFI 模式启动
if [ 'efi' == $grub_platform ] ; then
menuentry "[b] (实验性) 正常启动" --hotkey=b{
configfile "${prefix}/Config/NormalBootList.cfg"
}
fi
#############################
# NormalBootList.cfg
set timeout=10
set default=0
search --file --no-floppy --set=root /efi/deepin/grub.cfg
search --file --no-floppy --set=root /efi/Microsoft/Boot/bootmgfw.efi
if [ -e /efi/deepin/grub.cfg ] ; then
menuentry "[g] 启动 grub" --hotkey=g{
configfile ($root)/efi/deepin/grub.cfg
}
fi
if [ -e /efi/Microsoft/Boot/bootmgfw.efi ] ; then
menuentry "[w] 启动 Windows" --hotkey=w{
chainloader ($root)/efi/Microsoft/Boot/bootmgfw.efi
boot
}
fi
2018.4.27 更新
我修改了一下grub的配置,使其支持UEFI下正常启动deepin/ubuntu/Windows系统,原理是搜索EFI分区,若找到grubx64.efi则引导grub,否则引导bootmgfw.efi
新版本下载地址:百度云 密码: kze6
源码如下:
if [ 'efi' == $grub_platform ] ; then
if [ 'x86_64' == $grub_cpu ] ; then
menuentry "[d] (实验性) 正常启动" --hotkey=d{
echo "正在链式启动,请等待...."
insmod part_gpt
insmod fat
set root=(hd1,1)
search --label --no-floppy --set=root EFI
search --file --no-floppy --set=root /EFI/ubuntu/grubx64.efi
search --file --no-floppy --set=root /EFI/Microsoft/Boot/bootmgfw.efi
#若存在深度安装的grub则引导
if [ -e /EFI/deepin/grubx64.efi ]; then
chainloader (${root})/EFI/deepin/grubx64.efi
#否则,若存在Ubuntu安装的grub则引导
elif [ -e /EFI/ubuntu/grubx64.efi ]; then
chainloader (${root})/EFI/ubuntu/grubx64.efi
#否则,若存在Windows则引导
elif [ -e /EFI/Microsoft/Boot/bootmgfw.efi ]; then
chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi
else
echo "找不到主硬盘中的grub2,请拔下U盘,按Ctrl+Alt+Del重启电脑!"
echo "Couln't find Grub2 in HDD, please remove the flash disk and press CTRL+ALT+DEL to reboot!"
fi
boot
}
else
menuentry "[d] (实验性) 正常启动" --hotkey=d{
echo "正在链式启动,请等待...."
insmod part_gpt
insmod fat
set root=(hd1,1)
search --label --no-floppy --set=root EFI
search --file --no-floppy --set=root /EFI/ubuntu/grub.efi
search --file --no-floppy --set=root /EFI/Microsoft/Boot/bootmgfw.efi
#若存在深度安装的grub则引导
if [ -e /EFI/deepin/grubx64.efi ]; then
chainloader (${root})/EFI/deepin/grub.efi
#否则,若存在Ubuntu安装的grub则引导
elif [ -e /EFI/ubuntu/grubx64.efi ]; then
chainloader (${root})/EFI/ubuntu/grub.efi
#否则,若存在Windows则引导
elif [ -e /EFI/Microsoft/Boot/bootmgfw.efi ]; then
chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi
else
echo "找不到主硬盘中的grub2,请拔下U盘,按Ctrl+Alt+Del重启电脑!"
echo "Couln't find Grub2 in HDD, please remove the flash disk and press CTRL+ALT+DEL to reboot!"
fi
boot
}
fi
fi
目前仅在64位deepin/Windows下测试通过,如果出现了bug,请尽可能详细地报告给erickwok404@gmail.com
下载制作好的启动包以及Linux的镜像
推荐使用Deepin
启动包
启动包备用地址,密码为 wwgq

Linux
U盘分区
为了达到我们不影响U盘正常使用的目的,我们将U盘分出一个5GB的空间,并且格式化为fat32,剩下的空间最好格式化为ntfs,以便存放大文件,当然fat32亦可,只不过无法存放超过4GB的大文件而已,如有需要可以考虑使用压缩分卷。
扯远了,分区操作很简单,在Windows下可以使用傲梅或者系统自带的磁盘管理工具,Linux下也有GParted可以用,顺带提一句,安装完成之后可以把相应分区标记为“隐藏”,GParted可以做到,貌似Windows磁盘管理不能,所以建议用傲梅。


制作引导
分好区应该下载好了,我们把deepin_15.5_recovery-解压到U盘根目录.7z
这个文件里面的recovery
文件夹解压到5GB的那个分区里
然后再把U盘grub2+bootmgr引导2018.1.5.7z
里面的文件解压到U盘里,现在长这样

在Linux下的话,右键使用命令行,输入sudo bash install_Legacy_bash_shell_v1.1.3.sh

输入d1

然后自动跳回主菜单,出现这个界面即为成功

此时输入0
退出
到目前,U盘的引导已经做好了,包括MBR引导与UEFI引导。
拷贝镜像
此时如果你直接重启的话,无论是哪一个系统都进不去的,因为最关键的Linux的Live镜像和WinPE镜像还没拷进U盘。


所以我们将刚刚下载好的Deepin镜像放到/U盘/PE/deepin
里,重命名为deepin.iso
覆盖掉原本的空文件
然后将这两个文件夹

也复制到
/U盘/PE
里面耐心等待……

好了,现在是这样(tree命令需要额外安装,sudo apt install tree
)

如果你发现你还有文件是0b大小的,就检查一下是不是漏了哪个没拷进来

这样就可以重启测试能否进入PE和Live了
(可选)将这个分区设为隐藏
启动GParted,卸载/dev/sdd1


勾选"hidden"即可

Windows
分区
此步骤参见Linux段
分完区之后大概是这样

制作引导
与Linux相同,将这两个文件解压到我们分好的5GB的分区下,我这里是F:


脚本会申请管理员权限,允许即可

回车,脚本会提示你“在‘分区管理’中激活分区”



出现这个提示即为成功。
拷贝镜像
此时如果你直接重启的话,无论是哪一个系统都进不去的,因为最关键的Linux的Live镜像和WinPE镜像还没拷进U盘。


我们将这两个文件夹复制到F:\PE\
里


然后将下载好的Deepin系统镜像复制到F:\PE\deepin
里,并且改名为deepin.iso
覆盖掉原本的空文件
这下就可以重启测试是否能进入live和PE了
(可选)设为隐藏
这一步需要“傲梅分区助手”或“DiskGenius”

傲梅

恭喜,你现在拥有了一个双启动U盘
