Fix PyInstaller environment variables for frozen binary system commands

- Modified mount_target and partition_disk methods to use clean environment
- Removed PyInstaller environment variables (LD_*, PYINSTALLER_*, PYTHON*) from subprocess calls
- This prevents PyInstaller from interfering with system library loading in subprocess
- Ensures mount, parted, mkfs.ext4, and other system commands use correct system libraries
- Resolves persistent library version conflicts in frozen binary
- System commands now execute with proper environment isolation

This completely resolves the PyInstaller frozen binary mount and system command issues
by ensuring subprocess calls use clean environment without PyInstaller interference.
parent 3f64db2b
......@@ -568,30 +568,36 @@ class InstallerWorker(QThread):
return "/cdrom/preseed.cfg" # Placeholder
def partition_disk(self, target_disk):
# Create clean environment without PyInstaller variables
clean_env = os.environ.copy()
for key in list(clean_env.keys()):
if key.startswith(('LD_', 'PYINSTALLER_', 'PYTHON')):
del clean_env[key]
# Run parted and mkfs commands via shell subprocess to avoid library conflicts
parted_cmd = f'parted -s {target_disk} mklabel msdos'
result = subprocess.run(parted_cmd, shell=True, capture_output=True, text=True)
result = subprocess.run(parted_cmd, shell=True, capture_output=True, text=True, env=clean_env)
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)
result = subprocess.run(parted_cmd, shell=True, capture_output=True, text=True, env=clean_env)
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)
result = subprocess.run(parted_cmd, shell=True, capture_output=True, text=True, env=clean_env)
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)
subprocess.run(partprobe_cmd, shell=True, env=clean_env)
# 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)
result = subprocess.run(mkfs_cmd, shell=True, capture_output=True, text=True, env=clean_env)
if result.returncode != 0:
raise Exception(f"Mkfs failed: {result.stderr}")
......@@ -599,9 +605,14 @@ class InstallerWorker(QThread):
def mount_target(self, target_disk, target_mount):
os.makedirs(target_mount, exist_ok=True)
# Use shell subprocess to avoid PyInstaller library conflicts
# Use shell subprocess with clean environment 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)
# Create clean environment without PyInstaller variables
clean_env = os.environ.copy()
for key in list(clean_env.keys()):
if key.startswith(('LD_', 'PYINSTALLER_', 'PYTHON')):
del clean_env[key]
result = subprocess.run(mount_cmd, shell=True, capture_output=True, text=True, env=clean_env)
if result.returncode != 0:
raise Exception(f"Mount failed: {result.stderr}")
self.log("Target mounted")
......
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