Compare commits

...

15 Commits

Author SHA1 Message Date
ada17eefd7 Switch to systemd-boot for UEFI while keeping GRUB2 for BIOS/MBR 2026-02-10 13:29:02 +01:00
2e8e99f481 Add --force to UEFI grub2-install to bypass Fedora Secure Boot warning 2026-02-10 13:26:49 +01:00
53227e0f8e Fix UEFI grub2-install: add missing modules package and fix DNF stderr logging 2026-02-09 19:05:27 +01:00
2762f2f767 Robust log capture on SIGINT/SIGTERM and cleaner Discord reporting 2026-02-09 18:39:17 +01:00
19254e128c Enhance Discord error reporting: code blocks and crash robustness 2026-02-09 18:00:20 +01:00
5abba6ce88 Improve Discord logging for errors and further fix UEFI mount robustness 2026-02-09 17:41:12 +01:00
0ec7de3937 Fix UEFI GRUB installation: ensure ESP is mounted to /boot/efi and improve error logging 2026-02-09 16:53:30 +01:00
cbc1b05eca Simplify run_vm_bios.sh to unconditionally load clean-state snapshot 2026-02-09 15:24:46 +01:00
e8afc31d00 Enable snapshot support in run_vm_bios.sh with automatic detection 2026-02-09 15:14:09 +01:00
59219130bd Fix run_vm_bios.sh: add missing backslashes and improve CDROM boot compatibility 2026-02-09 15:08:23 +01:00
e8a2f7aaa9 Redo backend installer logic to support BIOS/MBR boot on older devices and switch to GRUB2 2026-02-09 15:02:14 +01:00
b37fc8d060 Update run_vm_uefi.sh 2026-02-09 14:22:45 +01:00
44af152887 Revert "Improve offline repository discovery and dnf configuration for ISO installs"
This reverts commit 297f2cd3c2.
2026-02-05 19:43:12 +01:00
5238fd29d9 Revert "Fix dnf failure by adding /run mount, removing --cacheonly, and ensuring host-config usage"
This reverts commit 951a1b7fdc.
2026-02-05 19:43:12 +01:00
74fedf9001 Revert "Further improvements to dnf robustness and repo discovery for offline installs"
This reverts commit 5df00a5814.
2026-02-05 19:43:12 +01:00
9 changed files with 317 additions and 371 deletions

View File

