加密分区中更新GRUB的方法及Ubuntu 16.04更新后GRUB故障求助
Hey there, let's tackle this GRUB problem you ran into after updating Ubuntu 16.04, plus cover how to update GRUB on encrypted partitions.
First: Get Back Into Your System From the GRUB Rescue Prompt
Since you're stuck at the black GRUB screen with just a prompt, here's how to manually boot into Ubuntu temporarily:
First, identify your Ubuntu root partition by running:
lsYou'll see entries like
(hd0,gpt1),(hd0,gpt2)—test which one is your root partition by running:ls (hd0,gpt2)/bootIf you see kernel files (like
vmlinuz-xxx-generic), that's your root partition.Set the root partition in GRUB:
set root=(hd0,gpt2) # Replace with your actual partitionLoad the kernel and initrd image (use TAB to auto-complete the kernel version):
linux /boot/vmlinuz-<your-kernel-version>-generic root=/dev/sda2 ro # sda2 matches the partition from step 1 initrd /boot/initrd.img-<your-kernel-version>-genericBoot into Ubuntu:
boot
Once you're in the system, we can fix GRUB permanently.
Permanently Repair GRUB (Non-Encrypted Partitions)
Run these commands to refresh and reinstall GRUB:
sudo update-grub sudo grub-install /dev/sda # Note: This is the disk (e.g., /dev/sda), not a partition like /dev/sda2
Reboot your system—you should now see the normal GRUB menu.
Updating GRUB on Encrypted Partitions
If your Ubuntu root partition is encrypted, follow these steps to safely update GRUB:
Unlock the encrypted partition (replace
/dev/sda2with your encrypted partition,ubuntu-cryptis a temporary mapping name):sudo cryptsetup luksOpen /dev/sda2 ubuntu-cryptMount the root partition to
/mnt:sudo mount /dev/mapper/ubuntu-crypt /mntMount the /boot partition if you have a separate one (replace
/dev/sda1with your boot partition):sudo mount /dev/sda1 /mnt/bootBind critical system directories to access them from the chroot environment:
sudo mount --bind /dev /mnt/dev sudo mount --bind /proc /mnt/proc sudo mount --bind /sys /mnt/sysEnter the chroot environment to work within your installed system:
sudo chroot /mntUpdate and reinstall GRUB:
update-grub grub-install /dev/sda # Again, target the disk, not a partitionClean up and unmount:
Exit the chroot, then unmount all the directories and close the encrypted partition:exit sudo umount /mnt/sys sudo umount /mnt/proc sudo umount /mnt/dev sudo umount /mnt/boot # Skip this if you didn't mount a separate boot partition sudo umount /mnt sudo cryptsetup luksClose ubuntu-crypt
Reboot your system, and GRUB should be properly updated for your encrypted setup.
内容的提问来源于stack exchange,提问作者Jarodd

