Merge pull request #678 from archlinux/torxed-fix-175
Adding support for swap on zram
This commit is contained in:
commit
17fe62c641
|
|
@ -1,10 +1,7 @@
|
|||
# flake8: noqa
|
||||
# The above ignore, see issue: https://github.com/archlinux/archinstall/pull/650#issuecomment-961995949
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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'])
|
||||
|
||||
|
|
@ -463,6 +463,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'):
|
||||
|
|
@ -575,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
|
||||
|
|
@ -651,7 +667,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", '""'])
|
||||
|
||||
|
|
@ -675,7 +690,6 @@ class Installer:
|
|||
return False
|
||||
|
||||
from .systemd import Boot
|
||||
|
||||
with Boot(self) as session:
|
||||
session.SysCommand(["localectl", "set-x11-keymap", '""'])
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import logging
|
||||
|
||||
from .general import SysCommand, SysCommandWorker, locate_binary
|
||||
from .installer import Installer
|
||||
from .output import log
|
||||
|
|
|
|||
|
|
@ -325,6 +325,10 @@ 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(' ')
|
||||
|
|
|
|||
|
|
@ -126,6 +126,9 @@ def ask_user_questions():
|
|||
if not archinstall.arguments.get("bootloader", None):
|
||||
archinstall.arguments["bootloader"] = archinstall.ask_for_bootloader()
|
||||
|
||||
if not archinstall.arguments.get('swap', None):
|
||||
archinstall.arguments['swap'] = archinstall.ask_for_swap()
|
||||
|
||||
# Get the hostname for the machine
|
||||
if not archinstall.arguments.get('hostname', None):
|
||||
archinstall.arguments['hostname'] = input('Desired hostname for the installation: ').strip(' ')
|
||||
|
|
@ -155,7 +158,7 @@ def ask_user_questions():
|
|||
# Ask about audio server selection if one is not already set
|
||||
if not archinstall.arguments.get('audio', None):
|
||||
# The argument to ask_for_audio_selection lets the library know if it's a desktop profile
|
||||
archinstall.arguments['audio'] = archinstall.ask_for_audio_selection(archinstall.profiles.is_desktop_profile(archinstall.arguments['profile']))
|
||||
archinstall.arguments['audio'] = archinstall.ask_for_audio_selection(archinstall.is_desktop_profile(archinstall.arguments['profile']))
|
||||
|
||||
# Ask for preferred kernel:
|
||||
if not archinstall.arguments.get("kernels", None):
|
||||
|
|
@ -268,6 +271,8 @@ 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.arguments['swap']:
|
||||
installation.setup_swap('zram')
|
||||
|
||||
# If user selected to copy the current ISO network configuration
|
||||
# Perform a copy of the config
|
||||
|
|
|
|||
Loading…
Reference in New Issue