Skip to main content

Library for reading and managing UEFI boot entries on Linux systems.

Project description

efiboot

A Python library for reading and managing UEFI boot entries on Linux systems.

Reads EFI variables directly from /sys/firmware/efi/efivars/, exposing the full raw data while keeping common use cases simple. Uses efibootmgr only for write operations.

Note: Most operations require root privileges.

Reading Boot Entries

List all boot entries with details

file_paths = efiboot.get_boot_entry_file_paths()

for path in file_paths:
    entry = efiboot.BootEntry(path)
    print(entry.index, entry.description, "active:", entry.is_active)
    # entry.description is also known as label or name

Get a specific entry by index

path = efiboot.get_boot_entry_file_path_from_index("0001")
entry = efiboot.BootEntry(path)
print(entry.description)

BootEntry attributes

Attribute Type Description
index str 4-character hex index (e.g. 0001)
description str Human-readable label
is_active bool Whether the entry is enabled
is_hidden bool Whether the entry is hidden
is_force_reconnect bool Whether reconnect is forced on boot
loader_location list[LoaderLocationNode] Raw EFI device path nodes
loader_parameters bytes Raw loader arguments

Other EFI variables

print(efiboot.get_boot_order())         # e.g. ['0001', '0002', '0003']
print(efiboot.get_current_boot_index()) # e.g. '0001'
print(efiboot.get_next_boot_index())    # e.g. '0002'
print(efiboot.get_boot_timeout())       # seconds, e.g. 5

TailFileGptDrivePart

This is the class for inspecting boot entries that point to a file (e.g. a kernel image or .efi file) on a GPT-partitioned drive — the most common use case for efiboot.

Given a BootEntry, pass its loader_location to TailFileGptDrivePart. It will raise ValueError if the entry doesn't match this structure (e.g. network boot, non-GPT disk), so wrap it in a try/except.

file_paths = efiboot.get_boot_entry_file_paths()

for path in file_paths:
    entry = efiboot.BootEntry(path)
    try:
        loader = efiboot.TailFileGptDrivePart(entry.loader_location)
        print(f"[{entry.index}] {entry.description}")
        print(f"  Loader path : {loader.loader_path}")
        print(f"  Partition   : {loader.partition_number}")
        print(f"  PARTUUID    : {loader.partuuid}")
    except ValueError:
        pass  # Entry uses a different boot mechanism, skip it

Available attributes

Attribute Type Description
loader_path str Path to the loader file on the partition (e.g. \vmlinuz-linux)
partuuid str UUID of the GPT partition
partition_number int Partition number on the disk
partition_start int Partition start offset in sectors
partition_size int Partition size in sectors
partition_signature bytes Raw 16-byte partition GUID

Managing Boot Entries

Create a boot entry

Use create_boot_entry_unicode for standard Linux kernel entries (loader parameters as a string):

efiboot.create_boot_entry_unicode(
    partition_path="/dev/sda1",
    description="Arch Linux",
    loader_path="\\vmlinuz-linux",
    loader_parameters="rw root=PARTUUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx initrd=\\initramfs-linux.img",
)

Use create_boot_entry when you need raw binary loader parameters:

efiboot.create_boot_entry(
    partition_path="/dev/sda1",
    description="My OS",
    loader_path="\\EFI\\myos\\bootx64.efi",
    loader_parameters=bin,
)

Both functions will raise FileNotFoundError if the loader file doesn't exist on the partition.

Note: loader_path accepts both / and \ path separators. Any paths embedded in loader_parameters must use \ separators.

Delete a boot entry

efiboot.delete_boot_entry("0003")

Set boot order

efiboot.set_boot_order(["0001", "0003", "0002"])

Activate or deactivate an entry

efiboot.set_boot_entry_active("0001", state=True)   # activate
efiboot.set_boot_entry_active("0001", state=False)  # deactivate

One-time next boot

efiboot.set_next_boot("0002")   # boot this entry once on next restart
efiboot.delete_next_boot()      # cancel the one-time override

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

efiboot-0.0.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

efiboot-0.0.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file efiboot-0.0.1.tar.gz.

File metadata

  • Download URL: efiboot-0.0.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for efiboot-0.0.1.tar.gz
Algorithm Hash digest
SHA256 99afc7465f58c00a050965510b8207317304eb2b37d81623ff04e591718ac135
MD5 2ac647732a856aa8a0b7502224f05dfb
BLAKE2b-256 29de4f34a581ef6ea3e91f8dfef4416b9eb19cd05050c3d79b458ddb39639b75

See more details on using hashes here.

File details

Details for the file efiboot-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: efiboot-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for efiboot-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6743e99d34e90a674eca9aa3d8bfe8f6a51cdc2406b84888d033dd00b45f4e9c
MD5 a57592c64683378457316ad633b27efd
BLAKE2b-256 e13feec071dd34a4e5717ffde068e023ab32e4afb9c5a36a79c5f89885f5dffd

See more details on using hashes here.

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