Rework default partition table (#3197)
This commit is contained in:
parent
8b375c97a5
commit
4b07f8a3ae
|
|
@ -52,12 +52,17 @@ class DeviceHandler:
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._devices: dict[Path, BDevice] = {}
|
self._devices: dict[Path, BDevice] = {}
|
||||||
|
self._partition_table = PartitionTable.default()
|
||||||
self.load_devices()
|
self.load_devices()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def devices(self) -> list[BDevice]:
|
def devices(self) -> list[BDevice]:
|
||||||
return list(self._devices.values())
|
return list(self._devices.values())
|
||||||
|
|
||||||
|
@property
|
||||||
|
def partition_table(self) -> PartitionTable:
|
||||||
|
return self._partition_table
|
||||||
|
|
||||||
def load_devices(self) -> None:
|
def load_devices(self) -> None:
|
||||||
block_devices = {}
|
block_devices = {}
|
||||||
|
|
||||||
|
|
@ -86,7 +91,7 @@ class DeviceHandler:
|
||||||
if dev_lsblk_info.pttype:
|
if dev_lsblk_info.pttype:
|
||||||
disk = newDisk(device)
|
disk = newDisk(device)
|
||||||
else:
|
else:
|
||||||
disk = freshDisk(device, PartitionTable.GPT.value)
|
disk = freshDisk(device, self.partition_table.value)
|
||||||
except DiskException as err:
|
except DiskException as err:
|
||||||
debug(f'Unable to get disk from {device.path}: {err}')
|
debug(f'Unable to get disk from {device.path}: {err}')
|
||||||
continue
|
continue
|
||||||
|
|
@ -702,18 +707,15 @@ class DeviceHandler:
|
||||||
"""
|
"""
|
||||||
Create a partition table on the block device and create all partitions.
|
Create a partition table on the block device and create all partitions.
|
||||||
"""
|
"""
|
||||||
if modification.wipe:
|
partition_table = partition_table or self.partition_table
|
||||||
if partition_table is None:
|
|
||||||
raise ValueError('Modification is marked as wipe but no partitioning table was provided')
|
|
||||||
|
|
||||||
if partition_table.is_mbr() and len(modification.partitions) > 3:
|
|
||||||
raise DiskError('Too many partitions on disk, MBR disks can only have 3 primary partitions')
|
|
||||||
|
|
||||||
# WARNING: the entire device will be wiped and all data lost
|
# WARNING: the entire device will be wiped and all data lost
|
||||||
if modification.wipe:
|
if modification.wipe:
|
||||||
|
if partition_table.is_mbr() and len(modification.partitions) > 3:
|
||||||
|
raise DiskError('Too many partitions on disk, MBR disks can only have 3 primary partitions')
|
||||||
|
|
||||||
self.wipe_dev(modification.device)
|
self.wipe_dev(modification.device)
|
||||||
part_table = partition_table.value if partition_table else None
|
disk = freshDisk(modification.device.disk.device, partition_table.value)
|
||||||
disk = freshDisk(modification.device.disk.device, part_table)
|
|
||||||
else:
|
else:
|
||||||
info(f'Use existing device: {modification.device_path}')
|
info(f'Use existing device: {modification.device_path}')
|
||||||
disk = modification.device.disk
|
disk = modification.device.disk
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ from ..models.device_model import (
|
||||||
LvmVolume,
|
LvmVolume,
|
||||||
LvmVolumeGroup,
|
LvmVolumeGroup,
|
||||||
PartitionModification,
|
PartitionModification,
|
||||||
PartitionTable,
|
|
||||||
SectorSize,
|
SectorSize,
|
||||||
Size,
|
Size,
|
||||||
Unit,
|
Unit,
|
||||||
|
|
@ -61,14 +60,13 @@ class FilesystemHandler:
|
||||||
|
|
||||||
# Setup the blockdevice, filesystem (and optionally encryption).
|
# Setup the blockdevice, filesystem (and optionally encryption).
|
||||||
# Once that's done, we'll hand over to perform_installation()
|
# Once that's done, we'll hand over to perform_installation()
|
||||||
partition_table = PartitionTable.default()
|
|
||||||
|
|
||||||
# make sure all devices are unmounted
|
# make sure all devices are unmounted
|
||||||
for mod in device_mods:
|
for mod in device_mods:
|
||||||
device_handler.umount_all_existing(mod.device_path)
|
device_handler.umount_all_existing(mod.device_path)
|
||||||
|
|
||||||
for mod in device_mods:
|
for mod in device_mods:
|
||||||
device_handler.partition(mod, partition_table=partition_table)
|
device_handler.partition(mod)
|
||||||
|
|
||||||
device_handler.udev_sync()
|
device_handler.udev_sync()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ from archinstall.lib.models.device_model import (
|
||||||
from archinstall.lib.output import debug
|
from archinstall.lib.output import debug
|
||||||
from archinstall.tui import Alignment, FrameProperties, MenuItem, MenuItemGroup, Orientation, PreviewStyle, ResultType, SelectMenu
|
from archinstall.tui import Alignment, FrameProperties, MenuItem, MenuItemGroup, Orientation, PreviewStyle, ResultType, SelectMenu
|
||||||
|
|
||||||
from ..hardware import SysInfo
|
|
||||||
from ..output import FormattedOutput
|
from ..output import FormattedOutput
|
||||||
from ..utils.util import prompt_dir
|
from ..utils.util import prompt_dir
|
||||||
|
|
||||||
|
|
@ -354,7 +353,7 @@ def suggest_single_disk_layout(
|
||||||
|
|
||||||
device_modification = DeviceModification(device, wipe=True)
|
device_modification = DeviceModification(device, wipe=True)
|
||||||
|
|
||||||
using_gpt = SysInfo.has_uefi()
|
using_gpt = device_handler.partition_table.is_gpt()
|
||||||
|
|
||||||
if using_gpt:
|
if using_gpt:
|
||||||
available_space = available_space.gpt_end()
|
available_space = available_space.gpt_end()
|
||||||
|
|
@ -515,7 +514,7 @@ def suggest_multi_disk_layout(
|
||||||
root_device_sector_size = root_device_modification.device.device_info.sector_size
|
root_device_sector_size = root_device_modification.device.device_info.sector_size
|
||||||
home_device_sector_size = home_device_modification.device.device_info.sector_size
|
home_device_sector_size = home_device_modification.device.device_info.sector_size
|
||||||
|
|
||||||
using_gpt = SysInfo.has_uefi()
|
using_gpt = device_handler.partition_table.is_gpt()
|
||||||
|
|
||||||
# add boot partition to the root device
|
# add boot partition to the root device
|
||||||
boot_partition = _boot_partition(root_device_sector_size, using_gpt)
|
boot_partition = _boot_partition(root_device_sector_size, using_gpt)
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,6 @@ class DiskLayoutConfiguration:
|
||||||
device_modification.partitions = device_partitions
|
device_modification.partitions = device_partitions
|
||||||
device_modifications.append(device_modification)
|
device_modifications.append(device_modification)
|
||||||
|
|
||||||
using_gpt = SysInfo.has_uefi()
|
|
||||||
|
|
||||||
for dev_mod in device_modifications:
|
for dev_mod in device_modifications:
|
||||||
dev_mod.partitions.sort(key=lambda p: (not p.is_delete(), p.start))
|
dev_mod.partitions.sort(key=lambda p: (not p.is_delete(), p.start))
|
||||||
|
|
||||||
|
|
@ -186,8 +184,9 @@ class DiskLayoutConfiguration:
|
||||||
|
|
||||||
last = create_partitions[-1]
|
last = create_partitions[-1]
|
||||||
total_size = dev_mod.device.device_info.total_size
|
total_size = dev_mod.device.device_info.total_size
|
||||||
if using_gpt and last.end > total_size.gpt_end():
|
if dev_mod.using_gpt(device_handler.partition_table):
|
||||||
raise ValueError('Partition overlaps backup GPT header')
|
if last.end > total_size.gpt_end():
|
||||||
|
raise ValueError('Partition overlaps backup GPT header')
|
||||||
elif last.end > total_size.align():
|
elif last.end > total_size.align():
|
||||||
raise ValueError('Partition too large for device')
|
raise ValueError('Partition too large for device')
|
||||||
|
|
||||||
|
|
@ -202,6 +201,9 @@ class PartitionTable(Enum):
|
||||||
GPT = 'gpt'
|
GPT = 'gpt'
|
||||||
MBR = 'msdos'
|
MBR = 'msdos'
|
||||||
|
|
||||||
|
def is_gpt(self) -> bool:
|
||||||
|
return self == PartitionTable.GPT
|
||||||
|
|
||||||
def is_mbr(self) -> bool:
|
def is_mbr(self) -> bool:
|
||||||
return self == PartitionTable.MBR
|
return self == PartitionTable.MBR
|
||||||
|
|
||||||
|
|
@ -1359,6 +1361,12 @@ class DeviceModification:
|
||||||
def device_path(self) -> Path:
|
def device_path(self) -> Path:
|
||||||
return self.device.device_info.path
|
return self.device.device_info.path
|
||||||
|
|
||||||
|
def using_gpt(self, partition_table: PartitionTable) -> bool:
|
||||||
|
if self.wipe:
|
||||||
|
return partition_table.is_gpt()
|
||||||
|
|
||||||
|
return self.device.disk.type == PartitionTable.GPT.value
|
||||||
|
|
||||||
def add_partition(self, partition: PartitionModification) -> None:
|
def add_partition(self, partition: PartitionModification) -> None:
|
||||||
self.partitions.append(partition)
|
self.partitions.append(partition)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue