usb启动盘安装grub

EFI启动方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# u盘是sdb的情况下
mkdir /mnt/1
mkdir /mnt/2
mkdir /mnt/3

local dev="sdb"
umount ${dev}*
parted -s ${dev} mklabel gpt # GPT
parted -s ${dev} mkpart ESP fat32 1MiB 301MiB set 1 esp on
parted -s ${dev} mkpart boot ext4 301MiB 701MiB
parted -s ${dev} mkpart primary ext4 701MiB 100%

mkfs.vfat -F 32 ${dev}1
mkfs.ext4 -F ${dev}2
mkfs.ext4 -F ${dev}3

local boot_dir=/mnt/1
local grub_boot=/mnt/2
local target=x86_64-efi # x86_64-efi x86架构;arm64-efi arm架构
grub-install --efi-directory=${boot_dir} --boot-directory=${grub_boot} --target=${target} ${dev} --removable --bootloader-id=ubuntu