From b4eb8557f5ab4ced63cae061875cf6080f0ab7cd Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 1 Nov 2021 09:59:32 +0000 Subject: Adding support for swap on zram --- archinstall/lib/installer.py | 11 +++++++++++ archinstall/lib/user_interaction.py | 3 +++ 2 files changed, 14 insertions(+) (limited to 'archinstall/lib') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 0bdddb2e..f83e0128 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1,4 +1,5 @@ import time +import shutil from .disk import * from .hardware import * from .locale_helpers import verify_keyboard_layout, verify_x11_keyboard_layout @@ -9,6 +10,7 @@ from .storage import storage from .user_interaction import * from .disk.btrfs import create_subvolume, mount_subvolume from .exceptions import DiskError, ServiceException +from .output import log # 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"] @@ -442,6 +444,15 @@ 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') + 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") + 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'): diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index ba6259b1..d0ed0747 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -326,6 +326,9 @@ class MiniCurses: return response +def ask_for_swap(prompt='Would you like to use swap on zram? (Y/n): ', forced=False): + return True if input(prompt).strip(' ').lower() not in ('n', 'no') else False + def ask_for_superuser_account(prompt='Username for required superuser with sudo privileges: ', forced=False): while 1: new_user = input(prompt).strip(' ') -- cgit v1.2.3-70-g09d2 From 9bc46a3eb6053fcf9e2c87a087c7ee30c0025491 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 1 Nov 2021 10:08:53 +0000 Subject: Adding in enabling of zram service --- archinstall/lib/installer.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'archinstall/lib') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index f83e0128..9de66215 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -450,6 +450,9 @@ class Installer: self.pacstrap('zram-generator') 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") + + if self.enable_service('systemd-zram-setup@zram0.service') and self.enable_service('systemd-zram-setup@zram1.service'): + return True else: raise ValueError(f"Archinstall currently only supports setting up swap on zram") -- cgit v1.2.3-70-g09d2 From 5df69abfee214cd5c19889b159ec277e43970b32 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 5 Nov 2021 21:41:19 +0100 Subject: Stripped down the default zram configuration for zram-generator --- archinstall/lib/installer.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 29b884d5..7cf59c22 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -467,10 +467,14 @@ class Installer: if kind == 'zram': self.log(f"Setting up swap on zram") self.pacstrap('zram-generator') - 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") - - if self.enable_service('systemd-zram-setup@zram0.service') and self.enable_service('systemd-zram-setup@zram1.service'): + + # 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}/usr/lib/systemd/zram-generator.conf", "w") as zram_conf: + zram_conf.write("[zram0]") + + if self.enable_service('systemd-zram-setup@zram0.service'): return True else: raise ValueError(f"Archinstall currently only supports setting up swap on zram") -- cgit v1.2.3-70-g09d2 From 525954946681945233c12f0f5b70a62d56cf9906 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 5 Nov 2021 21:47:30 +0100 Subject: Fixed some import errors that snuk in master --- archinstall/lib/disk/blockdevice.py | 2 +- archinstall/lib/disk/filesystem.py | 2 +- archinstall/lib/disk/partition.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/disk/blockdevice.py b/archinstall/lib/disk/blockdevice.py index fad04c7b..5f6e564c 100644 --- a/archinstall/lib/disk/blockdevice.py +++ b/archinstall/lib/disk/blockdevice.py @@ -3,8 +3,8 @@ import os import json import logging -from .exceptions import DiskError from .helpers import all_disks +from ..exceptions import DiskError from ..output import log from ..general import SysCommand diff --git a/archinstall/lib/disk/filesystem.py b/archinstall/lib/disk/filesystem.py index 69593d08..ac3c9d17 100644 --- a/archinstall/lib/disk/filesystem.py +++ b/archinstall/lib/disk/filesystem.py @@ -1,9 +1,9 @@ import time import logging import json -from .exceptions import DiskError from .partition import Partition from .validators import valid_fs_type +from ..exceptions import DiskError from ..general import SysCommand from ..output import log from ..storage import storage diff --git a/archinstall/lib/disk/partition.py b/archinstall/lib/disk/partition.py index afe46db3..a459a820 100644 --- a/archinstall/lib/disk/partition.py +++ b/archinstall/lib/disk/partition.py @@ -7,9 +7,9 @@ import os import hashlib from typing import Optional from .blockdevice import BlockDevice -from .exceptions import DiskError, SysCallError, UnknownFilesystemFormat from .helpers import get_mount_info, get_filesystem_type -from .storage import storage +from ..storage import storage +from ..exceptions import DiskError, SysCallError, UnknownFilesystemFormat from ..output import log from ..general import SysCommand -- cgit v1.2.3-70-g09d2 From 93fcc4cb546a73b6bcc274c540148cd98b70426a Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 5 Nov 2021 21:50:56 +0100 Subject: Fixed a broken import --- archinstall/lib/disk/blockdevice.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/disk/blockdevice.py b/archinstall/lib/disk/blockdevice.py index 5f6e564c..f80f57f3 100644 --- a/archinstall/lib/disk/blockdevice.py +++ b/archinstall/lib/disk/blockdevice.py @@ -1,9 +1,6 @@ -# flake8: noqa -# The above ignore, see issue: https://github.com/archlinux/archinstall/pull/650#issuecomment-961995949 import os import json import logging -from .helpers import all_disks from ..exceptions import DiskError from ..output import log from ..general import SysCommand -- cgit v1.2.3-70-g09d2 From 007e75b6f16f0a83767f11250ab49e6c2bf4f8ad Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 5 Nov 2021 21:59:09 +0100 Subject: Fixed broken import from master (GRUB non-EFI might be wonky) --- archinstall/lib/installer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 7cf59c22..e0c0aee5 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -6,7 +6,7 @@ import shlex import pathlib import subprocess import glob -from .disk import get_partitions_in_use, Partition, find_partition +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 @@ -591,7 +591,7 @@ class Installer: self.helper_flags['bootloader'] = True return True else: - boot_partition = 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 -- cgit v1.2.3-70-g09d2 From f1422d955fc793886c7f7b0f3906f8a2169d8d9e Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 5 Nov 2021 22:00:59 +0100 Subject: Fixed broken import from master --- archinstall/lib/installer.py | 4 +++- archinstall/lib/systemd.py | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index e0c0aee5..36f2e81f 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -14,7 +14,6 @@ from .disk.helpers import get_mount_info from .mirrors import use_mirrors from .plugins import plugins from .storage import storage -from .systemd import Boot # from .user_interaction import * from .output import log from .profiles import Profile @@ -270,6 +269,7 @@ class Installer: 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']) @@ -668,6 +668,7 @@ class Installer: # Setting an empty keymap first, allows the subsequent call to set layout for both console and x11. from .systemd import Boot + from .systemd import Boot with Boot(self) as session: session.SysCommand(["localectl", "set-keymap", '""']) @@ -692,6 +693,7 @@ class Installer: from .systemd import Boot + from .systemd import Boot with Boot(self) as session: session.SysCommand(["localectl", "set-x11-keymap", '""']) diff --git a/archinstall/lib/systemd.py b/archinstall/lib/systemd.py index d297c507..a7e35839 100644 --- a/archinstall/lib/systemd.py +++ b/archinstall/lib/systemd.py @@ -1,5 +1,4 @@ import logging - from .general import SysCommand, SysCommandWorker, locate_binary from .installer import Installer from .output import log -- cgit v1.2.3-70-g09d2 From a5730dec856d4265667283e9ef8b9227db069a84 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 5 Nov 2021 22:03:24 +0100 Subject: Misspelled variable name --- archinstall/lib/user_interaction.py | 1 + examples/guided.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 84eefdc0..e62d8c6c 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -328,6 +328,7 @@ class MiniCurses: def ask_for_swap(prompt='Would you like to use swap on zram? (Y/n): ', forced=False): return True if input(prompt).strip(' ').lower() not in ('n', 'no') else False + def ask_for_superuser_account(prompt='Username for required superuser with sudo privileges: ', forced=False): while 1: new_user = input(prompt).strip(' ') diff --git a/examples/guided.py b/examples/guided.py index 4bbe94ca..f5fa1542 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -127,7 +127,7 @@ def ask_user_questions(): archinstall.arguments["bootloader"] = archinstall.ask_for_bootloader() if not archinstall.arguments.get('swap', None): - archinstall.archinstall['swap'] = archinstall.ask_for_swap() + archinstall.arguments['swap'] = archinstall.ask_for_swap() # Get the hostname for the machine if not archinstall.arguments.get('hostname', None): @@ -271,7 +271,7 @@ def perform_installation(mountpoint): if archinstall.arguments["bootloader"] == "grub-install" and archinstall.has_uefi(): installation.add_additional_packages("grub") installation.add_bootloader(archinstall.arguments["bootloader"]) - if archinstall.archinstall['swap']: + if archinstall.arguments['swap']: installation.setup_swap('zram') # If user selected to copy the current ISO network configuration -- cgit v1.2.3-70-g09d2 From e29f440c0b9593d4197e1c376abb750f0e5694b5 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 5 Nov 2021 22:09:51 +0100 Subject: Fixed newline in zram conf --- archinstall/lib/installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 36f2e81f..1d4297a0 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -472,7 +472,7 @@ class Installer: # 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}/usr/lib/systemd/zram-generator.conf", "w") as zram_conf: - zram_conf.write("[zram0]") + zram_conf.write("[zram0]\n") if self.enable_service('systemd-zram-setup@zram0.service'): return True -- cgit v1.2.3-70-g09d2 From 0fed0b3ce544204ef3ef5ba155825e916f358323 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 5 Nov 2021 23:07:04 +0100 Subject: Fixed default zram conf location and imports --- archinstall/lib/installer.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 1d4297a0..b400e741 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -471,7 +471,7 @@ class Installer: # 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}/usr/lib/systemd/zram-generator.conf", "w") as zram_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'): @@ -666,8 +666,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 - from .systemd import Boot with Boot(self) as session: session.SysCommand(["localectl", "set-keymap", '""']) @@ -691,8 +689,6 @@ class Installer: self.log(f"Invalid x11-keyboard language specified: {language}", fg="red", level=logging.ERROR) return False - from .systemd import Boot - from .systemd import Boot with Boot(self) as session: session.SysCommand(["localectl", "set-x11-keymap", '""']) -- cgit v1.2.3-70-g09d2