Ubuntu 16.04更新NVIDIA驱动后黑屏,如何借助boot repair修复启动问题?
Hey there, let's work through this black screen issue you're facing after updating your NVIDIA driver on Ubuntu 16.04. The fact you can SSH in remotely is a huge win—we can leverage that to fix things step by step using Boot Repair, custom boot scripts, and adjustments to shimx64.efi. Let's dive in:
update-initramfs Command Since you mentioned errors when running sudo update-initramfs -u, this is likely the root of your boot-time graphics failure. Let's diagnose and resolve this first:
- First, check the initramfs logs to pinpoint the exact error:
Look for lines mentioning NVIDIA module failures or missing files—this will tell us if the corrupted driver is blocking initramfs generation.cat /var/log/initramfs-tools/*.log - If NVIDIA drivers are the culprit, purge all existing NVIDIA packages to clean up:
sudo apt purge nvidia-* - Now try regenerating the initramfs again:
If this runs successfully, you can try reinstalling a stable NVIDIA driver later. If not, move on to the next steps.sudo update-initramfs -u
Boot Repair is a tool that automates most boot-related fixes, including repairing shimx64.efi and GRUB entries. Here's how to use it via SSH:
- Install Boot Repair from its PPA:
sudo add-apt-repository ppa:yannubuntu/boot-repair sudo apt update && sudo apt install boot-repair - First, gather boot info to understand the current state (this helps if we need to troubleshoot further):
sudo boot-repair --boot-info - Now run the core repair command to fix GRUB and EFI boot entries (this will reinstall GRUB and ensure shimx64.efi is properly configured):
sudo boot-repair --reinstall-grub - If you get an error about the EFI partition not being mounted, first locate your EFI partition (usually
/dev/sda1—usesudo fdisk -lto confirm), then mount it:
Re-run the boot repair command after mounting.sudo mount /dev/sda1 /boot/efi
If Boot Repair doesn't resolve the black screen, we can modify the GRUB boot parameters to skip problematic graphics initialization:
- Edit the GRUB default configuration file:
sudo nano /etc/default/grub - Find the line starting with
GRUB_CMDLINE_LINUX_DEFAULTand addnomodesetto bypass proprietary graphics drivers on boot. It should look like:
Alternatively, if you want to force the open-source nouveau driver, useGRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"nouveau.modeset=1 nvidia.modeset=0instead ofnomodeset. - Save the file (Ctrl+O, Enter) and exit (Ctrl+X), then update GRUB:
sudo update-grub - Reboot your machine—this should let you boot into a working graphical environment.
If the above steps don't fix the EFI boot issue, let's manually repair shimx64.efi (the EFI bootloader for Ubuntu with secure boot support):
- Ensure your EFI partition is mounted (as we did earlier:
sudo mount /dev/sda1 /boot/efi). - Reinstall the shim-signed package (which provides shimx64.efi):
sudo apt install --reinstall shim-signed - Reinstall GRUB to the EFI partition:
sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu - Check your EFI boot entries to make sure Ubuntu is set as the priority:
sudo efibootmgr - If Ubuntu isn't listed or isn't the first entry, add it manually (replace
/dev/sdaand1with your disk and EFI partition number):sudo efibootmgr -c -d /dev/sda -p 1 -L "Ubuntu" -l "\EFI\ubuntu\shimx64.efi"
Once you can boot into the graphical interface again, let's install a reliable NVIDIA driver for Ubuntu 16.04:
- Purge any remaining NVIDIA packages:
sudo apt purge nvidia-* - Install the official stable driver for 16.04 (nvidia-384 is the LTS recommended driver):
sudo apt install nvidia-384 - Regenerate the initramfs one last time:
sudo update-initramfs -u - Reboot your machine—this should give you a working system with the NVIDIA driver installed correctly.
Quick Notes
- Always back up important files before running system repair commands.
- If you have Secure Boot enabled, you may need to disable it temporarily (in your BIOS/UEFI settings) or enroll the NVIDIA driver's signing key to avoid boot issues.
- If
update-initramfsstill fails, try deleting leftover NVIDIA module files manually:
Then re-runsudo rm -rf /usr/lib/modules/$(uname -r)/kernel/drivers/video/nvidia*sudo update-initramfs -u.
内容的提问来源于stack exchange,提问作者user3639557

