Added a small menu instead of a one-liner to select what to do with the disk if it has partitions.
This commit is contained in:
parent
bbf9face05
commit
8da8608e22
|
|
@ -87,6 +87,14 @@ def ask_to_configure_network():
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def ask_for_disk_layout():
|
||||||
|
options = {
|
||||||
|
'keep-existing' : 'Keep existing partition layout and select which ones to use where.',
|
||||||
|
'format-all' : 'Format entire drive and setup a basic partition scheme.'
|
||||||
|
}
|
||||||
|
|
||||||
|
return generic_select(options.values(), "Found partitions on the selected drive, (select by number) what do you want to do: ")
|
||||||
|
|
||||||
def generic_select(options, input_text="Select one of the above by index or absolute value: ", sort=True):
|
def generic_select(options, input_text="Select one of the above by index or absolute value: ", sort=True):
|
||||||
"""
|
"""
|
||||||
A generic select function that does not output anything
|
A generic select function that does not output anything
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,9 @@ else:
|
||||||
# 2. If so, ask if we should keep them or wipe everything
|
# 2. If so, ask if we should keep them or wipe everything
|
||||||
if archinstall.arguments['harddrive'].has_partitions():
|
if archinstall.arguments['harddrive'].has_partitions():
|
||||||
archinstall.log(f" ! {archinstall.arguments['harddrive']} contains existing partitions", fg='red')
|
archinstall.log(f" ! {archinstall.arguments['harddrive']} contains existing partitions", fg='red')
|
||||||
|
|
||||||
|
# We curate a list pf supported paritions
|
||||||
|
# and print those that we don't support.
|
||||||
partition_mountpoints = {}
|
partition_mountpoints = {}
|
||||||
for partition in archinstall.arguments['harddrive']:
|
for partition in archinstall.arguments['harddrive']:
|
||||||
try:
|
try:
|
||||||
|
|
@ -109,44 +112,56 @@ if archinstall.arguments['harddrive'].has_partitions():
|
||||||
partition_mountpoints[partition] = None
|
partition_mountpoints[partition] = None
|
||||||
except archinstall.UnknownFilesystemFormat as err:
|
except archinstall.UnknownFilesystemFormat as err:
|
||||||
archinstall.log(f" {partition} (Filesystem not supported)", fg='red')
|
archinstall.log(f" {partition} (Filesystem not supported)", fg='red')
|
||||||
#archinstall.log(f"Current filesystem is not supported: {err}", fg='red')
|
|
||||||
#input(f"Do you wish to erase all data? (y/n):")
|
|
||||||
|
|
||||||
if (option := input('Do you wish to keep one/more existing partitions or format entire drive? (k/f): ')).lower() in ('k', 'keep'):
|
# We then ask what to do with the paritions.
|
||||||
|
if (option := archinstall.ask_for_disk_layout()) == 'keep-existing':
|
||||||
archinstall.arguments['harddrive'].keep_partitions = True
|
archinstall.arguments['harddrive'].keep_partitions = True
|
||||||
|
|
||||||
archinstall.log(f" ** You will now select where (inside the installation) to mount partitions. **")
|
archinstall.log(f" ** You will now select which partitions to use by selecting mount points (inside the installation). **")
|
||||||
archinstall.log(f" ** The root would be a simple / and the boot partition /boot as it's relative paths. **")
|
archinstall.log(f" ** The root would be a simple / and the boot partition /boot (as all paths are relative inside the installation). **")
|
||||||
while True:
|
while True:
|
||||||
partition = archinstall.generic_select(partition_mountpoints.keys(), "Select a partition to assign mount-point to (leave blank when done): ")
|
# Select a partition
|
||||||
|
partition = archinstall.generic_select(partition_mountpoints.keys(),
|
||||||
|
"Select a partition by number that you want to set a mount-point for (leave blank when done): ")
|
||||||
if not partition:
|
if not partition:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# Select a mount-point
|
||||||
mountpoint = input(f"Enter a mount-point for {partition}: ").strip(' ')
|
mountpoint = input(f"Enter a mount-point for {partition}: ").strip(' ')
|
||||||
|
if len(mountpoint):
|
||||||
|
|
||||||
while 1:
|
# Get a valid & supported filesystem for the parition:
|
||||||
new_filesystem = input(f"Enter a valid filesystem for {partition} (leave blank for {partition.filesystem}): ").strip(' ')
|
while 1:
|
||||||
if len(new_filesystem) <= 0:
|
new_filesystem = input(f"Enter a valid filesystem for {partition} (leave blank for {partition.filesystem}): ").strip(' ')
|
||||||
|
if len(new_filesystem) <= 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
# Since the potentially new filesystem is new
|
||||||
|
# we have to check if we support it. We can do this by formatting /dev/null with the partitions filesystem.
|
||||||
|
# There's a nice wrapper for this on the partition object itself that supports a path-override during .format()
|
||||||
|
try:
|
||||||
|
partition.format(new_filesystem, path='/dev/null', log_formating=False, allow_formatting=True)
|
||||||
|
except archinstall.UnknownFilesystemFormat:
|
||||||
|
archinstall.log(f"Selected filesystem is not supported yet. If you want archinstall to support '{new_filesystem}', please create a issue-ticket suggesting it on github at https://github.com/Torxed/archinstall/issues.")
|
||||||
|
archinstall.log(f"Until then, please enter another supported filesystem.")
|
||||||
|
continue
|
||||||
|
except archinstall.SysCallError:
|
||||||
|
pass # Expected exception since mkfs.<format> can not format /dev/null.
|
||||||
|
# But that means our .format() function supported it.
|
||||||
break
|
break
|
||||||
|
|
||||||
try:
|
# When we've selected all three criterias,
|
||||||
partition.format(new_filesystem, path='/dev/null', log_formating=False, allow_formatting=True)
|
# We can safely mark the partition for formatting and where to mount it.
|
||||||
except archinstall.UnknownFilesystemFormat:
|
# TODO: allow_formatting might be redundant since target_mountpoint should only be
|
||||||
archinstall.log(f"Selected filesystem is not supported yet, if you wish archinstall should support '{new_filesystem}' please create a issue-ticket suggesting it on github at https://github.com/Torxed/archinstall/issues.")
|
# set if we actually want to format it anyway.
|
||||||
archinstall.log(f"Until then, please enter another supported filesystem.")
|
|
||||||
continue
|
|
||||||
except archinstall.SysCallError:
|
|
||||||
pass # Supported, but mkfs could not format /dev/null which is the whole point of /dev/null in path :)
|
|
||||||
break
|
|
||||||
|
|
||||||
if len(mountpoint):
|
|
||||||
partition.allow_formatting = True
|
partition.allow_formatting = True
|
||||||
partition.target_mountpoint = mountpoint
|
partition.target_mountpoint = mountpoint
|
||||||
|
# Only overwrite the filesystem definition if we selected one:
|
||||||
if len(new_filesystem):
|
if len(new_filesystem):
|
||||||
partition.filesystem = new_filesystem
|
partition.filesystem = new_filesystem
|
||||||
|
|
||||||
archinstall.log('Using existing partition table reported above.')
|
archinstall.log('Using existing partition table reported above.')
|
||||||
else:
|
elif option == 'format-all':
|
||||||
archinstall.arguments['harddrive'].keep_partitions = False
|
archinstall.arguments['harddrive'].keep_partitions = False
|
||||||
|
|
||||||
# Get disk encryption password (or skip if blank)
|
# Get disk encryption password (or skip if blank)
|
||||||
|
|
@ -217,7 +232,6 @@ archinstall.log(json.dumps(archinstall.arguments, indent=4, sort_keys=True, cls=
|
||||||
print()
|
print()
|
||||||
|
|
||||||
input('Press Enter to continue.')
|
input('Press Enter to continue.')
|
||||||
exit(0)
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Issue a final warning before we continue with something un-revertable.
|
Issue a final warning before we continue with something un-revertable.
|
||||||
|
|
@ -249,6 +263,7 @@ for i in range(5, 0, -1):
|
||||||
print()
|
print()
|
||||||
signal.signal(signal.SIGINT, original_sigint_handler)
|
signal.signal(signal.SIGINT, original_sigint_handler)
|
||||||
|
|
||||||
|
exit(0)
|
||||||
"""
|
"""
|
||||||
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()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue