Add support for ESP partition flag (#2133)
This commit is contained in:
parent
5f5b95f245
commit
9f5c2bb70b
|
|
@ -658,7 +658,8 @@ class PartitionModification:
|
||||||
partuuid: Optional[str] = None
|
partuuid: Optional[str] = None
|
||||||
uuid: Optional[str] = None
|
uuid: Optional[str] = None
|
||||||
|
|
||||||
_boot_indicator_flags = [PartitionFlag.Boot, PartitionFlag.XBOOTLDR]
|
_efi_indicator_flags = (PartitionFlag.Boot, PartitionFlag.ESP)
|
||||||
|
_boot_indicator_flags = (PartitionFlag.Boot, PartitionFlag.XBOOTLDR)
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
# needed to use the object as a dictionary key due to hash func
|
# needed to use the object as a dictionary key due to hash func
|
||||||
|
|
@ -728,6 +729,13 @@ class PartitionModification:
|
||||||
|
|
||||||
raise ValueError('Mountpoint is not specified')
|
raise ValueError('Mountpoint is not specified')
|
||||||
|
|
||||||
|
def is_efi(self) -> bool:
|
||||||
|
return (
|
||||||
|
any(set(self.flags) & set(self._efi_indicator_flags))
|
||||||
|
and self.fs_type == FilesystemType.Fat32
|
||||||
|
and PartitionFlag.XBOOTLDR not in self.flags
|
||||||
|
)
|
||||||
|
|
||||||
def is_boot(self) -> bool:
|
def is_boot(self) -> bool:
|
||||||
"""
|
"""
|
||||||
Returns True if any of the boot indicator flags are found in self.flags
|
Returns True if any of the boot indicator flags are found in self.flags
|
||||||
|
|
@ -828,9 +836,8 @@ class DeviceModification:
|
||||||
def get_efi_partition(self) -> Optional[PartitionModification]:
|
def get_efi_partition(self) -> Optional[PartitionModification]:
|
||||||
"""
|
"""
|
||||||
Similar to get_boot_partition() but excludes XBOOTLDR partitions from it's candidates.
|
Similar to get_boot_partition() but excludes XBOOTLDR partitions from it's candidates.
|
||||||
Also works with ESP flag.
|
|
||||||
"""
|
"""
|
||||||
filtered = filter(lambda x: (x.is_boot() or PartitionFlag.ESP in x.flags) and x.fs_type == FilesystemType.Fat32 and PartitionFlag.XBOOTLDR not in x.flags, self.partitions)
|
filtered = filter(lambda x: x.is_efi() and x.mountpoint, self.partitions)
|
||||||
return next(filtered, None)
|
return next(filtered, None)
|
||||||
|
|
||||||
def get_boot_partition(self) -> Optional[PartitionModification]:
|
def get_boot_partition(self) -> Optional[PartitionModification]:
|
||||||
|
|
@ -843,10 +850,7 @@ class DeviceModification:
|
||||||
filtered = filter(lambda x: x.is_boot() and x != efi_partition and x.mountpoint, self.partitions)
|
filtered = filter(lambda x: x.is_boot() and x != efi_partition and x.mountpoint, self.partitions)
|
||||||
if boot_partition := next(filtered, None):
|
if boot_partition := next(filtered, None):
|
||||||
return boot_partition
|
return boot_partition
|
||||||
if efi_partition.is_boot():
|
return efi_partition
|
||||||
return efi_partition
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
else:
|
else:
|
||||||
filtered = filter(lambda x: x.is_boot() and x.mountpoint, self.partitions)
|
filtered = filter(lambda x: x.is_boot() and x.mountpoint, self.partitions)
|
||||||
return next(filtered, None)
|
return next(filtered, None)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from typing import Any, Dict, TYPE_CHECKING, List, Optional, Tuple
|
||||||
|
|
||||||
from .device_model import PartitionModification, FilesystemType, BDevice, Size, Unit, PartitionType, PartitionFlag, \
|
from .device_model import PartitionModification, FilesystemType, BDevice, Size, Unit, PartitionType, PartitionFlag, \
|
||||||
ModificationStatus, DeviceGeometry, SectorSize
|
ModificationStatus, DeviceGeometry, SectorSize
|
||||||
|
from ..hardware import SysInfo
|
||||||
from ..menu import Menu, ListManager, MenuSelection, TextInput
|
from ..menu import Menu, ListManager, MenuSelection, TextInput
|
||||||
from ..output import FormattedOutput, warn
|
from ..output import FormattedOutput, warn
|
||||||
from .subvolume_menu import SubvolumeMenu
|
from .subvolume_menu import SubvolumeMenu
|
||||||
|
|
@ -105,10 +106,14 @@ class PartitioningList(ListManager):
|
||||||
entry.mountpoint = self._prompt_mountpoint()
|
entry.mountpoint = self._prompt_mountpoint()
|
||||||
if entry.mountpoint == Path('/boot'):
|
if entry.mountpoint == Path('/boot'):
|
||||||
entry.set_flag(PartitionFlag.Boot)
|
entry.set_flag(PartitionFlag.Boot)
|
||||||
|
if SysInfo.has_uefi():
|
||||||
|
entry.set_flag(PartitionFlag.ESP)
|
||||||
case 'mark_formatting' if entry:
|
case 'mark_formatting' if entry:
|
||||||
self._prompt_formatting(entry)
|
self._prompt_formatting(entry)
|
||||||
case 'mark_bootable' if entry:
|
case 'mark_bootable' if entry:
|
||||||
entry.invert_flag(PartitionFlag.Boot)
|
entry.invert_flag(PartitionFlag.Boot)
|
||||||
|
if SysInfo.has_uefi():
|
||||||
|
entry.invert_flag(PartitionFlag.ESP)
|
||||||
case 'set_filesystem' if entry:
|
case 'set_filesystem' if entry:
|
||||||
fs_type = self._prompt_partition_fs_type()
|
fs_type = self._prompt_partition_fs_type()
|
||||||
if fs_type:
|
if fs_type:
|
||||||
|
|
@ -310,6 +315,8 @@ class PartitioningList(ListManager):
|
||||||
|
|
||||||
if partition.mountpoint == Path('/boot'):
|
if partition.mountpoint == Path('/boot'):
|
||||||
partition.set_flag(PartitionFlag.Boot)
|
partition.set_flag(PartitionFlag.Boot)
|
||||||
|
if SysInfo.has_uefi():
|
||||||
|
partition.set_flag(PartitionFlag.ESP)
|
||||||
|
|
||||||
return partition
|
return partition
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -903,15 +903,22 @@ class Installer:
|
||||||
'--debug'
|
'--debug'
|
||||||
]
|
]
|
||||||
|
|
||||||
if SysInfo.has_uefi() and efi_partition is not None:
|
if SysInfo.has_uefi():
|
||||||
|
if not efi_partition:
|
||||||
|
raise ValueError('Could not detect efi partition')
|
||||||
|
|
||||||
info(f"GRUB EFI partition: {efi_partition.dev_path}")
|
info(f"GRUB EFI partition: {efi_partition.dev_path}")
|
||||||
|
|
||||||
self.pacman.strap('efibootmgr') # TODO: Do we need? Yes, but remove from minimal_installation() instead?
|
self.pacman.strap('efibootmgr') # TODO: Do we need? Yes, but remove from minimal_installation() instead?
|
||||||
|
|
||||||
|
boot_dir_arg = []
|
||||||
|
if boot_partition != efi_partition:
|
||||||
|
boot_dir_arg.append(f'--boot-directory={boot_dir}')
|
||||||
|
|
||||||
add_options = [
|
add_options = [
|
||||||
'--target=x86_64-efi',
|
'--target=x86_64-efi',
|
||||||
f'--efi-directory={efi_partition.mountpoint}',
|
f'--efi-directory={efi_partition.mountpoint}',
|
||||||
f'--boot-directory={boot_dir}',
|
*boot_dir_arg,
|
||||||
'--bootloader-id=GRUB',
|
'--bootloader-id=GRUB',
|
||||||
'--removable'
|
'--removable'
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -170,9 +170,11 @@ def select_disk_config(
|
||||||
|
|
||||||
|
|
||||||
def _boot_partition(sector_size: disk.SectorSize) -> disk.PartitionModification:
|
def _boot_partition(sector_size: disk.SectorSize) -> disk.PartitionModification:
|
||||||
|
flags = [disk.PartitionFlag.Boot]
|
||||||
if SysInfo.has_uefi():
|
if SysInfo.has_uefi():
|
||||||
start = disk.Size(1, disk.Unit.MiB, sector_size)
|
start = disk.Size(1, disk.Unit.MiB, sector_size)
|
||||||
size = disk.Size(512, disk.Unit.MiB, sector_size)
|
size = disk.Size(512, disk.Unit.MiB, sector_size)
|
||||||
|
flags.append(disk.PartitionFlag.ESP)
|
||||||
else:
|
else:
|
||||||
start = disk.Size(3, disk.Unit.MiB, sector_size)
|
start = disk.Size(3, disk.Unit.MiB, sector_size)
|
||||||
size = disk.Size(203, disk.Unit.MiB, sector_size)
|
size = disk.Size(203, disk.Unit.MiB, sector_size)
|
||||||
|
|
@ -185,7 +187,7 @@ def _boot_partition(sector_size: disk.SectorSize) -> disk.PartitionModification:
|
||||||
length=size,
|
length=size,
|
||||||
mountpoint=Path('/boot'),
|
mountpoint=Path('/boot'),
|
||||||
fs_type=disk.FilesystemType.Fat32,
|
fs_type=disk.FilesystemType.Fat32,
|
||||||
flags=[disk.PartitionFlag.Boot]
|
flags=flags
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue