Sample Header Ad - 728x90

Script to install Debian has UEFI issues, acts inconsistently across machines

0 votes
1 answer
318 views
For my own personal purposes, I am writing a script in order to automate installation of a custom Debian system onto the hard drive of whatever computer the script is running on. This script is intended to be used from any live Linux distribution. I am aware of Debian preseeding - unfortunately, preseeding is not a viable solution in this situation. The script works. However, it does not work consistently. On some machines (for example, my 2011 Macbook Air), the new EFI configuration is updated without any issues. However, on some machines (notably newer Dell laptops), I have to go into the BIOS and manually add my \EFI\debian\grubx64.efi file. How would I alter the below script in order to accommodate most modern UEFI systems? I am aware that I will likely need to alter my efibootmgr commands below. #!/bin/bash # Preliminary commands set -e echo "Available disks:" current_disk=$(df / | awk 'NR==2 {print $1}') for disk in $(lsblk -dnro NAME,TYPE | awk '$2=="disk" {print $1}'); do if [ "$disk" != "${current_disk#/dev/}" ]; then size=$(lsblk -dnro SIZE "/dev/$disk") echo "/dev/$disk: $size" fi done read -p "Enter the disk you want to install Debian on (e.g. /dev/sda): " disk mkdir -p /mnt sgdisk --zap-all "$disk" > /dev/null parted "$disk" mklabel gpt parted "$disk" mkpart ESP fat32 0% 512MB parted "$disk" mkpart primary ext4 512MB 100% # Set up main partition yes | mkfs.ext4 "${disk}2" mount "${disk}2" /mnt # Set up EFI partition yes | mkfs.fat -F32 "${disk}1" mkdir -p /mnt/efi mount "${disk}1" /mnt/efi debootstrap --arch=amd64 buster /mnt http://ftp.us.debian.org/debian/ # Set up bindings mount --bind /dev /mnt/dev mount --bind /proc /mnt/proc mount --bind /sys /mnt/sys # Chroot to set up grub chroot /mnt /bin/bash << "EOT" apt update -y apt install -y linux-image-amd64 grub-efi-amd64 grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=debian --recheck --no-floppy update-grub EOT # Set the path to your .EFI file efi_file="\EFI\debian\grubx64.efi" bootnum=$(efibootmgr -v | grep "Boot" | awk '{print $1}' | sed 's/Boot//g' | sort -n | tail -1 | awk '{print $1+1}') efibootmgr -c -d "$disk" -p 1 -L "Debian" -l "${efi_file}" -b "${bootnum}" efibootmgr -o "${bootnum}" # Unmount bindings umount -l /mnt/sys umount -l /mnt/proc umount -l /mnt/dev # Unmount filesystems umount -l /mnt/efi umount -l /mnt reboot
Asked by Ethan Hill (131 rep)
Apr 13, 2023, 11:46 AM
Last activity: Apr 13, 2023, 01:05 PM