I'm working on a Dell Latitude 7480. I wrote a bash script that is intended to be run from a live Linux distribution, and its intention is to wipe /dev/sda and install a base Debian system.

Here's the script:


# Set up partitions
echo "Set up partitions..."
sgdisk --zap-all /dev/sda
parted /dev/sda mklabel gpt
parted /dev/sda mkpart primary ext4 512MB 100%
parted /dev/sda mkpart primary fat32 0% 512MB
yes | mkfs.ext4 /dev/sda1
mount /dev/sda1 /mnt

echo "Setting up base system..."
debootstrap --arch=amd64 buster /mnt http://ftp.us.debian.org/debian/ > /dev/null 2>&1

# Set up bindings
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys

# Set up EFI partition
yes | mkfs.fat -F32 /dev/sda2
mkdir /mnt/boot/efi
mount /dev/sda2 /mnt/boot/efi

# Chroot to set up grub
chroot /mnt /bin/bash << "EOT"
echo "deb http://deb.debian.org/debian/ stable main contrib non-free" >> /etc/apt/sources.list
echo "deb-src http://deb.debian.org/debian/ stable main contrib non-free" >> /etc/apt/sources.list
dpkg --add-architecture i386
apt update -y
apt upgrade -y
apt install -y linux-image-amd64 grub-efi-amd64
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck --no-floppy

So far, it seems to work fine. However, my Dell workstation is forcing me to go into my BIOS and manually add the grubx64.efi file to my boot list. I need to be able to automate this installation for someone else, which means that I need to be able to avoid this step.

What could I add or change to the above bash script in order to automatically register my newly created .efi registry as a profile under my computer's BIOS?


1 Answer 1


In order to write data to UEFI, /sys/firmware/efi/efivars should be mounted in the chroot.

So assuming that efivars is already mounted in the host:

$ findmnt /sys/firmware/efi/efivars 
TARGET                    SOURCE   FSTYPE   OPTIONS
/sys/firmware/efi/efivars efivarfs efivarfs rw,nosuid,nodev,noexec,relatime


mount --bind /sys /mnt/sys

should be augmented to at least:

mount --bind /sys /mnt/sys
mount --bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars

so grub-install (as well as efibootmgr or any similar tool) can use it within the chroot to read or write an UEFI boot entry.

Should this still not be enough, then it's also possible to tell grub-install to write an additional EFI boot file in the EFI filesystem in addition to the one that should be pointed by the UEFI boot entry.

Add the --force-extra-removable option, as explained in the Debian Wiki. Thus giving:

grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck --no-floppy --force-extra-removable

This will write an additional entry that's supposed to be used even without UEFI boot entry.

If this was really needed, to ensure it stays that way on upgrades, one should also issue (in the chroot):

echo 'grub-efi-amd64        grub2/force_efi_extra_removable boolean true' | debconf-set-selections

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .