Skip to main content

Python API to manage EFI Boot Entries

Project description

pyefiboot

Python Library to manage EFI Boot Entries

The aim of this library is to provide an API to the functionality of the efibootmgr (https://github.com/rhinstaller/efibootmgr) application. This provides a programmatic mechanism to read and update the EFI Boot Variables, allowing scripting of tasks to manage the EFI boot process.

[!NOTE] The initial release is a straightforward read-only solution, effectively mimicking the features of efibootmgr and efibootmgr -v calls.

Installation

When complete, should be:

pip install pyefiboot

Seek information elsewhere about installing in a virtual environment

This library currently has no dependencies

Usage

Most work can be done via the BootManager class which reads and provides access to all Boot related EFI variables

Reading current Boot Entries

import pyefiboot

bootmgr = pyefiboot.BootManager()

bootmgr.update_from_efi()

Printing to screen

To get output similar to efibootmgr:

bootmgr.display()

To get output similar to efibootmgr -v:

bootmgr.display(verbose=True)

Reading the BootCurrent, BootNext, BootTimeout and BootOrder EFI Variables

import pyefiboot

cur = pyefiboot.BootCurrent()

# Integer value of the current EFI Boot Entry
x: int = cur.value

# String representation of the current EFI Boot Entry, four character hex number
y: str = cur.hex_value

# BootNext and BootTimeout have similar functionality to BootCurrent

ord = pyefiboot.BootOrder()

# List of integers mapping the current programmed order of EFI Boot Entries
x: list[int] = ord.value

# String representation of the current EFI Boot Entry order, displayed as comma separated string of four character hex numbers
y: str = ord.hex_value

Creation of any of the above four classes will raise an exception if the nominated EFI variable does not exist

Reading an EFI Boot Entry variable

import pathlib
import pyefiboot

entry1 = pyefiboot.BootEntry(efivar_name='Boot0001')
entry2 = pyefiboot.BootEntry(efivar_fullpath=pathlib.Path('/sys/firmware/efi/efivars/Boot0002-8be4df61-93ca-11d2-aa0d-00e098032b8c'))

# Print string representation of boot entry to screen
print(entry1)

# Print verbose string representation of boot entry to screen
print(entry1.verbose_str())

# String representation of Boot Entry Index, four character hex number
x: str = entry2.entry_num

# If the Boot Entry refers to an actual local kernel to boot, returns the string representing the kernel file name, otherwise None
y: str | None = entry2.kernel_file

Access to other variables within the BootEntry will be in future versions

Public Class Properties and APIs

BootTimeout

Upon creation will read the current value of the UEFI Timeout variable. If the variable does not exist, it will be stored as None

Properties

Property Name Type Action Description
value int or None Read
  • Return timeout in seconds as an integer
  • Return None if variable does not exist
value int or None Write
  • Set the timeout to the provided value
  • Delete the UEFI Timeout variable if set to None
hex_value string Read Return the current UEFI Timeout variable as a four-digit hex string
__str__ Class can be converted to string representation in format "BootTimeout: x seconds"

BootCurrent

Upon creation will read the current value of the UEFI BootCurrent variable

Properties

Property Name Type Action Description
value int Read Only Return the current UEFI BootCurrent variable as an integer
hex_value string Read Return the current UEFI BootCurrent variable as a four-digit hex string
__str__ Class can be converted to string representation in format "BootCurrent: xxxx"

BootNext

Upon creation will read the current value of the UEFI BootNext variable. If the variable does not exist, it will be stored as None

Properties

Property Name Type Action Description
value int or None Read
  • Return the Boot Entry index to be used on next boot as an integer
  • Return None if variable does not exist
value int or None Write
  • Set the BootNext variable to the provided value
  • Delete the UEFI BootNext variable if set to None
hex_value string Read Return the current UEFI BootNext variable as a four-digit hex string
__str__ Class can be converted to string representation in format "BootNext: xxxx" or "BootNext "

BootOrder

Upon creation will read the current value of the UEFI BootOrder variable. If the variable does not exist, it will be stored as None

Properties

Property Name Type Action Description
value list[int] or None Read
  • Return list of Boot Entry indexes as integers
  • Return None if variable does not exist
value list[int] or list[str] or None Write
  • Set the Boot Order to the provided list of integers OR hex strings
  • Delete the UEFI BootOrder variable if set to None
hex_value string Read Return the current UEFI BootOrder as a comma separated list of hex boot entry values
__str__ Class can be converted to string representation in format "BootOrder: xxxx,yyyy,zzzz"

Logging

All modules within pyefiboot support Python logging, enabling logging and an appropriate log level in your application will allow these logs to be captured

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyefiboot-0.0.2.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyefiboot-0.0.2-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file pyefiboot-0.0.2.tar.gz.

File metadata

  • Download URL: pyefiboot-0.0.2.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pyefiboot-0.0.2.tar.gz
Algorithm Hash digest
SHA256 895325410c909d96517a67a3e4458a572a4e819713a2d712c58cde90831e9ae9
MD5 43e7033c453906764d7adc3a31c1f3e8
BLAKE2b-256 a0355bc108dc862e099f057d0650ed6e407674bcf0b18d3512017e0a467527e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyefiboot-0.0.2.tar.gz:

Publisher: python-publish.yml on jason-but/pyefiboot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyefiboot-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyefiboot-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pyefiboot-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 776d6ebdb67bab006321eb44c365a5fb6e2e1c87dfc3ae06dba0c206fcf6d9ea
MD5 9cf1d380c48076dddc49fb51da7dabcc
BLAKE2b-256 59a8ae40dafebff039b56b3f786ab0a286a5568390693a6f853bda81477aba7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyefiboot-0.0.2-py3-none-any.whl:

Publisher: python-publish.yml on jason-but/pyefiboot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page