From 3a226108ec3d645100082c18142a66fd2e7493fb Mon Sep 17 00:00:00 2001 From: N0VA Date: Thu, 5 Feb 2026 14:55:18 +0100 Subject: [PATCH] Fix: ensure disk is unmounted before partitioning and use sudo for reboot --- iridium_installer/backend/disk.py | 34 +++++++++++++++++++++++++++++++ iridium_installer/ui/window.py | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/iridium_installer/backend/disk.py b/iridium_installer/backend/disk.py index bf61819..a0e9575 100644 --- a/iridium_installer/backend/disk.py +++ b/iridium_installer/backend/disk.py @@ -97,6 +97,37 @@ def get_disk_size(disk_device): return 0 +def ensure_unmounted(disk_device): + """ + Finds all mounted partitions belonging to disk_device and unmounts them. + """ + logger.info(f"Ensuring all partitions on {disk_device} are unmounted...") + try: + # Get all partitions for this disk from lsblk + res = run_command(["lsblk", "-nlo", "NAME,MOUNTPOINT", disk_device]) + for line in res.stdout.splitlines(): + parts = line.split() + if len(parts) >= 2: + # NAME is usually the leaf name (e.g. vda1), we need full path + # But lsblk -lp gives full paths + pass + + # Simpler approach: findmnt or just look at /proc/mounts + # Let's use lsblk -lp to get full paths + res = run_command(["lsblk", "-lpno", "NAME,MOUNTPOINT", disk_device]) + for line in res.stdout.splitlines(): + # line looks like "/dev/vda1 /mnt/boot" or "/dev/vda1" + parts = line.split() + if len(parts) >= 2: + dev_path = parts[0] + mount_point = parts[1] + if mount_point and mount_point != "None": + logger.info(f"Unmounting {dev_path} from {mount_point}...") + run_command(["umount", "-l", dev_path]) + except Exception as e: + logger.warning(f"Error during pre-partition unmount: {e}") + + def auto_partition_disk(disk_device): """ Automatically partitions the disk: @@ -109,6 +140,9 @@ def auto_partition_disk(disk_device): logger.info(f"Starting auto-partitioning on {disk_device}") log_disk_operation("PARTITION", "start", f"Disk: {disk_device}") + # 0. Ensure unmounted + ensure_unmounted(disk_device) + # Calculate sizes disk_size = get_disk_size(disk_device) ram_size = get_total_memory() diff --git a/iridium_installer/ui/window.py b/iridium_installer/ui/window.py index 21848aa..cdbff1b 100644 --- a/iridium_installer/ui/window.py +++ b/iridium_installer/ui/window.py @@ -247,7 +247,8 @@ class InstallerWindow(Adw.ApplicationWindow): def on_restart(b): import subprocess try: - subprocess.run(["systemctl", "reboot"]) + # Use sudo since we might be running as liveuser + subprocess.run(["sudo", "systemctl", "reboot"]) except Exception as e: print(f"Failed to reboot: {e}") self.close()