Fix GRUB installation timing and environment variable issues

- Move GRUB installation to occur BEFORE unmounting target filesystem
- Install GRUB inside configure_target_system method before cleanup
- Ensure all mount/umount operations use clean environment variables
- Specifically empty LD_PRELOAD variable to prevent PyInstaller interference
- Update partition_disk, mount_target, and install_bootloader methods
- Remove duplicate GRUB installation call from main run method

This ensures GRUB can access the mounted target filesystem and prevents
PyInstaller environment variables from interfering with system calls.
parent 46fa1122
......@@ -486,10 +486,7 @@ class InstallerWorker(QThread):
self.progress_updated.emit(90)
# Step 10: Install Bootloader (95%)
self.status_updated.emit("Installing bootloader...")
self.install_bootloader(target_mount, target_disk)
self.step_completed.emit("Bootloader installed")
# Step 10: Bootloader installation moved to configure_target_system (before unmount)
self.progress_updated.emit(95)
......@@ -696,6 +693,8 @@ class InstallerWorker(QThread):
# Wait for kernel to recognize partitions
time.sleep(2)
partprobe_cmd = f'partprobe {target_disk}'
# Use clean environment for partprobe as well
clean_env = self._clean_env()
subprocess.run(partprobe_cmd, shell=True, env=clean_env)
# Format partition
......@@ -719,6 +718,8 @@ class InstallerWorker(QThread):
del clean_env[key]
try:
# Use clean environment for mount operations (remove PyInstaller variables)
clean_env = self._clean_env()
result = subprocess.run(mount_cmd, shell=True, capture_output=True, text=True, env=clean_env, check=True)
self.log("Target mounted successfully")
except subprocess.CalledProcessError as e:
......@@ -984,7 +985,9 @@ class InstallerWorker(QThread):
for cmd, description in mount_operations:
try:
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
# Use clean environment for mount operations (remove PyInstaller variables)
clean_env = self._clean_env()
result = subprocess.run(cmd, capture_output=True, text=True, check=True, env=clean_env)
self.log(f"Successfully mounted {description}")
except subprocess.CalledProcessError as e:
# Check if already mounted (common in live systems)
......@@ -1051,6 +1054,15 @@ class InstallerWorker(QThread):
# Configure NTP
self._configure_ntp(target_mount)
# Install GRUB bootloader BEFORE unmounting (moved from main run method)
self.log("Installing GRUB bootloader...")
try:
self.install_bootloader(target_mount, self.config['target_disk'])
self.log("GRUB bootloader installed successfully")
except Exception as e:
self.log(f"Warning: GRUB installation failed: {str(e)}")
# Continue with installation despite GRUB failure
# Clean up bind mounts
self.log("Cleaning up bind mounts")
......@@ -1064,7 +1076,9 @@ class InstallerWorker(QThread):
for mount_point in unmount_operations:
try:
result = subprocess.run(['umount', mount_point], capture_output=True, text=True, check=True)
# Use clean environment for unmount operations (remove PyInstaller variables)
clean_env = self._clean_env()
result = subprocess.run(['umount', mount_point], capture_output=True, text=True, check=True, env=clean_env)
self.log(f"Successfully unmounted {mount_point}")
except subprocess.CalledProcessError as e:
# Check if not mounted (common if mount failed earlier)
......@@ -1190,12 +1204,15 @@ class InstallerWorker(QThread):
for key in list(env.keys()):
if key.startswith(('LD_', 'PYINSTALLER_', 'PYTHON')):
del env[key]
# Specifically empty LD_PRELOAD as it can interfere with mount operations
env['LD_PRELOAD'] = ''
return env
def install_bootloader(self, target_mount, target_disk):
# GRUB installation
# GRUB installation with clean environment
cmd = ['chroot', target_mount, 'grub-install', target_disk]
subprocess.run(cmd, check=True)
clean_env = self._clean_env()
subprocess.run(cmd, check=True, env=clean_env)
self.log("Bootloader installed")
def run_post_install(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