Update gpu detection during install

parent d4feb766
...@@ -1086,6 +1086,15 @@ class InstallerWorker(QThread): ...@@ -1086,6 +1086,15 @@ class InstallerWorker(QThread):
except Exception as e: except Exception as e:
self.log(f"Warning: rc.local modification failed: {str(e)}") self.log(f"Warning: rc.local modification failed: {str(e)}")
# Detect GPU and configure glx alternative and kernel drivers before GRUB installation
self.log("Detecting GPU and configuring graphics drivers...")
try:
self._configure_gpu(target_mount)
self.log("GPU configuration completed successfully")
except Exception as e:
self.log(f"Warning: GPU configuration failed: {str(e)}")
# Continue with installation despite GPU configuration failure
# Install GRUB bootloader BEFORE unmounting (this is the very last step before cleanup) # Install GRUB bootloader BEFORE unmounting (this is the very last step before cleanup)
self.log("Installing GRUB bootloader (final step before unmounting)...") self.log("Installing GRUB bootloader (final step before unmounting)...")
try: try:
...@@ -1603,6 +1612,187 @@ backup-logs=true ...@@ -1603,6 +1612,187 @@ backup-logs=true
# Implementation similar to original script # Implementation similar to original script
self.log("NTP configured") self.log("NTP configured")
def _detect_gpu(self):
"""Detect GPU type using lspci"""
self.log("Detecting GPU hardware...")
try:
result = subprocess.run(['lspci', '-nn'], capture_output=True, text=True, check=True)
gpu_info = []
for line in result.stdout.split('\n'):
if 'VGA' in line or '3D' in line or 'Display' in line:
gpu_info.append(line.lower())
# Check for NVIDIA
for info in gpu_info:
if 'nvidia' in info:
self.log("Detected NVIDIA GPU")
return 'nvidia'
# Check for AMD
for info in gpu_info:
if 'amd' in info or 'ati' in info or 'radeon' in info:
self.log("Detected AMD GPU")
return 'amd'
# Check for Intel
for info in gpu_info:
if 'intel' in info:
self.log("Detected Intel GPU")
return 'intel'
self.log("No specific GPU detected, will use mesa fallback")
return 'mesa'
except subprocess.CalledProcessError as e:
self.log(f"Warning: GPU detection failed: {e}")
return 'mesa'
def _detect_nvidia_driver(self):
"""Detect optimal NVIDIA driver using nvidia-detect"""
self.log("Detecting optimal NVIDIA driver...")
try:
result = subprocess.run(['nvidia-detect'], capture_output=True, text=True, check=True)
output = result.stdout.lower()
# Parse nvidia-detect output for recommended driver
if 'nvidia-driver' in output:
# Extract driver version from output
lines = output.split('\n')
for line in lines:
if 'nvidia-driver' in line and 'is' in line:
# Look for patterns like "nvidia-driver-470" or "nvidia-driver"
driver_match = re.search(r'nvidia-driver(?:-(\d+))?', line)
if driver_match:
version = driver_match.group(1)
if version:
driver_name = f"nvidia-driver-{version}"
else:
driver_name = "nvidia-driver"
self.log(f"NVIDIA driver detected: {driver_name}")
return driver_name
# Fallback to common driver versions
self.log("Using fallback NVIDIA driver detection")
return "nvidia-driver"
except subprocess.CalledProcessError as e:
self.log(f"Warning: nvidia-detect failed: {e}, using fallback")
return "nvidia-driver"
def _configure_gpu(self, target_mount):
"""Configure GPU drivers and GLX alternative"""
gpu_type = self._detect_gpu()
if gpu_type == 'nvidia':
self.log("Configuring NVIDIA GPU...")
driver_package = self._detect_nvidia_driver()
try:
# Install NVIDIA driver
self.log(f"Installing NVIDIA driver: {driver_package}")
cmd = ['chroot', target_mount, 'apt-get', 'install', '-y', '-qq', driver_package]
result = subprocess.run(cmd, capture_output=True, text=True, check=True, env=self._clean_env())
self.log("NVIDIA driver installed successfully")
# Blacklist nouveau driver to prevent conflicts
self.log("Blacklisting nouveau driver...")
blacklist_path = f"{target_mount}/etc/modprobe.d/nvidia-blacklist.conf"
try:
with open(blacklist_path, 'w') as f:
f.write("# Blacklist nouveau driver for NVIDIA GPU\n")
f.write("blacklist nouveau\n")
f.write("options nouveau modeset=0\n")
self.log("Nouveau driver blacklisted successfully")
except Exception as e:
self.log(f"Warning: Could not create nouveau blacklist: {e}")
# Set GLX alternative to NVIDIA
self._set_glx_alternative(target_mount, 'nvidia')
except subprocess.CalledProcessError as e:
self.log(f"Warning: NVIDIA driver installation failed: {e}")
# Fallback to mesa
self._set_glx_alternative(target_mount, 'mesa')
elif gpu_type == 'amd':
self.log("Configuring AMD GPU...")
try:
# Install AMD firmware and drivers
cmd = ['chroot', target_mount, 'apt-get', 'install', '-y', '-qq',
'firmware-amd-graphics', 'xserver-xorg-video-amdgpu']
result = subprocess.run(cmd, capture_output=True, text=True, check=True, env=self._clean_env())
self.log("AMD drivers installed successfully")
# Set GLX alternative to mesa (AMD uses mesa)
self._set_glx_alternative(target_mount, 'mesa')
# Update initramfs to include AMD modules
self._update_initramfs(target_mount)
except subprocess.CalledProcessError as e:
self.log(f"Warning: AMD driver installation failed: {e}")
self._set_glx_alternative(target_mount, 'mesa')
else:
# Intel or unknown GPU - use mesa
self.log("Using mesa GLX for Intel/unknown GPU")
self._set_glx_alternative(target_mount, 'mesa')
# Update initramfs for Intel graphics if needed
if gpu_type == 'intel':
self._update_initramfs(target_mount)
def _set_nvidia_alternative(self, target_mount):
"""Set NVIDIA alternative to current version"""
self.log("Setting NVIDIA alternative...")
try:
# Set NVIDIA alternative to current version (similar to hook)
cmd = ['chroot', target_mount, 'update-alternatives', '--set', 'nvidia', '/usr/lib/nvidia/current']
result = subprocess.run(cmd, capture_output=True, text=True, check=True, env=self._clean_env())
self.log("NVIDIA alternative set to current version")
except subprocess.CalledProcessError as e:
self.log(f"Warning: NVIDIA alternative setting failed: {e}")
def _set_glx_alternative(self, target_mount, provider):
"""Set GLX alternative to specified provider"""
self.log(f"Setting GLX alternative to {provider}...")
try:
if provider == 'nvidia':
# Set NVIDIA as GLX provider
cmd = ['chroot', target_mount, 'update-alternatives', '--set', 'glx', '/usr/lib/nvidia']
result = subprocess.run(cmd, capture_output=True, text=True, check=True, env=self._clean_env())
self.log("GLX alternative set to NVIDIA")
else:
# Set mesa as GLX provider (default)
cmd = ['chroot', target_mount, 'update-alternatives', '--set', 'glx', '/usr/lib/mesa-diverted']
result = subprocess.run(cmd, capture_output=True, text=True, check=True, env=self._clean_env())
self.log("GLX alternative set to mesa")
except subprocess.CalledProcessError as e:
self.log(f"Warning: GLX alternative setting failed: {e}")
def _update_initramfs(self, target_mount):
"""Update initramfs to include GPU modules"""
self.log("Updating initramfs for GPU modules...")
try:
# Update initramfs (works with both initramfs-tools and dracut)
cmd = ['chroot', target_mount, 'update-initramfs', '-u']
result = subprocess.run(cmd, capture_output=True, text=True, check=True, env=self._clean_env())
self.log("Initramfs updated successfully")
except subprocess.CalledProcessError as e:
self.log(f"Warning: Initramfs update failed: {e}")
# Try alternative dracut command if initramfs-tools fails
try:
cmd = ['chroot', target_mount, 'dracut', '--regenerate-all', '--force']
result = subprocess.run(cmd, capture_output=True, text=True, check=True, env=self._clean_env())
self.log("Dracut initramfs regenerated successfully")
except subprocess.CalledProcessError as e2:
self.log(f"Warning: Dracut regeneration also failed: {e2}")
def _clean_env(self): def _clean_env(self):
"""Return clean environment for subprocess calls""" """Return clean environment for subprocess calls"""
env = os.environ.copy() env = os.environ.copy()
......
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