Fix PyInstaller frozen binary system command execution

- Modified mount_target and partition_disk methods to use shell=True subprocess calls
- This bypasses PyInstaller library conflicts by running commands in separate shell processes
- Mount command now uses shell execution: 'mount /dev/sda1 /target'
- Partition commands (parted, mkfs.ext4) also use shell execution to avoid library issues
- Added proper error handling with stderr capture for shell commands
- Added time import for sleep functionality in partition_disk
- Ensures frozen binary can execute system commands without library version conflicts

This resolves the persistent mount error in PyInstaller frozen binary by
executing system commands through shell subprocess instead of direct calls.
parent b05c1e20
...@@ -9,6 +9,7 @@ import os ...@@ -9,6 +9,7 @@ import os
import subprocess import subprocess
import threading import threading
import re import re
import time
from pathlib import Path from pathlib import Path
from datetime import datetime from datetime import datetime
import glob import glob
...@@ -567,15 +568,42 @@ class InstallerWorker(QThread): ...@@ -567,15 +568,42 @@ class InstallerWorker(QThread):
return "/cdrom/preseed.cfg" # Placeholder return "/cdrom/preseed.cfg" # Placeholder
def partition_disk(self, target_disk): def partition_disk(self, target_disk):
# Run parted and mkfs commands via subprocess # Run parted and mkfs commands via shell subprocess to avoid library conflicts
cmd = ['parted', '-s', target_disk, 'mklabel', 'msdos'] parted_cmd = f'parted -s {target_disk} mklabel msdos'
subprocess.run(cmd, check=True) result = subprocess.run(parted_cmd, shell=True, capture_output=True, text=True)
# Add more commands... if result.returncode != 0:
raise Exception(f"Parted failed: {result.stderr}")
parted_cmd = f'parted -s {target_disk} mkpart primary ext4 1MiB 100%'
result = subprocess.run(parted_cmd, shell=True, capture_output=True, text=True)
if result.returncode != 0:
raise Exception(f"Parted mkpart failed: {result.stderr}")
parted_cmd = f'parted -s {target_disk} set 1 boot on'
result = subprocess.run(parted_cmd, shell=True, capture_output=True, text=True)
if result.returncode != 0:
raise Exception(f"Parted set boot failed: {result.stderr}")
# Wait for kernel to recognize partitions
time.sleep(2)
partprobe_cmd = f'partprobe {target_disk}'
subprocess.run(partprobe_cmd, shell=True)
# Format partition
mkfs_cmd = f'mkfs.ext4 -F {target_disk}1 -L "root"'
result = subprocess.run(mkfs_cmd, shell=True, capture_output=True, text=True)
if result.returncode != 0:
raise Exception(f"Mkfs failed: {result.stderr}")
self.log("Disk partitioned") self.log("Disk partitioned")
def mount_target(self, target_disk, target_mount): def mount_target(self, target_disk, target_mount):
os.makedirs(target_mount, exist_ok=True) os.makedirs(target_mount, exist_ok=True)
subprocess.run(['mount', f'{target_disk}1', target_mount], check=True) # Use shell subprocess to avoid PyInstaller library conflicts
mount_cmd = f'mount {target_disk}1 {target_mount}'
result = subprocess.run(mount_cmd, shell=True, capture_output=True, text=True)
if result.returncode != 0:
raise Exception(f"Mount failed: {result.stderr}")
self.log("Target mounted") self.log("Target mounted")
def copy_live_system(self, target_mount): def copy_live_system(self, target_mount):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment