原文链接:https://www.lainme.com/doku.php/blog/2017/07/%E5%88%B6%E4%BD%9Cbios%E5%92%8Cefi%E5%A4%9A%E5%90%AF%E5%8A%A8u%E7%9B%98
准备分区
U盘使用的是MBR分区表(GPT应该也行),并分为两个区:
-
第一分区:FAT32格式,作为引导分区/EFI分区,大小以100MB为宜。
-
第二分区:EXT4或其他你喜欢的格式,存放ISO和其他文件。
安装引导
启动引导使用GRUB,并假设第一分区是/dev/sdb1。先挂载分区
sudo mount /dev/sdb1 /mnt
然后安装BIOS引导
sudo grub-install --target=i386-pc --boot-directory=/mnt/boot --recheck /dev/sdb
再安装EFI引导
sudo grub-install --target=x86_64-efi --efi-directory=/mnt --boot-directory=/mnt/boot --removable --recheck
配置引导
假设其他文件都存放于第二分区(/dev/sdb2),并包含以下目录/文件
-- slax/ -- images/archlinux.iso -- images/ubuntu-gnome.iso
则建立/mnt/boot/grub/grub.cfg文件,并写入以下内容
insmod search_fs_uuid set rootuuid=[第二分区的UUID] set rootpath=/dev/disk/by-uuid/$rootuuid search --no-floppy --set=rootpart --fs-uuid $rootuuid insmod vbe insmod efi_gop insmod efi_uga insmod font if loadfont ${prefix}/fonts/unicode.pf2 then insmod gfxterm set gfxmode=auto set gfxpayload=keep terminal_output gfxterm fi menuentry 'Slax' { set syspath=/slax set root=$rootpart linux $syspath/boot/vmlinuz from=$syspath vga=normal load_ramdisk=1 prompt_ramdisk=0 printk.time=0 slax.flags=perch,xmode initrd $syspath/boot/initrfs.img } menuentry '[LiveCD] Archlinux' { set isopath=/images/archlinux.iso loopback loop ($rootpart)$isopath linux (loop)/arch/boot/x86_64/vmlinuz archisodevice=/dev/loop0 img_dev=$rootpath img_loop=$isopath initrd (loop)/arch/boot/x86_64/archiso.img } menuentry '[LiveCD] Ubuntu (GNOME)' { set isopath='/images/ubuntu-gnome.iso' loopback loop ($rootpart)$isopath linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isopath locale=zh_CN.UTF-8 initrd (loop)/casper/initrd.lz }
其中[第二分区的UUID]可以通过以下命令获取:
sudo blkid /dev/sdb2
自作过程记录:
-- slax/
-- images/opensuse-kde32.iso
-- images/opensuse-kde64.iso
-- images/manjaro-kde32.iso
-- images/manjaro-kde64.iso
-- images/manjaro-xfce64.iso
-- images/ubuntu18.04.3.iso
使用命令:blkid /dev/sdb5 获取分区的UUID:DA18-EBFA, 还有:TYPE="vfat" PARTUUID="969d4ec8-05"
insmod search_fs_uuid
set rootuuid=[DA18-EBFA]
set rootpath=/dev/disk/by-uuid/$rootuuid
search --no-floppy --set=rootpart --fs-uuid $rootuuid
insmod vbe
insmod efi_gop
insmod efi_uga
insmod font
if loadfont ${prefix}/fonts/unicode.pf2
then
insmod gfxterm
set gfxmode=auto
set gfxpayload=keep
terminal_output gfxterm
fi
menuentry 'Slax' {
set syspath=/slax
set root=$rootpart
linux $syspath/boot/vmlinuz from=$syspath vga=normal load_ramdisk=1 prompt_ramdisk=0 printk.time=0 slax.flags=perch,xmode
initrd $syspath/boot/initrfs.img
}
menuentry '[LiveCD] OpenSuseKde32' {
set isopath=/images/opensuse-kde32.iso
loopback loop ($rootpart)$isopath
linux (loop)/arch/boot/x86_64/vmlinuz archisodevice=/dev/loop0 img_dev=$rootpath img_loop=$isopath
initrd (loop)/arch/boot/x86_64/archiso.img
}
menuentry '[LiveCD] OpenSuseKde64' {
set isopath=/images/opensuse-kde64.iso
loopback loop ($rootpart)$isopath
linux (loop)/arch/boot/x86_64/vmlinuz archisodevice=/dev/loop0 img_dev=$rootpath img_loop=$isopath
initrd (loop)/arch/boot/x86_64/archiso.img
}
menuentry '[LiveCD] Ubuntu (GNOME)' {
set isopath='/images/ubuntu-gnome.iso'
loopback loop ($rootpart)$isopath
linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isopath locale=zh_CN.UTF-8
initrd (loop)/casper/initrd.lz
}