@@ -128,123 +128,97 @@ def ensure_unmounted(disk_device):
logger.warning(f"Error during pre-partition unmount: {e}") logger.warning(f"Error during pre-partition unmount: {e}")
def is_uefi():
"""Checks if the system is booted in UEFI mode."""
return os.path.exists("/sys/firmware/efi")
def auto_partition_disk(disk_device): def auto_partition_disk(disk_device):
""" """
Automatically partitions the disk: Automatically partitions the disk based on boot mode:
1. EFI System Partition (2GB standard, 1GB small) UEFI (GPT): ESP (1GB), Root (Remaining), Swap (RAM+2GB)
2. Root (Remaining) BIOS (MBR): Root (Remaining, Bootable), Swap (RAM+2GB)
3. Swap (RAM + 2GB, or 0 if small)
Layout: P1=EFI, P3=Swap (End), P2=Root (Middle)
""" """
logger.info(f"Starting auto-partitioning on {disk_device}") uefi = is_uefi()
log_disk_operation("PARTITION", "start", f"Disk: {disk_device}") logger.info(f"Starting auto-partitioning on {disk_device} (UEFI: {uefi})")
log_disk_operation("PARTITION", "start", f"Disk: {disk_device}, UEFI: {uefi}")
# 0. Ensure unmounted
ensure_unmounted(disk_device) ensure_unmounted(disk_device)
# Calculate sizes
disk_size = get_disk_size(disk_device) disk_size = get_disk_size(disk_device)
ram_size = get_total_memory() ram_size = get_total_memory()
# Defaults # Calculate sizes
efi_mb = 2048
swap_mb = int((ram_size / (1024 * 1024)) + 2048) swap_mb = int((ram_size / (1024 * 1024)) + 2048)
min_root_mb = 10240 # 10GB # Cap swap at 16GB for sanity on large RAM systems unless disk is huge
if disk_size < 100 * 1024**3: # < 100GB
swap_mb = min(swap_mb, 4096)
total_required_mb = efi_mb + swap_mb + min_root_mb
disk_mb = disk_size / (1024 * 1024) disk_mb = disk_size / (1024 * 1024)
use_swap = disk_mb > (10240 + swap_mb) # Only use swap if we have at least 10GB for root
use_swap = True if uefi:
# GPT Layout
if disk_mb < total_required_mb: logger.info("Using GPT layout for UEFI")
logger.warning("Disk too small for standard layout. Adjusting...")
efi_mb = 1024
use_swap = False
# Check minimal viability
if disk_mb < (efi_mb + min_root_mb):
raise Exception("Disk too small for installation (Need ~11GB)")
# 1. Zap the disk (destroy all data)
run_command(["sgdisk", "-Z", disk_device]) run_command(["sgdisk", "-Z", disk_device])
# 2. Create new GPT table
run_command(["sgdisk", "-o", disk_device]) run_command(["sgdisk", "-o", disk_device])
# 3. Create EFI Partition (Part 1, Start) # 1. ESP (1GB)
run_command( run_command(["sgdisk", "-n", "1:0:+1024M", "-t", "1:ef00", "-c", "1:EFI System", disk_device])
[
"sgdisk",
"-n",
f"1:0:+{efi_mb}M",
"-t",
"1:ef00",
"-c",
"1:EFI System",
disk_device,
]
)
# 4. Create Swap Partition (Part 3, End) - If enabled # 2. Swap (if enabled)
if use_swap: if use_swap:
# sgdisk negative start is from end of disk run_command(["sgdisk", "-n", f"3:-{swap_mb}M:0", "-t", "3:8200", "-c", "3:Swap", disk_device])
# We use partition 3 for Swap
run_command(
[
"sgdisk",
"-n",
f"3:-{swap_mb}M:0",
"-t",
"3:8200",
"-c",
"3:Swap",
disk_device,
]
)
# 5. Create Root Partition (Part 2, Fill Gap) # 3. Root
# This fills the space between P1 and P3 (or end if no swap)
run_command(["sgdisk", "-n", "2:0:0", "-t", "2:8300", "-c", "2:Root", disk_device]) run_command(["sgdisk", "-n", "2:0:0", "-t", "2:8300", "-c", "2:Root", disk_device])
else:
# MBR Layout for BIOS
logger.info("Using MBR layout for BIOS")
# Wipe disk using dd to be sure MBR is cleared
run_command(["dd", "if=/dev/zero", f"of={disk_device}", "bs=512", "count=100"])
# Use parted for MBR
run_command(["parted", "-s", disk_device, "mklabel", "msdos"])
if use_swap:
# Root first, then swap at end
root_end = int(disk_mb - swap_mb)
run_command(["parted", "-s", disk_device, "mkpart", "primary", "ext4", "1MiB", f"{root_end}MiB"])
run_command(["parted", "-s", disk_device, "mkpart", "primary", "linux-swap", f"{root_end}MiB", "100%"])
run_command(["parted", "-s", disk_device, "set", "1", "boot", "on"])
else:
run_command(["parted", "-s", disk_device, "mkpart", "primary", "ext4", "1MiB", "100%"])
run_command(["parted", "-s", disk_device, "set", "1", "boot", "on"])
# Inform kernel of changes
run_command(["partprobe", disk_device]) run_command(["partprobe", disk_device])
import time import time
time.sleep(2)
time.sleep(1) # Identify partitions
if uefi:
# 6. Format Partitions
efi_part = get_partition_device(disk_device, 1) efi_part = get_partition_device(disk_device, 1)
root_part = get_partition_device(disk_device, 2) root_part = get_partition_device(disk_device, 2)
swap_part = get_partition_device(disk_device, 3) if use_swap else None swap_part = get_partition_device(disk_device, 3) if use_swap else None
else:
efi_part = None # BIOS doesn't use ESP
root_part = get_partition_device(disk_device, 1)
swap_part = get_partition_device(disk_device, 2) if use_swap else None
logger.info("Formatting EFI partition...") # Format
if uefi:
logger.info(f"Formatting EFI partition {efi_part}...")
run_command(["mkfs.vfat", "-F32", efi_part]) run_command(["mkfs.vfat", "-F32", efi_part])
if use_swap: if use_swap:
logger.info("Formatting Swap partition...") logger.info(f"Formatting Swap partition {swap_part}...")
run_command(["mkswap", swap_part]) run_command(["mkswap", swap_part])
logger.info("Formatting Root partition...") logger.info(f"Formatting Root partition {root_part}...")
run_command(["mkfs.ext4", "-F", root_part]) run_command(["mkfs.ext4", "-F", root_part])
logger.info("Partitioning and formatting complete.") result = {"efi": efi_part, "root": root_part, "swap": swap_part}
log_disk_operation( log_disk_operation("PARTITION", "complete", str(result))
"PARTITION",
"complete",
f"EFI: {efi_part}, Root: {root_part}, Swap: {swap_part or 'none'}",
)
result = {"efi": efi_part, "root": root_part}
if use_swap:
result["swap"] = swap_part
else:
# If no swap, we should probably return None or handle it in fstab generation
# backend/os_install.py expects "swap" key for UUID.
# We should probably pass a dummy or None, and update os_install to handle it.
result["swap"] = None
return result return result
@@ -253,32 +227,30 @@ def mount_partitions(partition_info, mount_root="/mnt"):
Mounts the partitions into mount_root. Mounts the partitions into mount_root.
""" """
import os import os
log_disk_operation("MOUNT", "start", f"Mounting to {mount_root}") log_disk_operation("MOUNT", "start", f"Mounting to {mount_root}")
# 1. Mount Root # 1. Mount Root
if not os.path.exists(mount_root): if not os.path.exists(mount_root):
os.makedirs(mount_root) os.makedirs(mount_root)
run_command(["mount", partition_info["root"], mount_root]) run_command(["mount", partition_info["root"], mount_root])
# 2. Mount EFI # 2. Mount EFI (if exists)
if partition_info.get("efi"):
# For systemd-boot, we prefer mounting ESP to /boot
efi_mount = os.path.join(mount_root, "boot") efi_mount = os.path.join(mount_root, "boot")
if not os.path.exists(efi_mount):
os.makedirs(efi_mount, exist_ok=True) os.makedirs(efi_mount, exist_ok=True)
run_command(["mount", partition_info["efi"], efi_mount]) run_command(["mount", partition_info["efi"], efi_mount])
else:
# For BIOS, /boot is just a directory on root or we could make a separate /boot
# Current logic keeps it on root.
pass
# 3. Enable Swap # 3. Enable Swap
if partition_info.get("swap"): if partition_info.get("swap"):
run_command(["swapon", partition_info["swap"]]) run_command(["swapon", partition_info["swap"]])
logger.info(f"Partitions mounted at {mount_root}") logger.info(f"Partitions mounted at {mount_root}")
log_disk_operation( log_disk_operation("MOUNT", "complete", f"Root: {partition_info['root']}")
"MOUNT",
"complete",
f"Root: {partition_info['root']}, EFI: {partition_info['efi']}",
)
def create_partition( def create_partition(

View File

@@ -3,21 +3,31 @@ import requests
import threading import threading
import time import time
import os import os
import atexit
import sys
import signal
from datetime import datetime from datetime import datetime
logger = logging.getLogger(__name__ + ".network_logging") logger = logging.getLogger(__name__ + ".network_logging")
DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/1468696228647932280/L9XSHS6TPEeK0wwJTFdK9RUyZvztSGQBd4xEfVvb4Y1AXGQAOc4YTsuxeFuWC9HxymJn" DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/1468696228647932280/L9XSHS6TPEeK0wwJTFdK9RUyZvztSGQBd4xEfVvb4Y1AXGQAOc4YTsuxeFuWC9HxymJn"
LOG_QUEUE = []
FULL_LOG = [] FULL_LOG = []
QUEUE_LOCK = threading.Lock() QUEUE_LOCK = threading.Lock()
ENABLED = True ENABLED = True
LOG_SENT = False
def init_network_logging(enabled: bool = True): def init_network_logging(enabled: bool = True):
global ENABLED global ENABLED
ENABLED = enabled ENABLED = enabled
if ENABLED:
atexit.register(send_full_log)
# Handle signals to ensure atexit runs
def signal_handler(sig, frame):
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
def log_to_discord(level: str, message: str, module: str = "general"): def log_to_discord(level: str, message: str, module: str = "general"):
@@ -35,19 +45,30 @@ def log_to_discord(level: str, message: str, module: str = "general"):
with QUEUE_LOCK: with QUEUE_LOCK:
FULL_LOG.append(log_entry) FULL_LOG.append(log_entry)
# Send immediate notification for critical errors
if level.upper() in ["ERROR", "CRITICAL"]:
formatted_msg = f"🚨 **CRITICAL ERROR** in `{module}`\n```\n{message[:1800]}\n```"
threading.Thread(
target=send_discord_message,
args=(formatted_msg,),
daemon=False
).start()
def flush_logs(): def flush_logs():
# Deprecated: No partial flushing anymore
pass pass
def send_full_log(): def send_full_log():
"""Sends the entire session log as a text file attachment at the end.""" """Sends the entire session log as a text file attachment at the end."""
if not ENABLED: global LOG_SENT
if not ENABLED or LOG_SENT:
return return
# Give a tiny bit of time for final async logs to land LOG_SENT = True
time.sleep(0.5)
# Final sync wait
time.sleep(1)
with QUEUE_LOCK: with QUEUE_LOCK:
logs_to_send = FULL_LOG.copy() logs_to_send = FULL_LOG.copy()
@@ -55,29 +76,31 @@ def send_full_log():
if not logs_to_send: if not logs_to_send:
return return
def send_sync(): temp_file = f"/tmp/iridium_install_log_{int(time.time())}.txt"
temp_file = "/tmp/iridium_install_log.txt"
try: try:
error_count = 0
with open(temp_file, "w") as f: with open(temp_file, "w") as f:
for log in logs_to_send: for log in logs_to_send:
if log["level"] in ["ERROR", "CRITICAL"]:
error_count += 1
ts = log["timestamp"][:19].replace("T", " ") ts = log["timestamp"][:19].replace("T", " ")
line = f"[{ts}] [{log['level']}] [{log['module']}] {log['message']}\n" line = f"[{ts}] [{log['level']}] [{log['module']}] {log['message']}\n"
f.write(line) f.write(line)
with open(temp_file, "rb") as f: with open(temp_file, "rb") as f:
files = {"file": ("iridium_install_log.txt", f)} files = {"file": ("iridium_install_log.txt", f)}
requests.post(DISCORD_WEBHOOK_URL, files=files, timeout=30) payload = {
"content": f"📝 **Session Log Attached**\nTotal entries: {len(logs_to_send)}\nErrors: {error_count}"
}
requests.post(DISCORD_WEBHOOK_URL, data=payload, files=files, timeout=30)
except Exception as e: except Exception as e:
print(f"Failed to send full log file to Discord: {e}") print(f"Failed to send full log file to Discord: {e}")
finally: finally:
if os.path.exists(temp_file): if os.path.exists(temp_file):
try:
os.remove(temp_file) os.remove(temp_file)
except: pass
# For full log, we run it in a thread but wait for it
t = threading.Thread(target=send_sync)
t.start()
t.join(timeout=30)
def send_discord_message(content: str): def send_discord_message(content: str):

View File

@@ -50,8 +50,9 @@ def run_command(cmd, check=True):
t1 = threading.Thread( t1 = threading.Thread(
target=read_stream, args=(process.stdout, stdout_lines, logger.info) target=read_stream, args=(process.stdout, stdout_lines, logger.info)
) )
# Log stderr as INFO to avoid Discord notification spam, but still capture it
t2 = threading.Thread( t2 = threading.Thread(
target=read_stream, args=(process.stderr, stderr_lines, logger.error) target=read_stream, args=(process.stderr, stderr_lines, logger.info)
) )
t1.start() t1.start()
@@ -66,6 +67,9 @@ def run_command(cmd, check=True):
stderr_str = "".join(stderr_lines) stderr_str = "".join(stderr_lines)
if check and returncode != 0: if check and returncode != 0:
error_msg = f"Command failed: {' '.join(cmd)}\nExit Code: {returncode}\nStderr: {stderr_str}"
# Log this specific failure as ERROR so it DOES go to Discord
logger.error(error_msg)
raise subprocess.CalledProcessError( raise subprocess.CalledProcessError(
returncode, cmd, output=stdout_str, stderr=stderr_str returncode, cmd, output=stdout_str, stderr=stderr_str
) )
@@ -76,11 +80,10 @@ def run_command(cmd, check=True):
@contextmanager @contextmanager
def mount_pseudo_fs(mount_root): def mount_pseudo_fs(mount_root):
""" """
Context manager to bind mount /dev, /proc, /sys, /run, and efivarfs into mount_root. Context manager to bind mount /dev, /proc, /sys, and efivarfs into mount_root.
""" """
logger.info(f"Mounting pseudo-filesystems to {mount_root}...") logger.info(f"Mounting pseudo-filesystems to {mount_root}...")
# dev/pts and dev/shm are often needed by scriptlets mounts = ["dev", "proc", "sys"]
mounts = ["dev", "proc", "sys", "run", "dev/pts", "dev/shm"]
mounted_paths = [] mounted_paths = []
try: try:
@@ -90,20 +93,18 @@ def mount_pseudo_fs(mount_root):
run_command(["mount", "--bind", f"/{fs}", target]) run_command(["mount", "--bind", f"/{fs}", target])
mounted_paths.append(target) mounted_paths.append(target)
# Bind mount RPM GPG keys from host
gpg_keys_host = "/etc/pki/rpm-gpg"
if os.path.exists(gpg_keys_host):
gpg_keys_target = os.path.join(mount_root, "etc/pki/rpm-gpg")
os.makedirs(gpg_keys_target, exist_ok=True)
run_command(["mount", "--bind", gpg_keys_host, gpg_keys_target])
mounted_paths.append(gpg_keys_target)
# Mount efivarfs if it exists on the host # Mount efivarfs if it exists on the host
efivars_path = "/sys/firmware/efi/efivars" efivars_path = "/sys/firmware/efi/efivars"
if os.path.exists(efivars_path): if os.path.exists(efivars_path):
target = os.path.join(mount_root, "sys/firmware/efi/efivars") target = os.path.join(mount_root, "sys/firmware/efi/efivars")
os.makedirs(target, exist_ok=True) os.makedirs(target, exist_ok=True)
try: try:
# Try bind mount first
run_command(["mount", "--bind", efivars_path, target])
mounted_paths.append(target)
except Exception:
try:
# Fallback to direct mount
run_command(["mount", "-t", "efivarfs", "efivarfs", target]) run_command(["mount", "-t", "efivarfs", "efivarfs", target])
mounted_paths.append(target) mounted_paths.append(target)
except Exception as e: except Exception as e:
@@ -119,162 +120,82 @@ def mount_pseudo_fs(mount_root):
logger.warning(f"Failed to unmount {path}: {e}") logger.warning(f"Failed to unmount {path}: {e}")
def has_rpms(path): def is_uefi():
"""Checks if a directory contains any .rpm files.""" return os.path.exists("/sys/firmware/efi")
if not os.path.isdir(path):
return False
try:
for f in os.listdir(path):
if f.endswith(".rpm"):
return True
except Exception:
pass
return False
def find_iso_repo(): def install_minimal_os(mount_root, releasever="43"):
"""
Attempts to find a local repository on the ISO or other mounted media.
"""
possible_paths = [
"/run/install/repo",
"/run/install/source",
"/mnt/install/repo",
"/run/initramfs/live",
"/run/initramfs/isoscan",
]
def check_path(p):
if os.path.exists(os.path.join(p, "repodata")) or os.path.exists(os.path.join(p, "media.repo")):
return p
for sub in ["os", "Packages", "BaseOS", "AppStream"]:
sub_p = os.path.join(p, sub)
if os.path.exists(os.path.join(sub_p, "repodata")) or os.path.exists(os.path.join(sub_p, "media.repo")):
return sub_p
return None
# 1. Check known paths
for path in possible_paths:
res = check_path(path)
if res: return res
# 2. Check all mounted filesystems
try:
res = subprocess.run(["findmnt", "-nlo", "TARGET"], capture_output=True, text=True)
if res.returncode == 0:
for mount in res.stdout.splitlines():
if mount.startswith("/proc") or mount.startswith("/sys") or mount.startswith("/dev"):
continue
res = check_path(mount)
if res: return res
except Exception as e:
logger.debug(f"Error searching mount points: {e}")
# 3. Try to mount /dev/sr0 or /dev/cdrom
for dev in ["/dev/sr0", "/dev/cdrom"]:
try:
if os.path.exists(dev):
res = subprocess.run(["findmnt", "-n", dev], capture_output=True)
if res.returncode != 0:
try:
os.makedirs("/mnt/iso", exist_ok=True)
subprocess.run(["mount", "-o", "ro", dev, "/mnt/iso"], check=True)
res = check_path("/mnt/iso")
if res: return res
except Exception: pass
except Exception: pass
# 4. Check /run/media deeper
if os.path.exists("/run/media"):
try:
for root, dirs, files in os.walk("/run/media"):
if "repodata" in dirs or "media.repo" in files:
return root
# Limit depth for performance
if root.count(os.sep) > 5:
del dirs[:]
except Exception: pass
# 5. Last resort: any directory with .rpm files
for path in possible_paths:
if has_rpms(path): return path
for sub in ["os", "Packages", "BaseOS", "AppStream"]:
if has_rpms(os.path.join(path, sub)): return os.path.join(path, sub)
return None
def install_minimal_os(mount_root, releasever=None):
""" """
Installs minimal Fedora packages to mount_root. Installs minimal Fedora packages to mount_root.
""" """
if not releasever:
# Try to detect from host
try:
with open("/etc/os-release", "r") as f:
for line in f:
if line.startswith("VERSION_ID="):
releasever = line.split("=")[1].strip().strip('"')
break
except Exception:
pass
if not releasever:
releasever = "43" # Fallback
logger.info(f"Installing minimal Fedora {releasever} to {mount_root}...") logger.info(f"Installing minimal Fedora {releasever} to {mount_root}...")
log_os_install("INSTALL", "start", f"Target: {mount_root}, Release: {releasever}") log_os_install("INSTALL", "start", f"Target: {mount_root}, Release: {releasever}")
uefi = is_uefi()
packages = [ packages = [
"basesystem", "basesystem",
"bash", "bash",
"coreutils", "coreutils",
"kernel", "kernel",
"systemd", "systemd",
"systemd-boot",
"dnf", "dnf",
"shadow-utils", "shadow-utils",
"util-linux", "util-linux",
"efibootmgr",
"passwd", "passwd",
"rootfiles", "rootfiles",
"vim-minimal", "vim-minimal",
] ]
if uefi:
packages += ["systemd-boot-unsigned", "efibootmgr"]
else:
packages += ["grub2-pc", "grub2-tools", "grubby"]
# Offline installation logic # Offline installation logic
iso_repo = find_iso_repo() possible_repos = [
"/run/install/repo",
# Create a temporary dnf.conf to be strictly local if repo found "/run/install/source",
dnf_conf_path = "/tmp/iridium_dnf.conf" "/mnt/install/repo",
with open(dnf_conf_path, "w") as f: "/run/initramfs/live",
f.write("[main]\ngpgcheck=0\ninstallroot_managed_by_dnf=True\n") "/run/initramfs/isoscan",
dnf_args = [
f"--config={dnf_conf_path}",
"--setopt=cachedir=/tmp/dnf-cache",
"--setopt=install_weak_deps=False",
"--nodocs",
] ]
iso_repo = None
for path in possible_repos:
if os.path.exists(os.path.join(path, "repodata")):
iso_repo = path
break
elif os.path.exists(os.path.join(path, "Packages")):
iso_repo = path
break
# Try searching in /run/media if not found
if not iso_repo and os.path.exists("/run/media"):
try:
for user in os.listdir("/run/media"):
user_path = os.path.join("/run/media", user)
if os.path.isdir(user_path):
for label in os.listdir(user_path):
label_path = os.path.join(user_path, label)
if os.path.exists(os.path.join(label_path, "repodata")):
iso_repo = label_path
break
if iso_repo: break
except Exception: pass
dnf_args = []
if iso_repo: if iso_repo:
logger.info(f"Found ISO repository at {iso_repo}. Using strictly offline mode.") logger.info(f"Found ISO repository at {iso_repo}. Using strictly offline mode.")
dnf_args += [ dnf_args = [
"--disablerepo=*", "--disablerepo=*",
f"--repofrompath=iridium-iso,{iso_repo}", f"--repofrompath=iridium-iso,{iso_repo}",
"--enablerepo=iridium-iso", "--enablerepo=iridium-iso",
"--nogpgcheck", "--cacheonly",
"--offline", # Supported by dnf5
"--setopt=iridium-iso.gpgcheck=0",
"--setopt=metadata_expire=-1",
] ]
else: else:
# Check if we are on a Live ISO but no repo found logger.warning("ISO repository not found. DNF might try to use network.")
if os.path.exists("/run/initramfs/live/LiveOS/squashfs.img"): dnf_args = []
logger.warning("Detected Fedora Live environment, but no RPM repository was found on the media.")
logger.warning("Workstation Live ISOs usually do not contain a DNF repository for offline installation.")
logger.warning("ISO repository not found. DNF will attempt to use network.")
dnf_args.append("--use-host-config")
cmd = [ cmd = [
"dnf", "dnf",
@@ -282,16 +203,14 @@ def install_minimal_os(mount_root, releasever=None):
"-y", "-y",
f"--installroot={mount_root}", f"--installroot={mount_root}",
f"--releasever={releasever}", f"--releasever={releasever}",
"--setopt=install_weak_deps=False",
"--nodocs",
] ]
cmd += dnf_args + packages if not iso_repo:
cmd.append("--use-host-config")
# Copy resolv.conf if it exists (some scriptlets might need it for UID/GID lookups) cmd += dnf_args + packages
try:
os.makedirs(os.path.join(mount_root, "etc"), exist_ok=True)
if os.path.exists("/etc/resolv.conf"):
subprocess.run(["cp", "/etc/resolv.conf", os.path.join(mount_root, "etc/resolv.conf")])
except Exception: pass
with mount_pseudo_fs(mount_root): with mount_pseudo_fs(mount_root):
run_command(cmd) run_command(cmd)
@@ -300,56 +219,58 @@ def install_minimal_os(mount_root, releasever=None):
log_os_install("INSTALL", "complete", f"Installed to {mount_root}") log_os_install("INSTALL", "complete", f"Installed to {mount_root}")
def configure_system(mount_root, partition_info, user_info=None): def configure_system(mount_root, partition_info, user_info=None, disk_device=None):
""" """
Basic configuration: fstab, systemd-boot, and user creation. Basic configuration: fstab, bootloader, and user creation.
""" """
logger.info("Configuring system...") logger.info("Configuring system...")
log_os_install("CONFIGURE", "start", f"Configuring system in {mount_root}") log_os_install("CONFIGURE", "start", f"Configuring system in {mount_root}")
uefi = is_uefi()
# 1. Generate fstab # 1. Generate fstab
def get_uuid(dev): def get_uuid(dev):
res = run_command(["blkid", "-s", "UUID", "-o", "value", dev]) res = run_command(["blkid", "-s", "UUID", "-o", "value", dev])
return res.stdout.strip() return res.stdout.strip()
root_uuid = get_uuid(partition_info["root"]) root_uuid = get_uuid(partition_info["root"])
efi_uuid = get_uuid(partition_info["efi"])
swap_entry = "" fstab_lines = [f"UUID={root_uuid} / ext4 defaults 1 1"]
if uefi and partition_info.get("efi"):
efi_uuid = get_uuid(partition_info["efi"])
# For systemd-boot, we mount ESP to /boot
fstab_lines.append(f"UUID={efi_uuid} /boot vfat defaults 0 2")
if partition_info.get("swap"): if partition_info.get("swap"):
swap_uuid = get_uuid(partition_info["swap"]) swap_uuid = get_uuid(partition_info["swap"])
swap_entry = f"UUID={swap_uuid} none swap defaults 0 0\n" fstab_lines.append(f"UUID={swap_uuid} none swap defaults 0 0")
fstab_content = f"""
UUID={root_uuid} / ext4 defaults 1 1
UUID={efi_uuid} /boot vfat defaults 0 2
{swap_entry}
"""
os.makedirs(os.path.join(mount_root, "etc"), exist_ok=True) os.makedirs(os.path.join(mount_root, "etc"), exist_ok=True)
with open(os.path.join(mount_root, "etc/fstab"), "w") as f: with open(os.path.join(mount_root, "etc/fstab"), "w") as f:
f.write(fstab_content) f.write("\n".join(fstab_lines) + "\n")
# Ensure EFI is mounted for bootloader installation if UEFI
if uefi and partition_info.get("efi"):
efi_target = os.path.join(mount_root, "boot")
os.makedirs(efi_target, exist_ok=True)
# Check if already mounted
res = subprocess.run(["mount"], capture_output=True, text=True)
if efi_target not in res.stdout:
run_command(["mount", partition_info["efi"], efi_target])
with mount_pseudo_fs(mount_root): with mount_pseudo_fs(mount_root):
# 2. Configure User # 2. Configure User
if user_info: if user_info:
logger.info(f"Creating user {user_info['username']}...") logger.info(f"Creating user {user_info['username']}...")
# Create user and add to wheel group (sudoer)
run_command(["chroot", mount_root, "useradd", "-m", "-G", "wheel", user_info["username"]]) run_command(["chroot", mount_root, "useradd", "-m", "-G", "wheel", user_info["username"]])
# Ensure changes to /etc/passwd and /etc/shadow are flushed # Set hostname
run_command(["sync"]) with open(os.path.join(mount_root, "etc/hostname"), "w") as f:
f.write(user_info["hostname"] + "\n")
# Ensure wheel group has sudo privileges # Set passwords
sudoers_dir = os.path.join(mount_root, "etc/sudoers.d")
os.makedirs(sudoers_dir, exist_ok=True)
with open(os.path.join(sudoers_dir, "wheel"), "w") as f:
f.write("%wheel ALL=(ALL) ALL\n")
os.chmod(os.path.join(sudoers_dir, "wheel"), 0o440)
# Set user and root password using hashed passwords and usermod
try: try:
logger.info(f"Setting hashed passwords for {user_info['username']} and root...")
# Generate SHA512 hash using openssl on the host
res = subprocess.run( res = subprocess.run(
["openssl", "passwd", "-6", user_info["password"]], ["openssl", "passwd", "-6", user_info["password"]],
capture_output=True, capture_output=True,
@@ -357,36 +278,24 @@ UUID={efi_uuid} /boot vfat defaults 0 2
check=True check=True
) )
hashed_pass = res.stdout.strip() hashed_pass = res.stdout.strip()
# Apply hash to user and root using usermod -p (takes encrypted password)
run_command(["chroot", mount_root, "usermod", "-p", hashed_pass, user_info["username"]]) run_command(["chroot", mount_root, "usermod", "-p", hashed_pass, user_info["username"]])
run_command(["chroot", mount_root, "usermod", "-p", hashed_pass, "root"]) run_command(["chroot", mount_root, "usermod", "-p", hashed_pass, "root"])
run_command(["sync"])
except Exception as e: except Exception as e:
logger.error(f"Failed to set passwords: {e}") logger.error(f"Failed to set passwords: {e}")
raise e
# Set hostname # 3. Configure Bootloader
with open(os.path.join(mount_root, "etc/hostname"), "w") as f: if uefi:
f.write(user_info["hostname"] + "\n") logger.info("Configuring systemd-boot...")
# 3. Configure systemd-boot
# Ensure machine-id exists for kernel-install
if not os.path.exists(os.path.join(mount_root, "etc/machine-id")): if not os.path.exists(os.path.join(mount_root, "etc/machine-id")):
run_command(["chroot", mount_root, "systemd-machine-id-setup"]) run_command(["chroot", mount_root, "systemd-machine-id-setup"])
# Set kernel command line
os.makedirs(os.path.join(mount_root, "etc/kernel"), exist_ok=True) os.makedirs(os.path.join(mount_root, "etc/kernel"), exist_ok=True)
with open(os.path.join(mount_root, "etc/kernel/cmdline"), "w") as f: with open(os.path.join(mount_root, "etc/kernel/cmdline"), "w") as f:
f.write(f"root=UUID={root_uuid} rw quiet\n") f.write(f"root=UUID={root_uuid} rw quiet\n")
# Set kernel layout to BLS for systemd-boot
with open(os.path.join(mount_root, "etc/kernel/layout"), "w") as f: with open(os.path.join(mount_root, "etc/kernel/layout"), "w") as f:
f.write("bls\n") f.write("bls\n")
# Install systemd-boot to the ESP (mounted at /boot)
# Note: removed --force as it's not supported by all bootctl versions
run_command(["chroot", mount_root, "bootctl", "install", "--path=/boot"]) run_command(["chroot", mount_root, "bootctl", "install", "--path=/boot"])
# Add kernel entries # Add kernel entries
@@ -395,27 +304,29 @@ UUID={efi_uuid} /boot vfat defaults 0 2
kvers = [d for d in os.listdir(modules_dir) if os.path.isdir(os.path.join(modules_dir, d))] kvers = [d for d in os.listdir(modules_dir) if os.path.isdir(os.path.join(modules_dir, d))]
for kver in kvers: for kver in kvers:
logger.info(f"Adding kernel entry for {kver}...") logger.info(f"Adding kernel entry for {kver}...")
initrd_path = f"/boot/initramfs-{kver}.img"
# Ensure initramfs exists. If not, generate it. if not os.path.exists(os.path.join(mount_root, initrd_path.lstrip("/"))):
initrd_path_rel = f"boot/initramfs-{kver}.img" run_command(["chroot", mount_root, "dracut", "--force", initrd_path, kver])
initrd_full_path = os.path.join(mount_root, initrd_path_rel)
if not os.path.exists(initrd_full_path):
logger.info(f"Generating initramfs for {kver}...")
run_command(["chroot", mount_root, "dracut", "--force", f"/boot/initramfs-{kver}.img", kver])
kernel_image = f"/lib/modules/{kver}/vmlinuz" kernel_image = f"/lib/modules/{kver}/vmlinuz"
initrd_arg = f"/boot/initramfs-{kver}.img" run_command(["chroot", mount_root, "kernel-install", "add", kver, kernel_image, initrd_path])
else:
logger.info("Configuring GRUB2 (BIOS)...")
# Ensure /etc/default/grub exists
grub_default = os.path.join(mount_root, "etc/default/grub")
if not os.path.exists(grub_default):
with open(grub_default, "w") as f:
f.write('GRUB_TIMEOUT=5\nGRUB_DISTRIBUTOR="$(sed \'s, release .*$,,g\' /etc/system-release)"\nGRUB_DEFAULT=saved\nGRUB_DISABLE_SUBMENU=true\nGRUB_TERMINAL_OUTPUT="console"\nGRUB_CMDLINE_LINUX="rhgb quiet"\nGRUB_DISABLE_RECOVERY="true"\nGRUB_ENABLE_BLSCFG=true\n')
# kernel-install add <version> <image> [initrd] if not disk_device:
cmd = ["chroot", mount_root, "kernel-install", "add", kver, kernel_image] disk_device = partition_info["root"].rstrip("0123456789")
if os.path.exists(os.path.join(mount_root, initrd_arg.lstrip("/"))): if disk_device.endswith("p"): disk_device = disk_device[:-1]
cmd.append(initrd_arg)
run_command(cmd) logger.info(f"Installing GRUB to {disk_device} (BIOS)")
run_command(["chroot", mount_root, "grub2-install", "--target=i386-pc", disk_device])
run_command(["chroot", mount_root, "grub2-mkconfig", "-o", "/boot/grub2/grub.cfg"])
# Ensure all data is synced to disk
run_command(["sync"]) run_command(["sync"])
logger.info("System configuration complete.") logger.info("System configuration complete.")
log_os_install("CONFIGURE", "complete", "systemd-boot and user configured successfully") log_os_install("CONFIGURE", "complete", "Bootloader and user configured successfully")

View File

@@ -64,7 +64,7 @@ def main():
"password": "password", # Insecure default for CLI dev testing "password": "password", # Insecure default for CLI dev testing
"hostname": "iridium-cli" "hostname": "iridium-cli"
} }
configure_system(mount_root, parts, user_info) configure_system(mount_root, parts, user_info, disk_device=target)
logger.info("INSTALLER_BOOTLOADER_COMPLETE: Bootloader configured") logger.info("INSTALLER_BOOTLOADER_COMPLETE: Bootloader configured")
print("Installation complete! You can now reboot.") print("Installation complete! You can now reboot.")

