Table of Contents
We’ve all been there. We’re dual booting and Windows does a major upgrade. Suddenly, without warning, in the quiet of night, we can no longer access our Linux partition.
Or, maybe you’re not on Windows. Maybe you’re using Arch (btw…). You upgrade your OS after a week and, boom, SHTF. No more GRUB.
Perhaps you’ve done what I did. You don’t have Windows on your computer. But you decided to use it for something and a VM isn’t cutting it. So, you install Windows on an ENTIRELY DIFFERENT HARD DRIVE and, still, despite your precautions, GRUB is gone -_-;
What do you do? Do you really reinstall Linux, again, and lose your precious data? You made a ton of commits last night, but never pushed your changes!
Never fear! Trusty Ubuntu is here to save the day! (you can use whatever live environment you want, I am using Ubuntu for ease of use and familiarity)
If you use UEFI, do not use the first set of commands, scroll down please.
Debian and Ubuntu family
The live USB instructions are applicable to all of the distributions below.
Create a live USB with Etcher, Rufus, dd, or whatever your poison.
https://www.ubuntu.com/download/desktop
After that, you’ll want to select “Try Ubuntu without installing” to load the live environment.
Next, fire up the terminal.
Find your drive with linux on it. lsblk -f
works, as does gparted
or parted -l
Mount the root partition. For me, it was /dev/sda2
sudo mount /dev/sda2 /mnt
Next, you need to mount components of the file system to /mnt:
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
If you receive errors on the above, you may need to mount another partition.
Next, chroot into /mnt:
sudo chroot /mnt
Run the following commands:
grub-install /dev/sda
grub-install --recheck /dev/sda
update-grub
Exit chroot and unmount everything.
exit && umount /mnt
Reboot!
sudo shutdown -r now
For UEFI
UEFI is quite a bit different (but much easier).
My EFI partition was on /dev/sda1 and my root partition was on /dev/sda2
sudo mount /dev/sda2 /mnt
sudo mount /dev/sda1 /mnt/boot/efi
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
sudo chroot /mnt
grub-install /dev/sda
update-grub
The foreach loop above is basically saying "Hey, if you find /dev, /dev/pts, /proc, /sys, and /run, go ahead and mount them (as the superuser) to /mnt/pathYouFound.
The rest of the process is the same as the MBR process.
Thank you @TheCakeIsNaOH for this write up!
For Arch
The Arch live ISO does not have a GUI so you do not have to find a terminal. It also logs in as root, so no sudo is needed for commands.
To find your disk you can use parted -l
or lsblk -f
as above, or you can use fdisk -l
Mount your disk with mount /dev/sdxX /mnt
, replacing the xX with your disk number. Additionally mount the EFI partition with mount /dev/sdxX /mnt/efi/
if you boot with UEFI. The EFI partition may need to be mounted to a different location such as /mnt/boot/efi depending on your setup.
Then you can arch-chroot /mnt
. Arch-chroot is a script that mounts /dev, /proc, and /sys so you do not have to manually mount them.
For BIos
When you are in the chroot, then run grub-install /dev/sdx
, do not specify a number ie sda1, instead just put sda. It will install for i386-pc even though Arch is 64 bit only.
For UEFI
When you are in the chroot, then run grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB
. Adjust efi-directory if needed.
Back to guide for both
Run grub-mkconfig -o /boot/grub/grub.cfg
If you are chrooting into a system that has a Debian based distro installed, then you could alternatively run update-grub.
The rest of the guide is the same as for Debian.
exit && umount /mnt
shutdown -r now
Fedora
@SgtAwesomesauce Bah, I knew that! Thanks for the reminder!
For Fedora, the process is a little different, and a bit more streamlined.
mkdir /mnt/sda
Mount the partition that has grub:
sudo mount /dev/sda1 /mnt/sda
Install GRUB:
grub2-install --boot-directory=/mnt/sda/boot/ /dev/sda
Save the config:
grub2-mkconfig -o /boot/grub2/grub.cfg
Reboot and you should be in business.
I hope this helps. I know this question gets asked sometimes, especially those that like to dual boot. The answer is sometimes painful to find, but hopefully this is immortalized in the Level1 community and expounded upon.