Exemplo n.º 1
0
def perform_installation(mountpoint):
    """
	Performs the installation steps on a block device.
	Only requirement is that the block devices are
	formatted and setup prior to entering this function.
	"""
    with archinstall.Installer(mountpoint,
                               kernels=archinstall.arguments.get(
                                   'kernels', 'linux')) as installation:
        # if len(mirrors):
        # 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
        # We need to wait for it before we continue since we opted in to use a custom mirror/region.
        installation.log(
            'Waiting for automatic mirror selection (reflector) to complete.',
            level=logging.INFO)
        while archinstall.service_state('reflector') not in ('dead', 'failed'):
            time.sleep(1)
        # Set mirrors used by pacstrap (outside of installation)
        if archinstall.arguments.get('mirror-region', None):
            archinstall.use_mirrors(archinstall.arguments['mirror-region']
                                    )  # Set the mirrors for the live medium
        if installation.minimal_installation():
            installation.set_hostname(archinstall.arguments['hostname'])
            if archinstall.arguments['mirror-region'].get("mirrors",
                                                          None) is not None:
                installation.set_mirrors(
                    archinstall.arguments['mirror-region']
                )  # Set the mirrors in the installation medium
            if archinstall.arguments[
                    "bootloader"] == "grub-install" and has_uefi():
                installation.add_additional_packages("grub")
            installation.add_bootloader(archinstall.arguments["bootloader"])

            # If user selected to copy the current ISO network configuration
            # Perform a copy of the config
            if archinstall.arguments.get(
                    'nic',
                {}) == 'Copy ISO network configuration to installation':
                installation.copy_iso_network_config(
                    enable_services=True
                )  # Sources the ISO network configuration to the install medium.
            elif archinstall.arguments.get('nic',
                                           {}).get('NetworkManager', False):
                installation.add_additional_packages("networkmanager")
                installation.enable_service('NetworkManager.service')
            # Otherwise, if a interface was selected, configure that interface
            elif archinstall.arguments.get('nic', {}):
                installation.configure_nic(
                    **archinstall.arguments.get('nic', {}))
                installation.enable_service('systemd-networkd')
                installation.enable_service('systemd-resolved')

            if archinstall.arguments.get('audio', None) is not None:
                installation.log(
                    f"This audio server will be used: {archinstall.arguments.get('audio', None)}",
                    level=logging.INFO)
                if archinstall.arguments.get('audio', None) == 'pipewire':
                    print('Installing pipewire ...')

                    installation.add_additional_packages([
                        "pipewire", "pipewire-alsa", "pipewire-jack",
                        "pipewire-media-session", "pipewire-pulse",
                        "gst-plugin-pipewire", "libpulse"
                    ])
                elif archinstall.arguments.get('audio', None) == 'pulseaudio':
                    print('Installing pulseaudio ...')
                    installation.add_additional_packages("pulseaudio")
            else:
                installation.log("No audio server will be installed.",
                                 level=logging.INFO)

            if archinstall.arguments.get('packages',
                                         None) and archinstall.arguments.get(
                                             'packages', None)[0] != '':
                installation.add_additional_packages(
                    archinstall.arguments.get('packages', None))

            if archinstall.arguments.get('profile', None):
                installation.install_profile(
                    archinstall.arguments.get('profile', None))

            for user, user_info in archinstall.arguments.get('users',
                                                             {}).items():
                installation.user_create(user,
                                         user_info["!password"],
                                         sudo=False)

            for superuser, user_info in archinstall.arguments.get(
                    'superusers', {}).items():
                installation.user_create(superuser,
                                         user_info["!password"],
                                         sudo=True)

            if timezone := archinstall.arguments.get('timezone', None):
                installation.set_timezone(timezone)

            if (root_pw := archinstall.arguments.get('!root-password',
                                                     None)) and len(root_pw):
                installation.user_set_pw('root', root_pw)

            # This step must be after profile installs to allow profiles to install language pre-requisits.
            # After which, this step will set the language both for console and x11 if x11 was installed for instance.
            installation.set_keyboard_language(
                archinstall.arguments['keyboard-language'])

            if archinstall.arguments['profile'] and archinstall.arguments[
                    'profile'].has_post_install():
                with archinstall.arguments['profile'].load_instructions(
                        namespace=
                        f"{archinstall.arguments['profile'].namespace}.py"
                ) as imported:
                    if not imported._post_install():
                        archinstall.log(
                            ' * Profile\'s post configuration requirements was not fulfilled.',
                            fg='red')
                        exit(1)
Exemplo n.º 2
0
def perform_installation_steps():
    print()
    print('This is your chosen configuration:')
    archinstall.log("-- Guided template chosen (with below config) --",
                    level=logging.DEBUG)
    archinstall.log(json.dumps(archinstall.arguments,
                               indent=4,
                               sort_keys=True,
                               cls=archinstall.JSON),
                    level=logging.INFO)
    print()

    if not archinstall.arguments.get('silent'):
        input('Press Enter to continue.')
    """
		Issue a final warning before we continue with something un-revertable.
		We mention the drive one last time, and count from 5 to 0.
	"""

    if archinstall.arguments.get('harddrive', None):
        print(f" ! Formatting {archinstall.arguments['harddrive']} in ",
              end='')
        archinstall.do_countdown()
        """
			Setup the blockdevice, filesystem (and optionally encryption).
			Once that's done, we'll hand over to perform_installation()
		"""
        mode = archinstall.GPT
        if has_uefi() is False:
            mode = archinstall.MBR
        with archinstall.Filesystem(archinstall.arguments['harddrive'],
                                    mode) as fs:
            # Wipe the entire drive if the disk flag `keep_partitions`is False.
            if archinstall.arguments['harddrive'].keep_partitions is False:
                fs.use_entire_disk(
                    root_filesystem_type=archinstall.arguments.get(
                        'filesystem', 'btrfs'))

            # Check if encryption is desired and mark the root partition as encrypted.
            if archinstall.arguments.get('!encryption-password', None):
                root_partition = fs.find_partition('/')
                root_partition.encrypted = True

            # After the disk is ready, iterate the partitions and check
            # which ones are safe to format, and format those.
            for partition in archinstall.arguments['harddrive']:
                if partition.safe_to_format():
                    # 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.
                    # In which case partition.encrypted will be true, but passwd will be false.
                    if partition.encrypted and (passwd :=
                                                archinstall.arguments.get(
                                                    '!encryption-password',
                                                    None)):
                        partition.encrypt(password=passwd)
                    else:
                        partition.format()
                else:
                    archinstall.log(
                        f"Did not format {partition} because .safe_to_format() returned False or .allow_formatting was False.",
                        level=logging.DEBUG)

            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(
                        archinstall.storage.get('MOUNT_POINT', '/mnt'))
            else:
                fs.find_partition('/').mount(
                    archinstall.storage.get('MOUNT_POINT', '/mnt'))

            if has_uefi():
                fs.find_partition('/boot').mount(
                    archinstall.storage.get('MOUNT_POINT', '/mnt') + '/boot')