Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions archinstall/lib/boot.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
from __future__ import annotations

import time
from collections.abc import Iterator
from pathlib import Path
from types import TracebackType
from typing import TYPE_CHECKING, ClassVar, Self
from typing import ClassVar, Self

from archinstall.lib.command import SysCommand, SysCommandWorker, locate_binary
from archinstall.lib.exceptions import SysCallError
from archinstall.lib.output import error

if TYPE_CHECKING:
from archinstall.lib.installer import Installer


class Boot:
_active_boot: ClassVar[Self | None] = None

def __init__(self, installation: Installer):
self.instance = installation
def __init__(self, path: Path | str):
if isinstance(path, Path):
path = str(path)

self.path = path
self.container_name = 'archinstall'
self.session: SysCommandWorker | None = None
self.ready = False

def __enter__(self) -> Self:
if Boot._active_boot and Boot._active_boot.instance != self.instance:
if Boot._active_boot and Boot._active_boot.path != self.path:
raise KeyError('Archinstall only supports booting up one instance and another session is already active.')

if Boot._active_boot:
Expand All @@ -36,7 +35,7 @@ def __enter__(self) -> Self:
[
'systemd-nspawn',
'-D',
str(self.instance.target),
self.path,
'--timezone=off',
'-b',
'--no-pager',
Expand All @@ -61,7 +60,7 @@ def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseExceptio
if exc_type is not None:
error(
str(exc_value),
f'The error above occurred in a temporary boot-up of the installation {self.instance}',
f'The error above occurred in a temporary boot-up of the installation {self.path!r}',
)

shutdown = None
Expand All @@ -85,7 +84,7 @@ def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseExceptio
session_exit_code = self.session.exit_code if self.session else -1

raise SysCallError(
f'Could not shut down temporary boot of {self.instance}: {session_exit_code}/{shutdown_exit_code}',
f'Could not shut down temporary boot of {self.path!r}: {session_exit_code}/{shutdown_exit_code}',
exit_code=next(filter(bool, [session_exit_code, shutdown_exit_code])),
)

Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@ def set_keyboard_language(self, language: str) -> bool:

# 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.
with Boot(self) as session:
with Boot(self.target) as session:
os.system('systemd-run --machine=archinstall --pty localectl set-keymap ""')

try:
Expand All @@ -2046,7 +2046,7 @@ def set_x11_keyboard_language(self, language: str) -> bool:
error(f'Invalid x11-keyboard language specified: {language}')
return False

with Boot(self) as session:
with Boot(self.target) as session:
session.SysCommand(['localectl', 'set-x11-keymap', '""'])

try:
Expand Down