I am using debootstrap to create a custom Xenial-based distro which can then be written to a secondary bootable drive from a host machine. (Target is an Intel NUC.) When I put the drive in the target PC and power on, the EFI recognizes the bootable drive but cannot boot it (it immediately returns to the EFI boot menu.)
So I don't believe I'm actually getting as far as grub launching. I'm guessing this is a grub install/config issue.
Relevant portion of my script:
local DISK=$1 # e.g. /dev/sdc
local EFI_PARTITION=${DISK}1
local ROOT_PARTITION=${DISK}2
local ROOT_MOUNT=$(mktemp -d)
# create partitions and format
parted -s --align=minimal $DISK \
mklabel gpt \
mkpart ESP fat32 0% 513MiB \
mkpart primary ext4 513MiB 100% \
set 1 boot on
partprobe $DISK
sleep 1
mkfs.fat -F32 $EFI_PARTITION
mkfs.ext4 $ROOT_PARTITION
# copy rootfs
mount $ROOT_PARTITION $ROOT_MOUNT
rsync -a $CHROOT_DIR/ $ROOT_MOUNT
# enter chroot and install grub
for dir in /dev /proc /sys /run; do
mount --bind $dir $ROOT_MOUNT/$dir
done
mkdir $ROOT_MOUNT/boot/efi
mount $EFI_PARTITION $ROOT_MOUNT/boot/efi
chroot $ROOT_MOUNT <<EOF
/usr/sbin/grub-install --bootloader-id=ubuntu ${DISK}
/usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg
EOF
# generate fstab and additional customizations
# sync, unmount eject
I do see the correct partition UUID in the resulting grub.cfg.
Here's my partition details:
$ sudo parted /dev/sdb print
Model: ASMT 2115 (scsi)
Disk /dev/sdb: 64.0GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 538MB 538MB fat32 ESP boot, esp
2 538MB 64.0GB 63.5GB ext4 primary
After I added shim-singed
to my debootsrap includes, here's what I see in /boot/efi
:
$ sudo tree efi
efi
└── EFI
└── ubuntu
├── grub.cfg
├── grubx64.efi
├── MokManager.efi
└── shimx64.efi
After renaming EFI/ubuntu
to EFI/BOOT
and shimx64.efi
to bootx64.efi
I can boot from the drive! However I get a grub prompt... Guessing I'm down to grub config issues now.
I've been using these docs as my primary sources:
To be clear, I'm attempting to install a linux kernel/rootfs/bootloader to a drive connected to a host machine. That bootable drive is then put into a target machine and booted. This is not a dual-boot scenario.
Do I need to do something with efibootmgr
on the target?