Skip to content

Commit 4b07f8a

Browse files
authored
Rework default partition table (archlinux#3197)
1 parent 8b375c9 commit 4b07f8a

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

archinstall/lib/disk/device_handler.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,17 @@ class DeviceHandler:
5252

5353
def __init__(self) -> None:
5454
self._devices: dict[Path, BDevice] = {}
55+
self._partition_table = PartitionTable.default()
5556
self.load_devices()
5657

5758
@property
5859
def devices(self) -> list[BDevice]:
5960
return list(self._devices.values())
6061

62+
@property
63+
def partition_table(self) -> PartitionTable:
64+
return self._partition_table
65+
6166
def load_devices(self) -> None:
6267
block_devices = {}
6368

@@ -86,7 +91,7 @@ def load_devices(self) -> None:
8691
if dev_lsblk_info.pttype:
8792
disk = newDisk(device)
8893
else:
89-
disk = freshDisk(device, PartitionTable.GPT.value)
94+
disk = freshDisk(device, self.partition_table.value)
9095
except DiskException as err:
9196
debug(f'Unable to get disk from {device.path}: {err}')
9297
continue
@@ -702,18 +707,15 @@ def partition(
702707
"""
703708
Create a partition table on the block device and create all partitions.
704709
"""
705-
if modification.wipe:
706-
if partition_table is None:
707-
raise ValueError('Modification is marked as wipe but no partitioning table was provided')
710+
partition_table = partition_table or self.partition_table
708711

712+
# WARNING: the entire device will be wiped and all data lost
713+
if modification.wipe:
709714
if partition_table.is_mbr() and len(modification.partitions) > 3:
710715
raise DiskError('Too many partitions on disk, MBR disks can only have 3 primary partitions')
711716

712-
# WARNING: the entire device will be wiped and all data lost
713-
if modification.wipe:
714717
self.wipe_dev(modification.device)
715-
part_table = partition_table.value if partition_table else None
716-
disk = freshDisk(modification.device.disk.device, part_table)
718+
disk = freshDisk(modification.device.disk.device, partition_table.value)
717719
else:
718720
info(f'Use existing device: {modification.device_path}')
719721
disk = modification.device.disk

archinstall/lib/disk/filesystem.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
LvmVolume,
1919
LvmVolumeGroup,
2020
PartitionModification,
21-
PartitionTable,
2221
SectorSize,
2322
Size,
2423
Unit,
@@ -61,14 +60,13 @@ def perform_filesystem_operations(self, show_countdown: bool = True) -> None:
6160

6261
# Setup the blockdevice, filesystem (and optionally encryption).
6362
# Once that's done, we'll hand over to perform_installation()
64-
partition_table = PartitionTable.default()
6563

6664
# make sure all devices are unmounted
6765
for mod in device_mods:
6866
device_handler.umount_all_existing(mod.device_path)
6967

7068
for mod in device_mods:
71-
device_handler.partition(mod, partition_table=partition_table)
69+
device_handler.partition(mod)
7270

7371
device_handler.udev_sync()
7472

archinstall/lib/interactions/disk_conf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from archinstall.lib.output import debug
3131
from archinstall.tui import Alignment, FrameProperties, MenuItem, MenuItemGroup, Orientation, PreviewStyle, ResultType, SelectMenu
3232

33-
from ..hardware import SysInfo
3433
from ..output import FormattedOutput
3534
from ..utils.util import prompt_dir
3635

@@ -354,7 +353,7 @@ def suggest_single_disk_layout(
354353

355354
device_modification = DeviceModification(device, wipe=True)
356355

357-
using_gpt = SysInfo.has_uefi()
356+
using_gpt = device_handler.partition_table.is_gpt()
358357

359358
if using_gpt:
360359
available_space = available_space.gpt_end()
@@ -515,7 +514,7 @@ def suggest_multi_disk_layout(
515514
root_device_sector_size = root_device_modification.device.device_info.sector_size
516515
home_device_sector_size = home_device_modification.device.device_info.sector_size
517516

518-
using_gpt = SysInfo.has_uefi()
517+
using_gpt = device_handler.partition_table.is_gpt()
519518

520519
# add boot partition to the root device
521520
boot_partition = _boot_partition(root_device_sector_size, using_gpt)

archinstall/lib/models/device_model.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ def parse_arg(cls, disk_config: _DiskLayoutConfigurationSerialization) -> DiskLa
144144
device_modification.partitions = device_partitions
145145
device_modifications.append(device_modification)
146146

147-
using_gpt = SysInfo.has_uefi()
148-
149147
for dev_mod in device_modifications:
150148
dev_mod.partitions.sort(key=lambda p: (not p.is_delete(), p.start))
151149

@@ -186,8 +184,9 @@ def parse_arg(cls, disk_config: _DiskLayoutConfigurationSerialization) -> DiskLa
186184

187185
last = create_partitions[-1]
188186
total_size = dev_mod.device.device_info.total_size
189-
if using_gpt and last.end > total_size.gpt_end():
190-
raise ValueError('Partition overlaps backup GPT header')
187+
if dev_mod.using_gpt(device_handler.partition_table):
188+
if last.end > total_size.gpt_end():
189+
raise ValueError('Partition overlaps backup GPT header')
191190
elif last.end > total_size.align():
192191
raise ValueError('Partition too large for device')
193192

@@ -202,6 +201,9 @@ class PartitionTable(Enum):
202201
GPT = 'gpt'
203202
MBR = 'msdos'
204203

204+
def is_gpt(self) -> bool:
205+
return self == PartitionTable.GPT
206+
205207
def is_mbr(self) -> bool:
206208
return self == PartitionTable.MBR
207209

@@ -1359,6 +1361,12 @@ class DeviceModification:
13591361
def device_path(self) -> Path:
13601362
return self.device.device_info.path
13611363

1364+
def using_gpt(self, partition_table: PartitionTable) -> bool:
1365+
if self.wipe:
1366+
return partition_table.is_gpt()
1367+
1368+
return self.device.disk.type == PartitionTable.GPT.value
1369+
13621370
def add_partition(self, partition: PartitionModification) -> None:
13631371
self.partitions.append(partition)
13641372

0 commit comments

Comments
 (0)