Skip to content

Commit

Permalink
update root partition size for multidisk layout
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-ferrier committed Mar 30, 2024
1 parent a477990 commit 674667e
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions archinstall/lib/interactions/disk_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pathlib import Path
from typing import Any, TYPE_CHECKING
from typing import Optional, List, Tuple
from typing import Optional, List

from .. import disk
from ..disk.device_model import BtrfsMountOption
Expand Down Expand Up @@ -372,7 +372,7 @@ def suggest_multi_disk_layout(
# https://www.reddit.com/r/btrfs/comments/9us4hr/what_is_your_btrfs_partitionsubvolumes_scheme/
min_home_partition_size = disk.Size(40, disk.Unit.GiB, disk.SectorSize.default())
# rough estimate taking in to account user desktops etc. TODO: Catch user packages to detect size?
desired_root_partition_size = disk.Size(20, disk.Unit.GiB, disk.SectorSize.default())
min_root_partition_size = disk.Size(20, disk.Unit.GiB, disk.SectorSize.default())
mount_options = []

if not filesystem_type:
Expand All @@ -382,20 +382,25 @@ def suggest_multi_disk_layout(
possible_devices = list(filter(lambda x: x.device_info.total_size >= min_home_partition_size, devices))
home_device = max(possible_devices, key=lambda d: d.device_info.total_size) if possible_devices else None

# find proper device for /root
devices_delta = {}
for device in devices:
if device is not home_device:
delta = device.device_info.total_size - desired_root_partition_size
devices_delta[device] = delta

sorted_delta: List[Tuple[disk.BDevice, Any]] = sorted(devices_delta.items(), key=lambda x: x[1])
root_device: Optional[disk.BDevice] = sorted_delta[0][0]
# find proper device for /root (size >= min_root_size and not home)
root_possible_devices: list[disk.BDevice] = [
device
for device in devices
if device.device_info.total_size >= min_root_partition_size
and device is not home_device
]

# we take the smallest disk >= min_root_size
root_device: Optional[disk.BDevice] = (
min(root_possible_devices, key=lambda d: d.device_info.total_size)
if possible_devices
else None
)

if home_device is None or root_device is None:
text = _('The selected drives do not have the minimum capacity required for an automatic suggestion\n')
text += _('Minimum capacity for /home partition: {}GiB\n').format(min_home_partition_size.format_size(disk.Unit.GiB))
text += _('Minimum capacity for Arch Linux partition: {}GiB').format(desired_root_partition_size.format_size(disk.Unit.GiB))
text += _('Minimum capacity for Arch Linux partition: {}GiB').format(min_root_partition_size.format_size(disk.Unit.GiB))
Menu(str(text), [str(_('Continue'))], skip=False).run()
return []

Expand Down Expand Up @@ -423,8 +428,12 @@ def suggest_multi_disk_layout(
boot_partition = _boot_partition(root_device_sector_size, using_gpt)
root_device_modification.add_partition(boot_partition)

# add root partition to the root device
root_start = boot_partition.start + boot_partition.length
root_length = root_device.device_info.total_size - root_start
available_space = root_device.device_info.total_size - root_start
root_length = process_root_partition_size(
available_space=available_space, sector_size=root_device.device_info.sector_size
)

if using_gpt:
root_length -= root_align_buffer
Expand Down

0 comments on commit 674667e

Please sign in to comment.