Fix: ensure disk is unmounted before partitioning and use sudo for reboot

This commit is contained in:
2026-02-05 14:55:18 +01:00
parent 45b0fa5a84
commit 3a226108ec
2 changed files with 36 additions and 1 deletions

View File

@@ -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()

View File

@@ -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()