From 68807f7e601340ddb16026d54873ece3c0beb451 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Fri, 11 Dec 2020 15:07:25 +0100 Subject: [PATCH] Script to create (partition, mount,...) EFI device --- debian/create.efi.device.sh | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 debian/create.efi.device.sh diff --git a/debian/create.efi.device.sh b/debian/create.efi.device.sh new file mode 100755 index 0000000..abbb1a1 --- /dev/null +++ b/debian/create.efi.device.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +EFI_MOUNTPATH="/boot/efi" + +# Show a warning if not in a chroot (a rescue/chroot mode is mostly attempted) +if ! ischroot; then + printf "%s" "Take care, you are not in a chroot environment !\n" +fi + +# Select the future EFI partition +printf "%b" "Select device and partition to use for UEFI Stub (eg. /dev/sdd1) :\n" +read -r EFI_PARTITION + +# Test if partition exists +if [ ! -b "${EFI_PARTITION}" ]; then + EFI_DEVICE=$(printf "%s" "${EFI_PARTITION}" | sed "s;\(/dev/...\).*;\1;") + + printf "%b\n" "${EFI_PARTITION} partition doesn't exist. Create it with parted." + parted "${EFI_DEVICE}" mklabel gpt + parted "${EFI_DEVICE}" mkpart primary 1049kB 1gB +fi + +# Enable boot flag +parted "${EFI_DEVICE}" set 1 boot on +# Format in vfat +mkfs.fat "${EFI_PARTITION}" + +# Create mountpoint if needed +mkdir -p -- "${EFI_MOUNTPATH}" +# And mount it if not already mounted +mountpoint -q "${EFI_MOUNTPATH}" || mount -- "${EFI_PARTITION}" "${EFI_MOUNTPATH}" + +# Add EFI device automount in fstab +EFI_UUID=$(blkid -s UUID -o value "${EFI_PARTITION}") +printf "%b\n" "UUID=${EFI_UUID} ${EFI_MOUNTPATH} vfat defaults,x-systemd.automount,x-systemd.device-timeout=2,x-systemd.idle-timeout=1min,noatime,noauto 0 2" >> /etc/fstab + +# Install required packages +aptitude install -y efibootmgr efivar + +# Copy kernel and initrd +printf "%b\n" "Copy kernel and initramfs to EFI partition : ${EFI_MOUNTPATH}" +mkdir -p -- "${EFI_MOUNTPATH}"/EFI/debian/ +cp /vmlinuz /initrd.img -- "${EFI_MOUNTPATH}" + +exit 0