Differences between revisions 9 and 10
Revision 9 as of 2018-04-24 15:51:15
Size: 4501
Editor: TriMoon
Comment: Added new section with an automation script
Revision 10 as of 2018-04-24 18:57:37
Size: 5706
Editor: TriMoon
Comment: Updated script to v0.2. It will now automatically use Grub2 config when detected.
Deletions are marked like this. Additions are marked like this.
Line 56: Line 56:
Here are some line numbers with explanation:
 * ~-#12-~ The label you will see in the EFI boot menu.
 * ~-#13-~ The kernel image to use by the UEFI-BIOS. ~-'''''(inside the EFI partition)'''''-~
 * ~-#14-~ The initrd image to use by the UEFI-BIOS. ~-'''''(inside the EFI partition)'''''-~
 * ~-#16-~ The '/' file system to use by the kernel. ~-'''''(Automatically found from running system)'''''-~
 * ~-#17-~ The file system type of '/'. ~-'''''(Automatically found from running system)'''''-~
 * ~-#18-~ Default kernel parameters.
 * ~-#19-21-~ Extra kernel parameters.
Here are some line numbers with usage explanation:
 * ~-#13-~ The label you will see in the EFI boot menu.
 * ~-#14-~ The kernel image to use by the UEFI-BIOS. ~-'''''(must be inside the EFI partition)'''''-~
 * ~-#15-~ The initrd image to use by the UEFI-BIOS. ~-'''''(must be inside the EFI partition)'''''-~
 * ~-#17-20-~ Compose default kernel parameters.
  * ~-#18-~ Sets the file system partition for
'/' to use by the kernel. ~-'''''(Automatically found from running system)'''''-~
  * ~-#19-~ Sets the file system type of '/' for use by the kernel. ~-'''''(Automatically found from running system)'''''-~
  * ~-#20-~ Sets the initrd image for use by the kernel. ~-'''''(from value at #15)'''''-~
 * ~-#24-~ Grabs the default kernel parameters in use inside Grub2's config file. ~-'''''(Automatically found from running system)'''''-~
 * ~-#27-38-~ Combine default and extra kernel parameters.
  * ~-#28-30-~ Used when Grub2 config is detected ~-'''''(Combines values from
#18-20 with #24)'''''-~
  * ~-#32-37-~ Used when there is NO Grub2 config detected. ~-'''''(Combines values from #18-20 with Manual extra
