Differences between revisions 1 and 13 (spanning 12 versions)
Revision 1 as of 2013-06-18 13:08:25
Size: 1625
Editor: ?BertrandMarc
Comment: Howto EFI stub
Revision 13 as of 2021-04-21 07:05:01
Size: 6397
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from EFIStub
Line 7: Line 8:
## <<TableOfContents(2)>> <<TableOfContents(2)>>
Line 13: Line 14:
cp -u /vmlinuz /initrd /boot/efi/EFI/debian/ cp /vmlinuz /boot/efi/EFI/debian/
Line 18: Line 19:
./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):
{{{#!highlight bash
#!/bin/sh
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
Line 22: Line 34:
Replace the UUID with the one of your / partition, see the [[http://manpages.debian.net/cgi-bin/man.cgi?query=efibootmgr|efibootmgr manpage]] if you EFI partition is not /dev/sda1: Replace /dev/sda3 with the device of your / partition, see the [[http://manpages.debian.net/cgi-bin/man.cgi?query=efibootmgr|efibootmgr manpage]] if you EFI partition is not /dev/sda1:
Line 24: Line 36:
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 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"
Line 26: Line 39:

You may have to add --disk /dev/nvme0n1 in case it's not auto detected (nvme0n1 being the disk with the EFI partition).
Line 31: Line 47:
}}}

=== Or add the boot entry with a script ===
 1. Create the script below with it's contents. ~-'''''(Tip: Highlight and copy with linenumbers hidden)'''''-~
 1. Edit the parts to accommodate your needs.
  * See the [[http://manpages.debian.net/cgi-bin/man.cgi?query=bash|bash]], [[http://manpages.debian.net/cgi-bin/man.cgi?query=findmnt|findmnt]] and [[http://manpages.debian.net/cgi-bin/man.cgi?query=efibootmgr|efibootmgr]] manpage's of the utilities used for/in this script.
 1. Make it executable.
  ~-''chmod a+x /sbin/create_EFI_Boot_Entry.sh''-~
 1. Execute the script as '''root'''.
  ~-''sudo create_EFI_Boot_Entry.sh''-~
 * (./) -- TriMoon <<DateTime(2018-04-24T22:12:01+0300)>> 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.
{{{#!highlight bash
#!/usr/bin/env bash
# /sbin/create_EFI_Boot_Entry.sh v0.2
# Automatically create an EFI Boot entry.
#
# (C) 2018+ ©TriMoon™ <https://github.com/TriMoon>
# ------------------------------------------------
# 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/
#

# First compose the variables used as arguments:
label='Debian (EFI stub)'
loader='\EFI\debian\vmlinuz' # Use single \'s !
initrd='\EFI\debian\initrd.img' # Use single \'s !
# Compose default kernel arguments for an EFI-boot
printf -v largs "%s " \
 "root=UUID=$(findmnt -kno UUID /) ro" \
 "rootfstype=$(findmnt -kno FSTYPE /)" \
 "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
# Then create the EFI entry:
efibootmgr -c -L "${label}" -l "${loader}" -u "${largs%* }"}}}
On my system this EFI-entry was created using the script above:
{{{
Boot0000* Debian (EFI stub) HD(1,GPT,1e4d16a9-ba85-4a29-9fd1-277c77f4e461,0x800,0x100000)/File(\EFI\DEBIAN\VMLINUZ)r.o.o.t.=.U.U.I.D.=.7.9.2.0.e.1.9.8.-.5.0.5.6.-.4.e.b.4.-.b.3.7.c.-.1.a.b.f.8.1.c.5.a.e.8.d. .r.o. .r.o.o.t.f.s.t.y.p.e.=.e.x.t.4. .i.n.i.t.r.d.=.\.E.F.I.\.d.e.b.i.a.n.\.i.n.i.t.r.d...i.m.g. .q.u.i.e.t. .s.p.l.a.s.h. .i.n.t.e.l._.i.o.m.m.u.=.o.n. .n.v.i.d.i.a.-.d.r.m...m.o.d.e.s.e.t.=.1. .h.u.g.e.p.a.g.e.s.z.=.1.G.B. .h.u.g.e.p.a.g.e.s.=.4.
}}}
{{{#!wiki tip
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.

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).

Contents

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 may have to add --disk /dev/nvme0n1 in case it's not auto detected (nvme0n1 being the disk with the EFI partition).

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 /sbin/create_EFI_Boot_Entry.sh

  4. Execute the script as root.

    • sudo create_EFI_Boot_Entry.sh

  5. (./) -- TriMoon 2018-04-24 19:12:01 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%* }"

On my system this EFI-entry was created using the script above:

Boot0000* Debian (EFI stub)     HD(1,GPT,1e4d16a9-ba85-4a29-9fd1-277c77f4e461,0x800,0x100000)/File(\EFI\DEBIAN\VMLINUZ)r.o.o.t.=.U.U.I.D.=.7.9.2.0.e.1.9.8.-.5.0.5.6.-.4.e.b.4.-.b.3.7.c.-.1.a.b.f.8.1.c.5.a.e.8.d. .r.o. .r.o.o.t.f.s.t.y.p.e.=.e.x.t.4. .i.n.i.t.r.d.=.\.E.F.I.\.d.e.b.i.a.n.\.i.n.i.t.r.d...i.m.g. .q.u.i.e.t. .s.p.l.a.s.h. .i.n.t.e.l._.i.o.m.m.u.=.o.n. .n.v.i.d.i.a.-.d.r.m...m.o.d.e.s.e.t.=.1. .h.u.g.e.p.a.g.e.s.z.=.1.G.B. .h.u.g.e.p.a.g.e.s.=.4.

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