Started working on partitioning logic from declarative layouts.

This commit is contained in:
Anton Hvornum 2021-06-10 13:39:50 +02:00
parent 5701ef9539
commit e8d38ea1a7
3 changed files with 20 additions and 10 deletions

View File

@ -572,7 +572,14 @@ class Filesystem:
def load_layout(self, layout :dict):
for partition in layout:
print(partition)
# We don't want to re-add an existing partition (those containing a UUID already)
if 'UUID' not in partition:
self.add_partition(partition.get('type', 'primary'),
start=partition.get('start', '1MiB'), # TODO: Revisit sane block starts (4MB for memorycards for instance)
end=partition.get('size', '100%'),
partition_format=partition.get('filesystem', {}).get('format', 'btrfs'))
exit(0)

View File

@ -11,6 +11,7 @@ import termios
import time
import tty
from .disk import BlockDevice
from .exceptions import *
from .general import SysCommand
from .hardware import AVAILABLE_GFX_DRIVERS, has_uefi
@ -19,7 +20,6 @@ from .networking import list_interfaces
from .output import log
from .profiles import Profile, list_profiles
# TODO: Some inconsistencies between the selection processes.
# Some return the keys from the options, some the values?
@ -553,7 +553,7 @@ def generic_select(options, input_text="Select one of the above by index or abso
def select_partition_layout(block_device):
return {
"/dev/sda": { # Block Device level
BlockDevice("/dev/sda"): { # Block Device level
"wipe": False, # Safety flags
"partitions" : [ # Affected / New partitions
{
@ -565,7 +565,7 @@ def select_partition_layout(block_device):
}
]
},
"/dev/sdb" : {
BlockDevice("/dev/sdb") : {
"wipe" : True,
"partitions" : [
{
@ -653,7 +653,7 @@ def get_default_partition_layout(block_devices):
}
# TODO: Implement sane generic layout for 2+ drives
def wipe_and_create_partitions(block_device):
def wipe_and_create_partitions(block_device :BlockDevice) -> dict:
if hasUEFI():
partition_type = 'gpt'
else:
@ -747,7 +747,9 @@ def wipe_and_create_partitions(block_device):
partitions_result = [*suggested_layout]
elif task is None:
return partitions_result
return {
block_device : partitions_result
}
else:
for index, partition in enumerate(partitions_result):
print(f"{index}: Start: {partition['start']}, End: {partition['size']} ({partition['filesystem']['format']}{', mounting at: '+partition['mountpoint'] if partition['mountpoint'] else ''})")
@ -777,7 +779,9 @@ def wipe_and_create_partitions(block_device):
if (partition := generic_select(partitions_result, 'Select which partition to mark as bootable: ', options_output=False)):
partitions_result[partitions_result.index(partition)]['boot'] = not partitions_result[partitions_result.index(partition)].get('boot', False)
return partitions_result
return {
block_device : partitions_result
}
def select_individual_blockdevice_usage(block_devices :list):
result = {}

View File

@ -73,7 +73,7 @@ def ask_user_questions():
# Ask which harddrives/block-devices we will install to
# and convert them into archinstall.BlockDevice() objects.
if archinstall.arguments.get('harddrives', None):
archinstall.arguments['harddrives'] = [archinstall.BlockDevice(BlockDev) for BlockDev in archinstall.arguments['harddrives']]
archinstall.arguments['harddrives'] = [archinstall.BlockDevice(BlockDev) for BlockDev in archinstall.arguments['harddrives'].split(',')]
else:
archinstall.arguments['harddrives'] = archinstall.generic_multi_select(archinstall.all_disks(),
text="Select one or more harddrives to use and configure (leave blank to skip this step): ",
@ -82,7 +82,6 @@ def ask_user_questions():
if archinstall.arguments.get('harddrives', None):
archinstall.storage['disk_layouts'] = archinstall.select_disk_layout(archinstall.arguments['harddrives'])
# Get disk encryption password (or skip if blank)
if archinstall.arguments['harddrives'] and archinstall.arguments.get('!encryption-password', None) is None:
if (passwd := archinstall.get_password(prompt='Enter disk encryption password (leave blank for no encryption): ')):
@ -219,7 +218,7 @@ def perform_filesystem_operations():
for drive in archinstall.arguments['harddrives']:
with archinstall.Filesystem(drive, mode) as fs:
fs.load_layout(archinstall.arguments['harddrives'][drive])
fs.load_layout(archinstall.storage['disk_layouts'][drive])
perform_installation(archinstall.storage.get('MOUNT_POINT', '/mnt'))