这个故事要从一个dd工具说起。本来只是想要dd一个系统到u盘的,奈何我的电脑为window,也不想去找window下的dd工具,于是突发奇想装个linux live到u盘,要用到linux下的工具的时候只需插上u盘即可。
生命不息,折腾不止,那就干吧。
本来以为很简单,确实也很简单。
下载了个debian-live-10.0.0-i386-standard.iso
用Rufus工具把iso写进去创建个USB启动盘不就行了嘛
ok,启动盘创建好了。重启电脑,选择U盘启动,无法启动,折腾就此开启。
经过n多次尝试,google各种资料,最终发现,归根到底是自己不够理解原理的原因。
其中值得关注的几个点记录一下。
为什么会启动不了呢?
一开始以为是创建的USB启动盘是MBR分区,但我的电脑是uefi启动而非legacy启动的,不匹配?但改为GPT分区也是不行。
并非分区的问题。
UEFI启动的条件:
1. 磁盘(U盘)必须有一个ESP分区(EFI system partition – EFI系统分区)。
2. ESP分区其实就是一个文件系统为FAT格式(FAT16/FAT32)的分区。
3. ESP分区下面存在EFI启动程式,放在/EFI/Boot目录下,如:/efi/boot/bootx64.efi
即UEFI固件会执行U盘下FAT格式分区的/efi/boot/bootx64.efi启动程式
简单说就是把U盘格式化为FAT32文件系统,UEFI固件便会执行/efi/boot/bootx64.efi启动程式
我便是在这里发现了盲点,我的电脑是x64的,UEFI固件会执行/efi/boot/bootx64.efi这个启动程式,但我发现制作的USB启动盘并没有这个文件,才发现我下的iso是i386的…
解决了这个问题之后,我又想着进一步折腾这个U盘了,玩玩GRUB2,然后多个linux live…
玩转GRUB
1. 格式化U盘
根据上面的经验,把整个U盘格式化为FAT格式,把整个U盘当成ESP分区。
当然,把U盘分多个区也行,但必须要有一个ESP分区。
分区表是MBR或GPT都行。
2. 下载GRUB
到GRUB官网下载 grub-2.06-for-windows.zip :
https://ftp.gnu.org/gnu/grub/
3. 安装GRUB
解压下载的zip,管理员模式打开命令行,cd到解压的目录。
贴一下安装程序的help:
PS C:\F\int\grub-2.06-for-windows> .\grub-install.exe --help
Usage: grub-install.exe [OPTION...] [OPTION] [INSTALL_DEVICE]
Install GRUB on your drive.
--compress=no|xz|gz|lzo compress GRUB files [optional]
--disable-shim-lock disable shim_lock verifier
--dtb=FILE embed a specific DTB
-d, --directory=DIR use images and modules under DIR
[default=C:\F\int\grub-2.06-for-windows/<platform>]
--fonts=FONTS install FONTS [default=unicode]
--install-modules=MODULES install only MODULES and their dependencies
[default=all]
-k, --pubkey=FILE embed FILE as public key for signature checking
--locale-directory=DIR use translations under DIR
[default=C:\F\int\grub-2.06-for-windows/locale]
--locales=LOCALES install only LOCALES [default=all]
--modules=MODULES pre-load specified modules MODULES
--sbat=FILE SBAT metadata
--themes=THEMES install THEMES [default=starfield]
-v, --verbose print verbose messages.
--allow-floppy make the drive also bootable as floppy (default
for fdX devices). May break on some BIOSes.
--boot-directory=DIR install GRUB images under the directory DIR/grub
instead of the boot/grub directory
--bootloader-id=ID the ID of bootloader. This option is only
available on EFI and Macs.
--core-compress=xz|none|auto
choose the compression to use for core image
--disk-module=MODULE disk module to use (biosdisk or native). This
option is only available on BIOS target.
--efi-directory=DIR use DIR as the EFI System Partition root.
--force install even if problems are detected
--force-file-id use identifier file even if UUID is available
--label-bgcolor=COLOR use COLOR for label background
--label-color=COLOR use COLOR for label
--label-font=FILE use FILE as font for label
--macppc-directory=DIR use DIR for PPC MAC install.
--no-bootsector do not install bootsector
--no-nvram don't update the `boot-device'/`Boot*' NVRAM
variables. This option is only available on EFI
and IEEE1275 targets.
--no-rs-codes Do not apply any reed-solomon codes when
embedding core.img. This option is only available
on x86 BIOS targets.
--product-version=STRING use STRING as product version
--recheck delete device map if it already exists
--removable the installation device is removable. This option
is only available on EFI.
-s, --skip-fs-probe do not probe for filesystems in DEVICE
--target=TARGET install GRUB for TARGET platform
[default=x86_64-efi]; available targets:
arm-coreboot, arm-efi, arm-uboot, arm64-efi,
i386-coreboot, i386-efi, i386-ieee1275,
i386-multiboot, i386-pc, i386-qemu, i386-xen,
i386-xen_pvh, ia64-efi, mips-arc, mips-qemu_mips,
mipsel-arc, mipsel-loongson, mipsel-qemu_mips,
powerpc-ieee1275, riscv32-efi, riscv64-efi,
sparc64-ieee1275, x86_64-efi, x86_64-xen
-?, --help give this help list
-V, --version print program version
--usage give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
INSTALL_DEVICE must be system device filename.
C:\F\int\grub-2.06-for-windows\grub-install.exe copies GRUB images into
boot/grub. On some platforms, it may also install GRUB into the boot sector.
Report bugs to <bug-grub@gnu.org>.
执行下面命令即可把GRUB安装到U盘(根据实际情况替换 “G:\boot” 和 \\.\PHYSICALDRIVE2):
// 安装传统BIOS平台的GRUB2 > .\grub-install.exe --target="i386-pc" --boot-directory="G:\boot" \\.\PHYSICALDRIVE2 Installing for i386-pc platform. Installation finished. No error reported. // 安装32位UEFI平台的GRUB2 > .\grub-install.exe --target="i386-efi" --boot-directory="G:\boot" --efi-directory="G:\" --removable Installing for i386-efi platform. Installation finished. No error reported. // 安装64位UEFI平台的GRUB2 > .\grub-install.exe --target="x86_64-efi" --boot-directory="G:\boot" --efi-directory="G:\" --removable Installing for x86_64-efi platform. Installation finished. No error reported.
查看 \\.\PHYSICALDRIVE2 (DeviceID) 可使用命令 wmic diskdrive list brief
好了,安装好GRUB可以看到U盘目录下就有了 G:\EFI\BOOT\BOOTX64.EFI 启动程式了,理论上现在是可以进入到GRUB界面的,验证一下