kernel parameters)'''''-~
   * ~-#34-37-~ Manual extra kernel parameters that you can set that will be appended to the defaults from #18-20
.
Line 66: Line 71:
# create_EFI_Boot_Entry.sh v0.1 Automatically create an EFI Boot entry. # /sbin/create_EFI_Boot_Entry.sh v0.2
#
Automatically create an EFI Boot entry.
Line 69: Line 75:
#  ------------------------------------------------
#  License: BY-SA 4.0
#  This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
#  https://creativecommons.org/licenses/by-sa/4.0/
# ------------------------------------------------
# License: BY-SA 4.0
# This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
# https://creativecommons.org/licenses/by-sa/4.0/
Line 79: Line 85:
# Compose default kernel arguments for an EFI-boot
Line 80: Line 87:
 "root=UUID=$(findmnt -kno UUID /)" \  "root=UUID=$(findmnt -kno UUID /) ro" \
Line 82: Line 89:
 "ro quiet splash" \
 "add_efi_memmap" \
 "intel_iommu=on" \
 "nvidia-drm.modeset=1" \
 "initrd=$initrd"
 "initrd=${initrd}"
# Grab extra kernel arguments from grub2 config.
grub_cmdline=''
if test -f /etc/default/grub; then
 grub_cmdline="$(sed -nE '/^GRUB_CMDLINE_LINUX_DEFAULT=\"/ {s#GRUB_CMDLINE_LINUX_DEFAULT=\"##; s#\"$##; p}' </etc/default/grub)"
fi
# Append extra kernel arguments
if test -n "${grub_cmdline}"; then
 printf -v largs "%s " \
  "${largs%* }" \
  "${grub_cmdline}"
else
 printf -v largs "%s " \
  "${largs%* }" \
  "quiet splash" \
  "add_efi_memmap" \
  "intel_iommu=on" \
  "nvidia-drm.modeset=1"
fi
# echo "${largs%* }"; exit
Line 89: Line 110:
efibootmgr -c -L "${label}" -l "${loader}" -u "${largs%* }"
}}}
efibootmgr -c -L "${label}" -l "${loader}" -u "${largs%* }"}}}

Translation(s): none


Since Wheezy, Debian kernel on x86 contain their own BootLoader called EFI stub. Therefore it is possible to load the kernel directly, without any additional bootloader (like grub-efi).

Copy the files

The UEFI firmware is only able to load files from the EFI partition (usually FAT). If you use a standard UEFI installation of Debian, you should copy the kernel and the initrd to /boot/efi. The best way to keep it up to date is to place a script in /etc/kernel/postinst.d/zz-update-efistub:

   1 #!/bin/sh
   2 cp /vmlinuz /boot/efi/EFI/debian/

Make it executable and launch it manually:

chmod +x /etc/kernel/postinst.d/zz-update-efistub
/etc/kernel/postinst.d/zz-update-efistub

/etc/initramfs/post-update.d/zz-update-efistub (create the directory if it does not exist):

   1 #!/bin/sh
   2 cp /initrd.img /boot/efi/EFI/debian/

Make it executable and launch it manually:

chmod +x /etc/initramfs/post-update.d/zz-update-efistub
/etc/initramfs/post-update.d/zz-update-efistub

Add the boot entry

Replace /dev/sda3 with the device of your / partition, see the efibootmgr manpage if you EFI partition is not /dev/sda1:

export UUID=$(blkid -s UUID -o value /dev/sda3)
efibootmgr -c -g -L "Debian (EFI stub)" -l '\EFI\debian\vmlinuz' -u "root=UUID=$UUID ro quiet rootfstype=ext4 add_efi_memmap initrd=\\EFI\\debian\\initrd.img"

You can check your new boot entry. Since EFI uses UCS2, it should look like this:

#efibootmgr -v
...
.i.n.i.t.r.d.=.\.E.F.I.\.d.e.b.i.a.n.\.i.n.i.t.r.d.

Or add the boot entry with a script

  1. Create the script below with it's contents. (Tip: Highlight and copy with linenumbers hidden)

  2. Edit the parts to accommodate your needs.
  3. Make it executable.
    • chmod a+x create_EFI_Boot_Entry.sh

  4. Execute the script as root.

    • sudo create_EFI_Boot_Entry.sh

  5. (./) -- TriMoon 2018-04-24 15:51:14 B) {OK}

Here are some line numbers with usage explanation:

  • #13 The label you will see in the EFI boot menu.

  • #14 The kernel image to use by the UEFI-BIOS. (must be inside the EFI partition)

  • #15 The initrd image to use by the UEFI-BIOS. (must be inside the EFI partition)

  • #17-20 Compose default kernel parameters.

    • #18 Sets the file system partition for '/' to use by the kernel. (Automatically found from running system)

    • #19 Sets the file system type of '/' for use by the kernel. (Automatically found from running system)

    • #20 Sets the initrd image for use by the kernel. (from value at #15)

  • #24 Grabs the default kernel parameters in use inside Grub2's config file. (Automatically found from running system)

  • #27-38 Combine default and extra kernel parameters.

    • #28-30 Used when Grub2 config is detected (Combines values from #18-20 with #24)

    • #32-37 Used when there is NO Grub2 config detected. (Combines values from #18-20 with Manual extra kernel parameters)

      • #34-37 Manual extra kernel parameters that you can set that will be appended to the defaults from #18-20.

   1 #!/usr/bin/env bash
   2 #       /sbin/create_EFI_Boot_Entry.sh v0.2
   3 #       Automatically create an EFI Boot entry.
   4 #
   5 #       (C) 2018+ ©TriMoon™ <https://github.com/TriMoon>
   6 #       ------------------------------------------------
   7 #       License: BY-SA 4.0
   8 #       This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
   9 #       https://creativecommons.org/licenses/by-sa/4.0/
  10 #
  11 
  12 # First compose the variables used as arguments:
  13 label='Debian (EFI stub)'
  14 loader='\EFI\debian\vmlinuz' # Use single \'s !
  15 initrd='\EFI\debian\initrd.img' # Use single \'s !
  16 # Compose default kernel arguments for an EFI-boot
  17 printf -v largs "%s " \
  18         "root=UUID=$(findmnt -kno UUID /) ro" \
  19         "rootfstype=$(findmnt -kno FSTYPE /)" \
  20         "initrd=${initrd}"
  21 # Grab extra kernel arguments from grub2 config.
  22 grub_cmdline=''
  23 if test -f /etc/default/grub; then
  24         grub_cmdline="$(sed -nE '/^GRUB_CMDLINE_LINUX_DEFAULT=\"/ {s#GRUB_CMDLINE_LINUX_DEFAULT=\"##; s#\"$##; p}' </etc/default/grub)"
  25 fi
  26 # Append extra kernel arguments
  27 if test -n "${grub_cmdline}"; then
  28         printf -v largs "%s " \
  29                 "${largs%* }" \
  30                 "${grub_cmdline}"
  31 else
  32         printf -v largs "%s " \
  33                 "${largs%* }" \
  34                 "quiet splash" \
  35                 "add_efi_memmap" \
  36                 "intel_iommu=on" \
  37                 "nvidia-drm.modeset=1"
  38 fi
  39 # echo "${largs%* }"; exit
  40 # Then create the EFI entry:
  41 efibootmgr -c -L "${label}" -l "${loader}" -u "${largs%* }"

If you were installing Debian from UEFI medium, efibootmgr should be installed by default. However, sometimes it can report that EFI variables are not supported. If you are sure that you have EFI partition, probably you need to download efivar package and modprobe efivars module.


CategoryBootProcess