Update os_install.py
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
import subprocess
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CommandResult:
|
||||
def __init__(self, stdout, stderr, returncode):
|
||||
self.stdout = stdout
|
||||
self.stderr = stderr
|
||||
self.returncode = returncode
|
||||
|
||||
|
||||
def run_command(cmd, check=True):
|
||||
logger.info(f"Running command: {' '.join(cmd)}")
|
||||
|
||||
@@ -20,7 +22,7 @@ def run_command(cmd, check=True):
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
bufsize=1 # Line buffered
|
||||
bufsize=1, # Line buffered
|
||||
)
|
||||
|
||||
stdout_lines = []
|
||||
@@ -35,8 +37,13 @@ def run_command(cmd, check=True):
|
||||
line_list.append(line)
|
||||
|
||||
import threading
|
||||
t1 = threading.Thread(target=read_stream, args=(process.stdout, stdout_lines, logger.info))
|
||||
t2 = threading.Thread(target=read_stream, args=(process.stderr, stderr_lines, logger.error))
|
||||
|
||||
t1 = threading.Thread(
|
||||
target=read_stream, args=(process.stdout, stdout_lines, logger.info)
|
||||
)
|
||||
t2 = threading.Thread(
|
||||
target=read_stream, args=(process.stderr, stderr_lines, logger.error)
|
||||
)
|
||||
|
||||
t1.start()
|
||||
t2.start()
|
||||
@@ -50,10 +57,13 @@ def run_command(cmd, check=True):
|
||||
stderr_str = "".join(stderr_lines)
|
||||
|
||||
if check and returncode != 0:
|
||||
raise subprocess.CalledProcessError(returncode, cmd, output=stdout_str, stderr=stderr_str)
|
||||
raise subprocess.CalledProcessError(
|
||||
returncode, cmd, output=stdout_str, stderr=stderr_str
|
||||
)
|
||||
|
||||
return CommandResult(stdout_str, stderr_str, returncode)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def mount_pseudo_fs(mount_root):
|
||||
"""
|
||||
@@ -78,7 +88,8 @@ def mount_pseudo_fs(mount_root):
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to unmount {path}: {e}")
|
||||
|
||||
def install_minimal_os(mount_root, releasever="41"):
|
||||
|
||||
def install_minimal_os(mount_root, releasever="43"):
|
||||
"""
|
||||
Installs minimal Fedora packages to mount_root.
|
||||
"""
|
||||
@@ -96,16 +107,18 @@ def install_minimal_os(mount_root, releasever="41"):
|
||||
"efibootmgr",
|
||||
"passwd",
|
||||
"rootfiles",
|
||||
"vim-minimal"
|
||||
"vim-minimal",
|
||||
]
|
||||
|
||||
cmd = [
|
||||
"dnf", "install", "-y",
|
||||
"dnf",
|
||||
"install",
|
||||
"-y",
|
||||
f"--installroot={mount_root}",
|
||||
f"--releasever={releasever}",
|
||||
"--use-host-config",
|
||||
"--setopt=install_weak_deps=False",
|
||||
"--nodocs"
|
||||
"--nodocs",
|
||||
] + packages
|
||||
|
||||
with mount_pseudo_fs(mount_root):
|
||||
@@ -113,6 +126,7 @@ def install_minimal_os(mount_root, releasever="41"):
|
||||
|
||||
logger.info("Base system installation complete.")
|
||||
|
||||
|
||||
def configure_system(mount_root, partition_info):
|
||||
"""
|
||||
Basic configuration: fstab and grub.
|
||||
@@ -144,7 +158,13 @@ UUID={efi_uuid} /boot/efi vfat defaults 0 2
|
||||
# 2. Configure GRUB
|
||||
with mount_pseudo_fs(mount_root):
|
||||
# grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||
chroot_cmd = ["chroot", mount_root, "grub2-mkconfig", "-o", "/boot/grub2/grub.cfg"]
|
||||
chroot_cmd = [
|
||||
"chroot",
|
||||
mount_root,
|
||||
"grub2-mkconfig",
|
||||
"-o",
|
||||
"/boot/grub2/grub.cfg",
|
||||
]
|
||||
run_command(chroot_cmd)
|
||||
|
||||
logger.info("System configuration complete.")
|
||||
|
||||
Reference in New Issue
Block a user