Added a 'use /mnt' option to the formatted #124. This has not yet been tested, but the logic should work according to the new API layout for Installation().

This commit is contained in:
Anton Hvornum 2021-04-09 15:27:22 +02:00
parent 740eccb213
commit f298b9e393
No known key found for this signature in database
GPG Key ID: F1234C5BA67C59DF
2 changed files with 54 additions and 48 deletions

View File

@ -179,6 +179,7 @@ def ask_to_configure_network():
def ask_for_disk_layout(): def ask_for_disk_layout():
options = { options = {
'keep-existing' : 'Keep existing partition layout and select which ones to use where.', 'keep-existing' : 'Keep existing partition layout and select which ones to use where.',
'use-mnt' : 'Use whatever is mounted under /mnt and don\'t format anything',
'format-all' : 'Format entire drive and setup a basic partition scheme.', 'format-all' : 'Format entire drive and setup a basic partition scheme.',
'abort' : 'Abort the installation.' 'abort' : 'Abort the installation.'
} }

View File

@ -53,6 +53,9 @@ def ask_user_questions():
if (option := archinstall.ask_for_disk_layout()) == 'abort': if (option := archinstall.ask_for_disk_layout()) == 'abort':
archinstall.log(f"Safely aborting the installation. No changes to the disk or system has been made.") archinstall.log(f"Safely aborting the installation. No changes to the disk or system has been made.")
exit(1) exit(1)
elif option == 'use-mnt':
archinstall.arguments['harddrive'] = None
archinstall.arguments['target-mount'] = '/mnt'
elif option == 'keep-existing': elif option == 'keep-existing':
archinstall.arguments['harddrive'].keep_partitions = True archinstall.arguments['harddrive'].keep_partitions = True
@ -197,62 +200,63 @@ def perform_installation_steps():
We mention the drive one last time, and count from 5 to 0. We mention the drive one last time, and count from 5 to 0.
""" """
print(f" ! Formatting {archinstall.arguments['harddrive']} in ", end='') if archinstall.arguments.get('harddrive', None):
archinstall.do_countdown() print(f" ! Formatting {archinstall.arguments['harddrive']} in ", end='')
archinstall.do_countdown()
""" """
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()
""" """
with archinstall.Filesystem(archinstall.arguments['harddrive'], archinstall.GPT) as fs: with archinstall.Filesystem(archinstall.arguments['harddrive'], archinstall.GPT) as fs:
# Wipe the entire drive if the disk flag `keep_partitions`is False. # Wipe the entire drive if the disk flag `keep_partitions`is False.
if archinstall.arguments['harddrive'].keep_partitions is False: if archinstall.arguments['harddrive'].keep_partitions is False:
fs.use_entire_disk(root_filesystem_type=archinstall.arguments.get('filesystem', 'btrfs')) fs.use_entire_disk(root_filesystem_type=archinstall.arguments.get('filesystem', 'btrfs'))
# Check if encryption is desired and mark the root partition as encrypted. # Check if encryption is desired and mark the root partition as encrypted.
if archinstall.arguments.get('!encryption-password', None): if archinstall.arguments.get('!encryption-password', None):
root_partition = fs.find_partition('/') root_partition = fs.find_partition('/')
root_partition.encrypted = True root_partition.encrypted = True
# After the disk is ready, iterate the partitions and check # After the disk is ready, iterate the partitions and check
# which ones are safe to format, and format those. # which ones are safe to format, and format those.
for partition in archinstall.arguments['harddrive']: for partition in archinstall.arguments['harddrive']:
if partition.safe_to_format(): if partition.safe_to_format():
# Partition might be marked as encrypted due to the filesystem type crypt_LUKS # Partition might be marked as encrypted due to the filesystem type crypt_LUKS
# But we might have omitted the encryption password question to skip encryption. # But we might have omitted the encryption password question to skip encryption.
# In which case partition.encrypted will be true, but passwd will be false. # In which case partition.encrypted will be true, but passwd will be false.
if partition.encrypted and (passwd := archinstall.arguments.get('!encryption-password', None)): if partition.encrypted and (passwd := archinstall.arguments.get('!encryption-password', None)):
partition.encrypt(password=passwd) partition.encrypt(password=passwd)
else:
partition.format()
else: else:
partition.format() archinstall.log(f"Did not format {partition} because .safe_to_format() returned False or .allow_formatting was False.", level=archinstall.LOG_LEVELS.Debug)
fs.find_partition('/boot').format('vfat')
if archinstall.arguments.get('!encryption-password', None):
# First encrypt and unlock, then format the desired partition inside the encrypted part.
# archinstall.luks2() encrypts the partition when entering the with context manager, and
# unlocks the drive so that it can be used as a normal block-device within archinstall.
with archinstall.luks2(fs.find_partition('/'), 'luksloop', archinstall.arguments.get('!encryption-password', None)) as unlocked_device:
unlocked_device.format(fs.find_partition('/').filesystem)
unlocked_device.mount('/mnt')
else: else:
archinstall.log(f"Did not format {partition} because .safe_to_format() returned False or .allow_formatting was False.", level=archinstall.LOG_LEVELS.Debug) fs.find_partition('/').format(fs.find_partition('/').filesystem)
fs.find_partition('/').mount('/mnt')
if archinstall.arguments.get('!encryption-password', None): fs.find_partition('/boot').mount('/mnt/boot')
# First encrypt and unlock, then format the desired partition inside the encrypted part.
# archinstall.luks2() encrypts the partition when entering the with context manager, and perform_installation('/mnt')
# unlocks the drive so that it can be used as a normal block-device within archinstall.
with archinstall.luks2(fs.find_partition('/'), 'luksloop', archinstall.arguments.get('!encryption-password', None)) as unlocked_device:
unlocked_device.format(fs.find_partition('/').filesystem)
perform_installation(device=unlocked_device,
boot_partition=fs.find_partition('/boot'),
language=archinstall.arguments['keyboard-language'],
mirrors=archinstall.arguments['mirror-region'])
else:
perform_installation(device=fs.find_partition('/'),
boot_partition=fs.find_partition('/boot'),
language=archinstall.arguments['keyboard-language'],
mirrors=archinstall.arguments['mirror-region'])
def perform_installation(device, boot_partition, language, mirrors): def perform_installation(mountpoint):
""" """
Performs the installation steps on a block device. Performs the installation steps on a block device.
Only requirement is that the block devices are Only requirement is that the block devices are
formatted and setup prior to entering this function. formatted and setup prior to entering this function.
""" """
with archinstall.Installer(device, boot_partition=boot_partition, hostname=archinstall.arguments.get('hostname', 'Archinstall')) as installation: with archinstall.Installer(mountpoint) as installation:
## if len(mirrors): ## if len(mirrors):
# Certain services might be running that affects the system during installation. # Certain services might be running that affects the system during installation.
# Currently, only one such service is "reflector.service" which updates /etc/pacman.d/mirrorlist # Currently, only one such service is "reflector.service" which updates /etc/pacman.d/mirrorlist
@ -261,10 +265,11 @@ def perform_installation(device, boot_partition, language, mirrors):
while 'dead' not in (status := archinstall.service_state('reflector')): while 'dead' not in (status := archinstall.service_state('reflector')):
time.sleep(1) time.sleep(1)
archinstall.use_mirrors(mirrors) # Set the mirrors for the live medium archinstall.use_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors for the live medium
if installation.minimal_installation(): if installation.minimal_installation():
installation.set_mirrors(mirrors) # Set the mirrors in the installation medium installation.set_hostname(archinstall.arguments['hostname'])
installation.set_keyboard_language(language) installation.set_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors in the installation medium
installation.set_keyboard_language(archinstall.arguments['keyboard-language'])
installation.add_bootloader() installation.add_bootloader()
# If user selected to copy the current ISO network configuration # If user selected to copy the current ISO network configuration