Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/installer.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-11-06 10:47:19 +0100
committerAnton Hvornum <anton@hvornum.se>2021-11-06 10:47:19 +0100
commit129326b93fc58a00d15ed89fe4e701d07b0385bf (patch)
tree7c86893ab3776a6806241a74a75052e448c6cad3 /archinstall/lib/installer.py
parent97a91aab6019d6efb500de1240bc58b4165ab02d (diff)
parent17fe62c641607cc460e6c6590192ad8de0a21b1a (diff)
Merge branch 'master' of https://github.com/archlinux/archinstall into torxed-fix-109
Diffstat (limited to 'archinstall/lib/installer.py')
-rw-r--r--archinstall/lib/installer.py79
1 files changed, 56 insertions, 23 deletions
diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py
index 9cff1f7a..c2c30f7c 100644
--- a/archinstall/lib/installer.py
+++ b/archinstall/lib/installer.py
@@ -1,15 +1,25 @@
import time
from typing import Union
-from .disk import *
-from .hardware import *
+import logging
+import os
+import shutil
+import shlex
+import pathlib
+import subprocess
+import glob
+from .disk import get_partitions_in_use, Partition, find_partition_by_mountpoint
+from .general import SysCommand
+from .hardware import has_uefi, is_vm, cpu_vendor
from .locale_helpers import verify_keyboard_layout, verify_x11_keyboard_layout
from .disk.helpers import get_mount_info
-from .mirrors import *
+from .mirrors import use_mirrors
from .plugins import plugins
from .storage import storage
-from .user_interaction import *
+# from .user_interaction import *
+from .output import log
+from .profiles import Profile
from .disk.btrfs import create_subvolume, mount_subvolume
-from .exceptions import DiskError, ServiceException
+from .exceptions import DiskError, ServiceException, RequirementError, HardwareIncompatibilityError
# Any package that the Installer() is responsible for (optional and the default ones)
__packages__ = ["base", "base-devel", "linux-firmware", "linux", "linux-lts", "linux-zen", "linux-hardened"]
@@ -165,7 +175,7 @@ class Installer:
for mountpoint in sorted(mountpoints.keys()):
if mountpoints[mountpoint]['encrypted']:
- loopdev = storage.get('ENC_IDENTIFIER', 'ai')+'loop'
+ loopdev = storage.get('ENC_IDENTIFIER', 'ai') + 'loop'
password = mountpoints[mountpoint]['password']
with luks2(mountpoints[mountpoint]['device_instance'], loopdev, password, auto_unmount=False) as unlocked_device:
unlocked_device.mount(f"{self.target}{mountpoint}")
@@ -224,7 +234,7 @@ class Installer:
self.log(f"Updating {self.target}/etc/fstab", level=logging.INFO)
with open(f"{self.target}/etc/fstab", 'a') as fstab_fh:
- fstab_fh.write(SysCommand(f'/usr/bin/genfstab {flags} {self.target}').decode())
+ fstab_fh.write((fstab := SysCommand(f'/usr/bin/genfstab {flags} {self.target}')).decode())
if not os.path.isfile(f'{self.target}/etc/fstab'):
raise RequirementError(f'Could not generate fstab, strapping in packages most likely failed (disk out of space?)\n{fstab}')
@@ -273,10 +283,21 @@ class Installer:
)
def activate_ntp(self):
- self.log('Installing and activating NTP.', level=logging.INFO)
- if self.pacstrap('ntp'):
- if self.enable_service('ntpd'):
- return True
+ log(f"activate_ntp() is deprecated, use activate_time_syncronization()", fg="yellow", level=logging.INFO)
+ self.activate_time_syncronization()
+
+ def activate_time_syncronization(self):
+ self.log('Activating systemd-timesyncd for time synchronization using Arch Linux and ntp.org NTP servers.', level=logging.INFO)
+ self.enable_service('systemd-timesyncd')
+
+ with open(f"{self.target}/etc/systemd/timesyncd.conf", "w") as fh:
+ fh.write("[Time]\n")
+ fh.write("NTP=0.arch.pool.ntp.org 1.arch.pool.ntp.org 2.arch.pool.ntp.org 3.arch.pool.ntp.org\n")
+ fh.write("FallbackNTP=0.pool.ntp.org 1.pool.ntp.org 0.fr.pool.ntp.org\n")
+
+ from .systemd import Boot
+ with Boot(self) as session:
+ session.SysCommand(["timedatectl", "set-ntp", 'true'])
def enable_service(self, *services):
for service in services:
@@ -291,9 +312,9 @@ class Installer:
def run_command(self, cmd, *args, **kwargs):
return SysCommand(f'/usr/bin/arch-chroot {self.target} {cmd}')
- def arch_chroot(self, cmd, *args, **kwargs):
- if 'runas' in kwargs:
- cmd = f"su - {kwargs['runas']} -c \"{cmd}\""
+ def arch_chroot(self, cmd, run_as=None):
+ if run_as:
+ cmd = f"su - {run_as} -c {shlex.quote(cmd)}"
return self.run_command(cmd)
@@ -468,6 +489,22 @@ class Installer:
return True
+ def setup_swap(self, kind='zram'):
+ if kind == 'zram':
+ self.log(f"Setting up swap on zram")
+ self.pacstrap('zram-generator')
+
+ # We could use the default example below, but maybe not the best idea: https://github.com/archlinux/archinstall/pull/678#issuecomment-962124813
+ # zram_example_location = '/usr/share/doc/zram-generator/zram-generator.conf.example'
+ # shutil.copy2(f"{self.target}{zram_example_location}", f"{self.target}/usr/lib/systemd/zram-generator.conf")
+ with open(f"{self.target}/etc/systemd/zram-generator.conf", "w") as zram_conf:
+ zram_conf.write("[zram0]\n")
+
+ if self.enable_service('systemd-zram-setup@zram0.service'):
+ return True
+ else:
+ raise ValueError(f"Archinstall currently only supports setting up swap on zram")
+
def add_bootloader(self, bootloader='systemd-bootctl'):
for plugin in plugins.values():
if hasattr(plugin, 'on_add_bootloader'):
@@ -580,7 +617,7 @@ class Installer:
self.helper_flags['bootloader'] = True
return True
else:
- boot_partition = filesystem.find_partition(mountpoint=f"{self.target}/boot")
+ boot_partition = find_partition_by_mountpoint(self.partitions, relative_mountpoint=f"/boot")
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --target=i386-pc --recheck {boot_partition.path}')
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-mkconfig -o /boot/grub/grub.cfg')
self.helper_flags['bootloader'] = True
@@ -621,14 +658,14 @@ class Installer:
if not handled_by_plugin:
self.log(f'Creating user {user}', level=logging.INFO)
- o = b''.join(SysCommand(f'/usr/bin/arch-chroot {self.target} useradd -m -G wheel {user}'))
+ SysCommand(f'/usr/bin/arch-chroot {self.target} useradd -m -G wheel {user}')
if password:
self.user_set_pw(user, password)
if groups:
for group in groups:
- o = b''.join(SysCommand(f'/usr/bin/arch-chroot {self.target} gpasswd -a {user} {group}'))
+ SysCommand(f'/usr/bin/arch-chroot {self.target} gpasswd -a {user} {group}')
if sudo and self.enable_sudo(user):
self.helper_flags['user'] = True
@@ -640,14 +677,12 @@ class Installer:
# This means the root account isn't locked/disabled with * in /etc/passwd
self.helper_flags['user'] = True
- o = b''.join(SysCommand(f"/usr/bin/arch-chroot {self.target} sh -c \"echo '{user}:{password}' | chpasswd\""))
- pass
+ SysCommand(f"/usr/bin/arch-chroot {self.target} sh -c \"echo '{user}:{password}' | chpasswd\"")
def user_set_shell(self, user, shell):
self.log(f'Setting shell for {user} to {shell}', level=logging.INFO)
- o = b''.join(SysCommand(f"/usr/bin/arch-chroot {self.target} sh -c \"chsh -s {shell} {user}\""))
- pass
+ SysCommand(f"/usr/bin/arch-chroot {self.target} sh -c \"chsh -s {shell} {user}\"")
def chown(self, owner, path, options=[]):
return SysCommand(f"/usr/bin/arch-chroot {self.target} sh -c 'chown {' '.join(options)} {owner} {path}")
@@ -664,7 +699,6 @@ class Installer:
# In accordance with https://github.com/archlinux/archinstall/issues/107#issuecomment-841701968
# Setting an empty keymap first, allows the subsequent call to set layout for both console and x11.
from .systemd import Boot
-
with Boot(self) as session:
session.SysCommand(["localectl", "set-keymap", '""'])
@@ -688,7 +722,6 @@ class Installer:
return False
from .systemd import Boot
-
with Boot(self) as session:
session.SysCommand(["localectl", "set-x11-keymap", '""'])