mirror of https://git.48k.eu/ogclient
utils: add enforce_gpt argument to get_efi_partition()
The Windows bootloader only supports a UEFI boot from a GPT partition. Set enforce_gpt to True in every codepath related to Windows. When enforce_gpt is set to True get_efi_partition() raises an exception when an MBR partition scheme is detected.master
parent
42791a1a7c
commit
97647c32aa
|
|
@ -57,7 +57,7 @@ def _boot_bios_windows(disk, part, mountpoint):
|
||||||
def _boot_uefi_windows(disk, part, mountpoint):
|
def _boot_uefi_windows(disk, part, mountpoint):
|
||||||
logging.info(f'Booting windows system')
|
logging.info(f'Booting windows system')
|
||||||
bootlabel = f'Part-{disk:02d}-{part:02d}'
|
bootlabel = f'Part-{disk:02d}-{part:02d}'
|
||||||
esp, esp_disk, esp_part_number = get_efi_partition(disk)
|
esp, esp_disk, esp_part_number = get_efi_partition(disk, enforce_gpt=True)
|
||||||
esp_mountpoint = esp.replace('dev', 'mnt')
|
esp_mountpoint = esp.replace('dev', 'mnt')
|
||||||
if not mount_mkdir(esp, esp_mountpoint):
|
if not mount_mkdir(esp, esp_mountpoint):
|
||||||
raise RuntimeError(f'Unable to mount detected EFI System Partition at {esp} into {esp_mountpoint}')
|
raise RuntimeError(f'Unable to mount detected EFI System Partition at {esp} into {esp_mountpoint}')
|
||||||
|
|
@ -82,7 +82,7 @@ def _boot_uefi_windows(disk, part, mountpoint):
|
||||||
def _boot_uefi_linux(disk, part, mountpoint):
|
def _boot_uefi_linux(disk, part, mountpoint):
|
||||||
logging.info(f'Booting Linux system')
|
logging.info(f'Booting Linux system')
|
||||||
bootlabel = f'Part-{disk:02d}-{part:02d}'
|
bootlabel = f'Part-{disk:02d}-{part:02d}'
|
||||||
esp, esp_disk, esp_part_number = get_efi_partition(disk)
|
esp, esp_disk, esp_part_number = get_efi_partition(disk, enforce_gpt=False)
|
||||||
esp_mountpoint = esp.replace('dev', 'mnt')
|
esp_mountpoint = esp.replace('dev', 'mnt')
|
||||||
if not mount_mkdir(esp, esp_mountpoint):
|
if not mount_mkdir(esp, esp_mountpoint):
|
||||||
raise RuntimeError(f'Unable to mount detected EFI System Partition at {esp} into {esp_mountpoint}')
|
raise RuntimeError(f'Unable to mount detected EFI System Partition at {esp} into {esp_mountpoint}')
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,12 @@ def get_partition_device(disknum, partnum):
|
||||||
raise ValueError(f'No such partition with disk index {disknum} and partition index {partnum}')
|
raise ValueError(f'No such partition with disk index {disknum} and partition index {partnum}')
|
||||||
|
|
||||||
|
|
||||||
def get_efi_partition(disknum):
|
def get_efi_partition(disknum, enforce_gpt):
|
||||||
"""
|
"""
|
||||||
Look for an EFI System Partition at the n-th disk. If disknum is invalid an exception is thrown
|
Look for an EFI System Partition at the n-th disk. If disknum is invalid an
|
||||||
|
exception is thrown.
|
||||||
|
If enforce_gpt is set to True the ESP will be ignored in a MBR partition
|
||||||
|
scheme.
|
||||||
|
|
||||||
Returns tuple with:
|
Returns tuple with:
|
||||||
- Device name containing the ESP
|
- Device name containing the ESP
|
||||||
|
|
@ -57,7 +60,7 @@ def get_efi_partition(disknum):
|
||||||
disk = get_disks()[disk_index]
|
disk = get_disks()[disk_index]
|
||||||
cxt = fdisk.Context(f'/dev/{disk}')
|
cxt = fdisk.Context(f'/dev/{disk}')
|
||||||
|
|
||||||
if cxt.label == fdisk.FDISK_DISKLABEL_DOS:
|
if enforce_gpt and cxt.label == fdisk.FDISK_DISKLABEL_DOS:
|
||||||
raise RuntimeError(f'Disk has DOS partition scheme, cannot find ESP at /dev/{disk}')
|
raise RuntimeError(f'Disk has DOS partition scheme, cannot find ESP at /dev/{disk}')
|
||||||
|
|
||||||
for pa in cxt.partitions:
|
for pa in cxt.partitions:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue