Added a soft-wrapper around parted logic. This logic will guide users through setting up partitions, if they chose to wipe a drive. We'll avoid doing to much auto-magic, and this is just a start.

This commit is contained in:
Anton Hvornum 2021-05-10 10:14:33 +02:00
parent d6f63375c6
commit 3e601ff9ab
2 changed files with 82 additions and 6 deletions

View File

@ -444,6 +444,7 @@ def generic_select(options, input_text="Select one of the above by index or abso
# Therefore, now we can only provide the dictionary itself
if type(options) == dict: options = list(options.values())
if sort: options = sorted(options) # As we pass only list and dict (converted to list), we can skip converting to list
options = [x for x in options if x] # Clean it up from empty options
if len(options) == 0:
log(f" * Generic select didn't find any options to choose from * ", fg='red')
log(" * If problem persists, please create an issue on https://github.com/archlinux/archinstall/issues * ", fg='yellow')
@ -515,6 +516,77 @@ def select_partition_layout(block_device):
}
}
def valid_fs_type(fstype :str) -> bool:
# https://www.gnu.org/software/parted/manual/html_node/mkpart.html
return fstype in [
"ext2",
"fat16", "fat32",
"hfs", "hfs+", "hfsx",
"linux-swap",
"NTFS",
"reiserfs",
"ufs",
"btrfs",
]
def valid_parted_position(pos :str):
return len(pos) and (start.isdigit() or (start[-1] == '%' and start[:-1].isdigit()))
def partition_overlap(partitions :list, start :str, end :str) -> bool:
# TODO: Implement sanity check
return False
def wipe_and_create_partitions(block_device):
if hasUEFI():
partition_type = 'gpt'
else:
partition_type = 'msdos'
partitions_result = []
while True:
modes = [
"Create new partition",
"Delete partition" if len(block_device) else "",
"Assign mount-point for partition" if len(block_device) else "",
"Mark a partition as encrypted" if len(block_device) else "",
"Mark a partition as bootable (automatic for /boot)" if len(block_device) else ""
]
task = generic_select(modes,
input_text=f"Select what to do with {block_device}: ")
if task == 'Create new partition':
if partition_type == 'gpt':
# https://www.gnu.org/software/parted/manual/html_node/mkpart.html
# https://www.gnu.org/software/parted/manual/html_node/mklabel.html
name = input("Enter a desired name for the partition: ").strip()
fstype = input("Enter a desired filesystem type for the partition: ").strip()
start = input("Enter the start sector of the partition (percentage or block number, ex: 0%): ").strip()
end = input("Enter the end sector of the partition (percentage or block number, ex: 100%): ").strip()
if valid_parted_position(start) and valid_parted_position(end) and valid_fs_type(fstype):
if partition_overlap(partitions_result, start, end):
log(f"This partition overlaps with other partitions on the drive! Ignoring this partition creation.", fg="red")
continue
partitions_result.append({
"type" : "primary", # Strictly only allowed under MSDOS, but GPT accepts it so it's "safe" to inject
"start" : start,
"size" : end,
"filesystem" : {
"format" : fstype
}
})
else:
log(f"Invalid start, end or fstype for this partition. Ignoring this partition creation.", fg="red")
continue
elif task == "Delete partition":
elif task == "Assign mount-point for partition":
elif task == "Mark a partition as encrypted":
elif task == "Mark a partition as bootable (automatic for /boot)":
def select_individual_blockdevice_usage(block_devices :list):
result = {}
@ -526,11 +598,13 @@ def select_individual_blockdevice_usage(block_devices :list):
]
device_mode = generic_select(modes)
if device_mode == "Re-use partitions":
layout = select_partition_layout(device)
result[device.path] = layout
else:
...
layout = wipe_and_create_partitions(device)
result[device.path] = layout
def select_disk_layout(block_devices :list):

View File

@ -44,6 +44,12 @@ def ask_user_questions():
archinstall.arguments['mirror-region'] = {selected_region : archinstall.list_mirrors()[selected_region]}
# Ask which boot-loader to use (will only ask if we're in BIOS (non-efi) mode)
# We do this before the disk selection process because there are some soft dependencies
# in retards to which boot loader/mode we're in.
archinstall.arguments["bootloader"] = archinstall.ask_for_bootloader()
# Ask which harddrives/block-devices we will install to
# and convert them into archinstall.BlockDevice() objects.
if archinstall.arguments.get('harddrives', None):
@ -65,10 +71,6 @@ def ask_user_questions():
archinstall.arguments['!encryption-password'] = passwd
# Ask which boot-loader to use (will only ask if we're in BIOS (non-efi) mode)
archinstall.arguments["bootloader"] = archinstall.ask_for_bootloader()
# Get the hostname for the machine
if not archinstall.arguments.get('hostname', None):
archinstall.arguments['hostname'] = input('Desired hostname for the installation: ').strip(' ')