Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert Bootnum at a Specific Index in the Boot Order #126

Closed
Neurognostic opened this issue Feb 20, 2020 · 1 comment · Fixed by #166
Closed

Insert Bootnum at a Specific Index in the Boot Order #126

Neurognostic opened this issue Feb 20, 2020 · 1 comment · Fixed by #166

Comments

@Neurognostic
Copy link

Neurognostic commented Feb 20, 2020

Summary

When adding new entries to the boot order, efibootmgr(8) always places the new entry at the top of the boot order. I require the ability to insert the new entry at a specific index (i.e., position) in the boot order.

Currently, this can only be achieved by wrapping efibootmgr(8) in a script that parses the boot order before and after the new entry is created (i.e., --create), then reconstruct the boot order (i.e. --bootorder`) with the new entry at the desired index.

It's a somewhat complex operation for shell scripting that must be done anytime the user wants to create a new entry but does not want it to be at index 1; and this operation ought be supported by the tool natively.

The only alternative to the above description of reconstructing the boot order is to delete all of the boot entries in the boot order up to the index where the new entry is needed, then recreate all of the entries in reverse order to achieve the desired boot order. This has potential to cause excessive wear on the NVRAM if the user is often changing the boot order.

Implementation

efibootmgr(8) needs to:

  1. Support index option when --create option is used to specify where in the boot order to place the new entry or even to not place it in the boot order at all. Default to current behaviour, index 1.

  2. After the boot entry already exists, support operation to insert or move a specific bootnum to a specified index in the boot order. Default to placing the specified bootnum at the top of the bootorder, index 1. This is similar to Feature request: ability to edit an entry #49, but does not require editing a boot entry, only editing the boot order.

Thank you. 🖖

@Neurognostic
Copy link
Author

Neurognostic commented Feb 21, 2020

Here is an example of a "somewhat complex" shell script that creates a boot entry and sets it at index 2.

#!/bin/zsh

# Index to add new boot entry to
index=2

# Save current boot order list
bootorder=( ${(s:,:)${(M)"${(@f)"$(efibootmgr)"}":#BootOrder*}#* } )

# Create new boot entry and save its boot number
new_bootnum=${${(s.,.)${(M)"${(@f)"$(efibootmgr \
	--label 'rEFInd' --create \
	--disk /dev/disk/by-label/ESP \
	--loader EFI/BOOT/bootx64.efi)"}":#BootOrder*}#* }[1]}

# Create new boot order with rEFInd boot number in position 2
bootorder=( $bootorder[0,$index-1] $new_bootnum $bootorder[$index,-1] )

# Save new boot order to BootOrder EFI var
efibootmgr --bootorder ${(j:,:)bootorder}

As you can see, there is a lot of overhead for the user if they want to do an operation as [seemingly] simple as adding a new boot entry to the second position in the boot order.

bdk0 pushed a commit to bdk0/efibootmgr that referenced this issue May 9, 2020
Provides the functionality from Issue rhboot#126

1) When adding a new entry with -c, optionally allow an Index to be
provided with -I. If no index is provided, it defaults to 1, which
inserts the new entry first in the boot order, and provides the
same functionality as previous versions. If -I is provided, it
specifies where in the BootOrder to insert the new entry. (If -I 2
is passed, the new entry will be inserted in the second place.)
If the index specified is greater than the number of entries in the
BootOrder, the entry is placed last.

2) In addition to modifying the BootOrder by passing an entire new
BootOrder as comma-delimted string to -o, two new formats are allowed:

   -o -5 will remove entry 5 (Boot0005) from the BootOrder string
   -o +5 will add entry 5 (Boot0005) to the BootOrder string.
         By default the entry will be added at the beginning of the
         BootOrder (in first place), but this behavior can be
         overridden by specifying an index with -I as above.
         If the specified entry already exists in the BootOrder,
         then it will be moved to the specified index.
bdk0 pushed a commit to bdk0/efibootmgr that referenced this issue May 9, 2020
Provides the functionality from Issue rhboot#126

1) When adding a new entry with -c, optionally allow an Index to be
provided with -I. If no index is provided, it defaults to 1, which
inserts the new entry first in the boot order, and provides the
same functionality as previous versions. If -I is provided, it
specifies where in the BootOrder to insert the new entry. (If -I 2
is passed, the new entry will be inserted in the second place.)
If the index specified is greater than the number of entries in the
BootOrder, the entry is placed last.

2) In addition to modifying the BootOrder by passing an entire new
BootOrder as comma-delimted string to -o, two new formats are allowed:

   -o -5 will remove entry 5 (Boot0005) from the BootOrder string
   -o +5 will add entry 5 (Boot0005) to the BootOrder string.
         By default the entry will be added at the beginning of the
         BootOrder (in first place), but this behavior can be
         overridden by specifying an index with -I as above.
         If the specified entry already exists in the BootOrder,
         then it will be moved to the specified index.
bdk0 pushed a commit to bdk0/efibootmgr that referenced this issue May 9, 2020
Provides the functionality from Issue rhboot#126

1) When adding a new entry with -c, optionally allow an Index to be
provided with -I. If no index is provided, it defaults to 1, which
inserts the new entry first in the boot order, and provides the
same functionality as previous versions. If -I is provided, it
specifies where in the BootOrder to insert the new entry. (If -I 2
is passed, the new entry will be inserted in the second place.)
If the index specified is greater than the number of entries in the
BootOrder, the entry is placed last.

2) In addition to modifying the BootOrder by passing an entire new
BootOrder as comma-delimted string to -o, two new formats are allowed:

   -o -5 will remove entry 5 (Boot0005) from the BootOrder string
   -o +5 will add entry 5 (Boot0005) to the BootOrder string.
         By default the entry will be added at the beginning of the
         BootOrder (in first place), but this behavior can be
         overridden by specifying an index with -I as above.
         If the specified entry already exists in the BootOrder,
         then it will be moved to the specified index.
bdk0 pushed a commit to bdk0/efibootmgr that referenced this issue May 9, 2020
Provides the functionality from Issue rhboot#126

1) When adding a new entry with -c, optionally allow an Index to be
provided with -I. If no index is provided, it defaults to 1, which
inserts the new entry first in the boot order, and provides the
same functionality as previous versions. If -I is provided, it
specifies where in the BootOrder to insert the new entry. (If -I 2
is passed, the new entry will be inserted in the second place.)
If the index specified is greater than the number of entries in the
BootOrder, the entry is placed last.

2) In addition to modifying the BootOrder by passing an entire new
BootOrder as comma-delimted string to -o, two new formats are allowed:

   -o -5 will remove entry 5 (Boot0005) from the BootOrder string
   -o +5 will add entry 5 (Boot0005) to the BootOrder string.
         By default the entry will be added at the beginning of the
         BootOrder (in first place), but this behavior can be
         overridden by specifying an index with -I as above.
         If the specified entry already exists in the BootOrder,
         then it will be moved to the specified index.
@frozencemetery frozencemetery changed the title Feature Request: Insert Bootnum at a Specific Index in the Boot Order Insert Bootnum at a Specific Index in the Boot Order Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants