I want to reinstall GRUB 2 and I found these instructions: How to Repair, Restore, or Reinstall Grub 2 with a Ubuntu Live CD or USB. In my case, the boot loader is installed in the EFI partition. If I use the commands provided in this guide, will GRUB be reinstalled to the EFI partition automatically, or will it be installed into the root partition where Ubuntu is installed ? Obviously, I do not want this to happen.
13 Answers
Reinstall the GRUB boot loader to your Ubuntu installation in EFI mode this way ...
Boot from the Ubuntu installation medium and select 'Try Ubuntu without installing'.
(Boot your install medium in EFI mode, select the Ubuntu entry with UEFI in front.)
Once you are on the Live desktop, open a terminal and execute these commands :
sudo mount /dev/sdXY /mnt
sudo mount /dev/sdXX /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/sdX
update-grub
exit
Note: If the grub-install command reports an error, it cannot find efivars. Try the following while still in the chroot environment (Thanks to @michael_dunn - the step was necessary in Ubuntu 22.10) :
mount -t efivarfs none /sys/firmware/efi/efivars
Afterwards execute the grub-install command again : grub-install /dev/sdX
To avoid possible unexpected issues, properly unmount the file systems afterwards.
sudo umount /dev/sdXX
sudo umount /dev/sdXY
Note : sdX = disk | sdXX = efi partition | sdXY = system partition
To identify the partitions use GParted, the tool is included in the installation medium.
After having run the commands, GRUB will be installed in the separate EFI partition.
- 31,491
this is the only way that worked for me: (System: sdb8, boot: sdb6, efi: sdb2)
sudo mount /dev/sdb8 /mnt
sudo mount /dev/sdb6 /mnt/boot
sudo mount /dev/sdb2 /mnt/boot/efi
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
sudo chroot /mnt
grub-install --target=x86_64-efi /dev/sdb
grub-install --recheck /dev/sdb
exit &&
sudo umount /mnt/sys &&
sudo umount /mnt/proc &&
sudo umount /mnt/dev/pts &&
sudo umount /mnt/dev &&
sudo umount /mnt
- 189
This is how I did it on a standard x86_amd64 EFI desktop, without chrooting, assuming you have a partition containing Ubuntu on your hard drive and possibly an EFI partition where GRUB should be installed.
boot on a live Ubuntu, I used 18.04 but more recent should work
if you have currently no EFI partition (maybe it was deleted, or you are migrating to a new drive):
sudo gparted
create a FAT 32 partition of around 100 MB on the disk of your choice (in general the one that host the Ubuntu partition). If you plan to move or resize some paritions, anticipate that (for instance by creating the EFI partition at the end of the free space).
set the flag esp on this partition (the flag boot will also be selected)
if the directory /sys/firmware/efi/efivars is empty, run:
mount -t efivarfs none /sys/firmware/efi/efivars
after which is should not be empty anymore
now assuming that the Ubuntu partition is /dev/sda2 and the (possibly new) EFI partition is /dev/sda1
sudo apt install grub-efi
sudo mkdir /media/root && sudo mount /dev/sda2 /media/root
sudo mkdir /media/efi && sudo mount /dev/sda1 /media/efi
if you use Secure Boot, add the argument --uefi-secure-boot to grub-install command below
sudo grub-install --target=x86_64-efi /dev/sda --efi-directory=/media/efi --boot-directory=/media/root/boot
This should give:
Installing for x86_64-efi platform.
Installation finished. No error reported.
Then reboot and you should be done. You may have to tell your BIOS which drive to use, or which EFI partition to use, or which EFI binary to use.
If you created a new EFI partition, you may have to add it to /etc/fstab to have update-grub working correctly.
For more information : https://wiki.archlinux.org/index.php/Multiboot_USB_drive#Hybrid_UEFI_GPT_+_BIOS_GPT/MBR_boot
source for how to populate /sys/firmware/efi/efivars (else grub-install warns: warning: EFI variables are not supported on this system)
source for how to make it work with Secure Boot.
- 24,696
During the last months there have been some updates to the libraries involved.
The steps below were useful for me. They took ideas from old answers as well as from other forums.
Make sure that you booted using EFI
efibootmgr -v
Run grub-install
sudo mount /dev/nvme0n1p5 /mnt
sudo mount /dev/nvme0n1p1 /mnt/boot/efi
for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do sudo mount -B $i /mnt$i; done
sudo chroot /mnt
grub-install --target=x86_64-efi /dev/nvme0n1
grub-install --recheck /dev/nvme0n1
as a second attempt, you could also try (assuming debian is your distro)
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian
grub-mkconfig -o /boot/grub/grub.cfg
update-grub2
exit &&
sudo umount /mnt/sys &&
sudo umount /mnt/proc &&
sudo umount /mnt/dev/pts &&
sudo umount /mnt/dev &&
sudo umount /mnt
Make sure that efibootmgr lists your Linux as an entry
efibootmgr -v
- 319
Thanks to @cl-netbox for the instructions!
After I upgraded (Linux Mint 18.2 Sonya to 18.3 Sylvia) my system wouldn't boot so I followed the instructions above but still no success. I noticed however that my machine has /boot in a separate partition (possibly because I am using LVM) so my slightly modified process was:
sudo mount /dev/sdXXX /mnt
sudo mount /dev/sdXY /mnt/boot
sudo mount /dev/sdXX /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/sdX
update-grub
Note : sdX = disk | sdXX = efi partition | sdXY = boot partition | sdXXX = system partition
- 79
Also, if booting from Live CD to recover, it might happen that you are missing the grub-efi-amd64-bin package and then the line:
grub-install --target=x86_64-efi /dev/sdb
fails with error message:
grub-install: error: /usr/lib/grub/x86_64-efi/modinfo.sh doesn't exist. Please specify --target or --directory.
In this case, run this outside of chroot:
sudo apt get grub-efi-amd64-bin
and then add /usr/lib/grub/x86_64-efi to chroot mounts.
BTW, the /dev/sdb parameter is obsolete and is being ignored.
- 16,703
- 146
If you happen to lose your EFI partition, it's easy to get it back. You can use a partitioning tool such as fdisk or parted to create a new partition sdXY (e.g. sda1) with type "EFI partition (1)" and format it with:
sudo mkfs.msdos /dev/sdXY
then mount it with:
sudo mount /dev/sdXY /boot/efi
and you can reinstall GRUB by running:
sudo grub-install --efi-directory=/boot/efi
as mentioned in other solutions.
- 150
I can't comment (not enough reputation), but @Chilu Pereira's answer is the way to go in an EFi or multiboot situation. It is similar to the approach in the gentoo-guide.
They use a slightly different approach :
Instead of a mount --bind they use mount --rbind followed by mount --make-rslave for sys and dev and proc gets simply mounted again.
In gentoo I used to create mounts from a live-system like this:
mount -t proc /proc /mnt/proc
mount --rbind /sys /mnt/sys
mount --make-rslave /mnt/sys
mount --rbind /dev /mnt/dev
mount --make-rslave /mnt/dev
chmod 1777 /mnt/dev/shm
(Anybody knows what is exactly the difference between --bind and --rbind / --make-rslave btw ?)
But today I got two errors in chroot from grub2, I never experienced before :
connect: No such file or directory
Please make sure that the zfs-fuse daemon is running
and
grub-install: warning: Cannot read EFI Boot* variables.
grub-install: warning: read_file: could not read from file: Input/output error.
The zfs-fuse error seems not to matter but for Efivars I had to add one more mount :
mount --bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars
I guess /sys/firmware/efi/efivars does not exist in chroot or maybe it's read only - but anyway it worked
- 41
in addition to ci-netbox answer.
If your pendrive OS version does not match the one that is installed on the disk, grub-install may have difficulties to identify the right grub installation:
$ sudo chroot /mnt
# grub-install /dev/sdX
grub-install: error: /usr/lib/grub/i386-pc/modinfo.sh doesn't exist.
Please specify --target or --directory.
Try to identify manually the installation to use
# ls /usr/lib/grub/
grub-mkconfig_lib x86_64-efi x86_64-efi-signed
Then restart grub-install :
# grub-install --target=x86_64-efi /dev/sdX
Installing for x86_64-efi platform.
Installation finished. No error reported.
- 1,333
Took me a while getting lost doing this. I have the same setup (non-encrypted /boot in ADDITION to a vfat /boot/efi). The following debian guide nails it. Missing pieces from all other guides were mounting the efivars and just comprehensive steps for grub re-installing etc. Hope this helps!
https://wiki.debian.org/GrubEFIReinstall
Details on the specific parts that were missing from other answers here:
include the efivars in the chroot whole installing grub
for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do sudo mount -B $i /mnt$i; donedon't forget to mount
/bootand then also/boot/efiin the chrootrun all the grub commands
apt-get install --reinstall grub-efi grub-install /dev/disk update-grub
Thank you debian!!
The simplest for me was to use this small tool (20 Mb) that will let you boot the broken grub system (I used Ventoy to boot the tool):
https://www.supergrubdisk.org/category/download/supergrub2diskdownload/
And once the tool has made its magic and booted your linux systen, do:
sudo grub-install /dev/nvme0n1
sudo update-grub
- 309
Just used this tool https://help.ubuntu.com/community/Boot-Repair on Ubuntu. That was the easiest way and all was automatic.
I used Grub-Customizer. I know some of you don't like this program, but in some cases it comes in very handy ( renaming Ubuntu in Kubuntu ( don't have to do that in 'etc/grub.d/10_Linux_Proxy' ), add a theme, or in this case.
File --> Install in MBR.
And all was done.
I don't use Linux based OS's that long ( 7 or 8 months now ), and if I have to write everything down to use in the command-line, it not only takes a long time ( mostly the writing down ), but I can make errors that way.
I had my Windows Bootloader in partition 1 and grub2 in another EFI partition ( 8 )( didn't want to mess up Windows Bootloader ), so every time I wanted to use my Kubuntu ( daily ) or Mint OS I had to press F11, wait, select USB ( don't ask me why ), select Ubuntu, then wait again for Grub and then select my Linux based OS. Now I get Grub2 almost instantly.
Update 211111/1135 Like Organic Marble commented 'MBR doesn't sound right for a UEFI system', he is right. It worked, but only once. What I did is install Grub2Win in my Win10 installation. From Kubuntu I could export my 'grub.conf´ to the 'My Documents'-partition ( NTFS, so Win10 can read that ) and imported it in Grub2Win. Now it is working like it is suposed to.
PS. I saved this page, so I know how to do it when I get rid of Windows.
- 1,570