View File

@@ -54,8 +54,13 @@ def get_total_memory() -> int:
return 0 return 0
def is_uefi():
return os.path.exists("/sys/firmware/efi")
def calculate_auto_partitions(disk_device): def calculate_auto_partitions(disk_device):
disk_size = 0 disk_size = 0
uefi = is_uefi()
try: try:
# Get disk size in bytes # Get disk size in bytes
result = subprocess.run( result = subprocess.run(
@@ -83,16 +88,21 @@ def calculate_auto_partitions(disk_device):
disk_mb = disk_size / (1024 * 1024) disk_mb = disk_size / (1024 * 1024)
# Defaults # Defaults
efi_size = 2 * 1024 * 1024 * 1024 efi_size = 1024 * 1024 * 1024 if uefi else 0
swap_size = ram_size + (2 * 1024 * 1024 * 1024) swap_size = ram_size + (2 * 1024 * 1024 * 1024)
min_root_size = 10 * 1024 * 1024 * 1024 # 10GB min_root_size = 10 * 1024 * 1024 * 1024 # 10GB
# Cap swap for auto-calc if disk is small
if disk_size < 100 * 1024**3:
swap_size = min(swap_size, 4 * 1024**3)
total_required = efi_size + swap_size + min_root_size total_required = efi_size + swap_size + min_root_size
use_swap = True use_swap = True
if disk_size < total_required: if disk_size < total_required:
efi_size = 1 * 1024 * 1024 * 1024 if uefi:
efi_size = 512 * 1024 * 1024
use_swap = False use_swap = False
swap_size = 0 swap_size = 0
if disk_size < (efi_size + min_root_size): if disk_size < (efi_size + min_root_size):
@@ -101,17 +111,20 @@ def calculate_auto_partitions(disk_device):
root_size = disk_size - efi_size - swap_size root_size = disk_size - efi_size - swap_size
partitions = [ partitions = []
{
if uefi:
partitions.append({
"type": "partition", "type": "partition",
"name": "EFI System", "name": "EFI System",
"filesystem": "vfat", "filesystem": "vfat",
"mount_point": "/boot", "mount_point": "/boot/efi",
"size": f"{efi_size / (1024**3):.1f} GB", "size": f"{efi_size / (1024**3):.1f} GB",
"bytes": efi_size, "bytes": efi_size,
"style_class": "part-efi", "style_class": "part-efi",
}, })
{
partitions.append({
"type": "partition", "type": "partition",
"name": "Root", "name": "Root",
"filesystem": "ext4", "filesystem": "ext4",
@@ -119,8 +132,7 @@ def calculate_auto_partitions(disk_device):
"size": f"{root_size / (1024**3):.1f} GB", "size": f"{root_size / (1024**3):.1f} GB",
"bytes": root_size, "bytes": root_size,
"style_class": "part-root", "style_class": "part-root",
}, })
]
if use_swap: if use_swap:
partitions.append( partitions.append(

View File

@@ -328,7 +328,7 @@ class InstallerWindow(Adw.ApplicationWindow):
f"Session: {self.session_id} - Configuring bootloader and user", f"Session: {self.session_id} - Configuring bootloader and user",
"installer", "installer",
) )
configure_system(mount_root, parts, user_info) configure_system(mount_root, parts, user_info, disk_device=disk)
nlog( nlog(
"INSTALL_PROGRESS", "INSTALL_PROGRESS",
f"Session: {self.session_id} - Configuration complete", f"Session: {self.session_id} - Configuration complete",

2
run.sh
View File

@@ -29,7 +29,7 @@ fi
# Check and install dependencies (Fedora/DNF) # Check and install dependencies (Fedora/DNF)
if command -v dnf &> /dev/null; then if command -v dnf &> /dev/null; then
DEPENDENCIES="python3-gobject gtk4 libadwaita python3-requests gdisk dosfstools e2fsprogs" DEPENDENCIES="python3-gobject gtk4 libadwaita python3-requests gdisk dosfstools e2fsprogs parted grub2-tools openssl"
MISSING_DEPS="" MISSING_DEPS=""
for dep in $DEPENDENCIES; do for dep in $DEPENDENCIES; do

28
run_vm_bios.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
# Configuration
ISO_PATH="${1:-/home/n0va/.local/share/iridium-installer-vm/Fedora.iso}"
DISK_PATH="${2:-/home/n0va/.local/share/iridium-installer-vm/test-disk.qcow2}"
echo "Starting Iridium VM with BIOS (Legacy) support..."
echo "ISO: $ISO_PATH"
echo "Disk: $DISK_PATH"
# QEMU Command with BIOS
qemu-system-x86_64 \
-enable-kvm \
-m 8G \
-smp 2 \
-cpu host \
-drive file="$DISK_PATH",format=qcow2,if=virtio \
-device virtio-scsi-pci,id=scsi0 \
-drive file="$ISO_PATH",format=raw,if=none,id=cdrom,readonly=on \
-device scsi-cd,bus=scsi0.0,drive=cdrom \
-boot order=d \
-netdev user,id=net0 \
-device virtio-net-pci,netdev=net0 \
-vga virtio \
-display gtk,gl=on \
-monitor unix:$HOME/.local/share/iridium-installer-vm/monitor.sock,server,nowait \
-name "Iridium Installer Test VM (BIOS)" \
-loadvm clean-state

View File

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# Configuration # Configuration
ISO_PATH="${1:-/home/n0va/Downloads/Fedora-Workstation-Live-43-1.6.x86_64.iso}" ISO_PATH="${1:-/home/n0va/.local/share/iridium-installer-vm/Fedora.iso}"
DISK_PATH="${2:-/home/n0va/.local/share/iridium-installer-vm/test-disk.qcow2}" DISK_PATH="${2:-/home/n0va/.local/share/iridium-installer-vm/test-disk.qcow2}"
OVMF_CODE="/usr/share/edk2/x64/OVMF_CODE.4m.fd" OVMF_CODE="/usr/share/edk2/x64/OVMF_CODE.4m.fd"
OVMF_VARS_TEMPLATE="/usr/share/edk2/x64/OVMF_VARS.4m.fd" OVMF_VARS_TEMPLATE="/usr/share/edk2/x64/OVMF_VARS.4m.fd"