Installing the grub uefi ubuntu 16.04 bootloader. How to fix GRUB2 if Ubuntu won't boot

Task: There is a computer with two systems: Windows 7 and Ubuntu 14.04
It is necessary to update the version of Windows, to 10 and ubuntu - to 16.04
To begin with, I had to install a licensed Windows instead of what was and update it to the latest version - dozens.
The image of the seven was downloaded from the Microsoft website, uploaded to a USB flash drive using a free and free program rufus, Windows was successfully installed from this flash drive and then updated to 10.
Now the task arose to restore GRUB, since Windows, of course, wiped out the bootloader, installing its own, which does not want to know about any Linuxes :) The task is complicated by the fact that modern motherboards do not contain BIOS, but UEFI - a more advanced local operating system. And as before, you can't install GRUB stupidly.

After a little googling this question, I found a solution in the form of the Boot-Repair program.
It scans disks for operating systems and installs GRUB, with the formation of the desired menu and all the necessary settings.
There are two ways to work with this program:
The first way is to boot from an ubuntu USB flash drive or LiveCD, install and run this program:
Open terminal (Ctrl + Alt + T), copy and execute the following commands:
sudo add-apt-repository ppa: yannubuntu / boot-repair
Then update sources:
sudo apt-get update
The following command will install Boot-Repair:
sudo apt-get install -y boot-repair
After that, the program can be launched in the usual way for Ubuntu, through the system menu.
Second way - download disk image with this program, upload it to a USB flash drive or CD, boot from it and restore the bootloader. I chose the second option as it is more practical. You never know where else it may be needed. I downloaded and uploaded it to the USB flash drive with the same rufusth.
I don't know how it is with the LiveCD, but if you boot from a flash drive on motherboards with UEFI, you need to boot in UEFI mode, otherwise the program will refuse to restore GRUB. And right here, a possible pitfall awaits. Instead of the usual choice of language and boot parameters, on the screen we see the GRUB menu on a black background with a line of the only start option.
If you boot from a USB flash drive with Ubuntu, we have a menu with two options:
- Booting Ubuntu without installing
- Installing Ubuntu.
In all these cases, when I selected any item, I had a black screen with a freeze. That is, the system could not pick up the video mode and fell into a stupor.
This problem is solved as follows: You need to select the desired menu item in GRUB, press the "e" key, so we get to the run line editor, then at the end of the line, which is the longest, before "-", add the nomodeset parameter. Then press F10. The system will boot in a simplified graphical mode with the default English language.
The program offers recommended operating parameters. In most cases, this is sufficient. Advanced users can select the operating system boot priority and selection timeout in the advanced options.
in the process, you need to do everything that the program asks for. The process is simple and intuitive. When the recovery is complete, you will see a message that the bootloader has been restored and you can restart your computer.

Today, almost everyone has already heard about UEFI technology. I'm not going to talk about what it is and why it is needed. Today I would like to describe the simplest scenario for installing a Dual Boot system with full UEFI support, and also consider separately installing and configuring the rEFInd boot manager. Perhaps you have already seen such manuals and guides, but I will try to convey very clearly the essence of what we will do and why. In other manuals, you just look at the "magic" of the gambler and try to repeat it, often making elementary mistakes. Who is interested in this topic - please, under cat.

In general, UEFI is intended, on the contrary, to simplify the boot process, rather than complicate it. For example, using this technology, the computer can boot the OS without any layer in the face of GRUB / LILO / etc, UEFI itself can act as the bootloader. However, this method has its drawbacks, for example, you have to tinker after updating the kernel, you can, of course, write a script, but in general this is what grub2-efi does.

So, let's form a rough list of our actions, some will have to read it and get down to business. Actually there will be everything four item. The fifth and sixth items are optional.

  1. Writing a Windows 10 (8 / 8.1) image to a disk / flash drive
  2. Installing Windows 10 on a part of the disk.
  3. Burning an image of a Linux distribution kit with EFI support (most) to a disk / flash drive.
  4. Installing Linux distribution on the rest of the disk.
  5. Installing and configuring rEFInd.
  6. Remove GRUB and switch to rEFInd completely.

At first glance, everything is very simple, there are only 4 basic points, but there are a lot of nuances here.

Mistakes are made at all stages: they enter the Legacy-bios mode, indicate the wrong boot partition, simply do not understand what they are doing, etc. Ultimately, all of this leads to a lot of pain and suffering in forums, chat rooms, etc. In fact, everything is unrealistically simple, you just need to understand what you are doing at each stage and check yourself.

Some theory first

UEFI sees only one special ESP partition, usually it has a size of 100-200 megabytes and is formatted in FAT32 (sometimes in FAT16), it contains folders with names a la Boot, Microsoft, Fedora, Ubuntu, etc. If you've tried a fair amount of operating systems and never formatted this partition, then a decent number of folders could accumulate there. For example, I had 2 live axes and there were about 6 folders.

Incorporating a beautiful theme

With that, everything is simple, just above the last line of the config points to the theme's .conf file. It is advisable to put the themes themselves in the / boot / efi / EFI / refind / themes folder. By default it is not there, create it via mkdir.
Go to the themes directory and just write git clone https://github.com/munlik/refind-theme-regular.git. In the config, add the line include themes / refind-theme-regular / theme.conf
Other topics can be found at the office. site.

There you can also see detailed installation processes, parameters for fine-tuning the config and much more.

Perhaps that's all. We got a beautiful boot manager for choosing the desired OS with full UEFI support. The rEFInd setting is the most difficult, and therefore optional, grub2-efi is enough for most.

Finally, a short video from me:


Surely a decent number of errors crept in in the text, I will be glad if you write me a PM about them.

Despite the fact that the Linux operating system occupies an insignificant market share, its various assemblies are gaining popularity for their official free-of-charge, fairly stable operation, and also considerable flexibility in settings. Yes, some things don't work the same as on Windows or Mac OS, and most software is created primarily for these two products. But this does not stop everyone.

For Linux to work, the Grub boot loader must be restored if a failure occurs.

Although almost any Linux build works flawlessly, sometimes a bootloader error can occur, making it impossible to start the operating system. What are the reasons for this? How do I repair the Grub bootloader in Linux? What working methods are there? We will tell about all this and even a little more in today's article.

After you install Linux on your hard drive, all files are copied to separate folders. Some directories store common software files that you can safely remove. Others write files without which the operating system will not work. This includes the Linux kernel, graphical shell, and the Grub boot loader. It is the latter that is used in order to run the installed operating system. How does this happen?

In a special boot partition, the system creates a master boot record. Its English abbreviation looks like MBR, and stands for Master Boot Record. When the computer starts, the BIOS accesses this entry, and then Grub comes into play and, when everything is in order, Linux starts up. And if the bootloader is damaged, an error will occur at startup and the system will not start.

For what reasons can this happen? The vast majority of cases are due to the fact that after installing Linux as the first system, you install Windows in the secondary role. Microsoft has traditionally disliked Linux, so the Windows installer removes Grub Linux. The same problem can arise when the Linux itself is not installed correctly, when you switch to another distribution, or because of disk repartitioning.

The most important thing to consider is that you don't have to immediately think about reinstalling the entire system. You just need to restore Grub and everything will work as before. Let's move on to considering the most effective methods available even to inexperienced users.

Via terminal from bootable media

To do this, you need a bootable USB flash drive or a disc with the recorded Linux distribution. Ideally, it should be similar to the system installed on the hard drive. But if the distribution kit is not the most important point, then the bit depth should be the same in any case. Otherwise, it is fraught with even greater consequences, as a result of which you will definitely have to reinstall everything.

  1. Insert a USB flash drive or disk into the computer connector, then as a priority for loading. The required setting is located in the Boot Device Priority or First Boot Device section. To start the BIOS, at startup, press the desired button or their combination on the keyboard. The most popular options are F2, Del, Shift + F2, F10. In order not to deal with BIOS, you can simply press F11 or F12 and select a medium from the list provided.
  2. Next, you need to find out on which partition of the hard drive the system is installed, and which one is specified as the bootloader. To do this, you need to launch a terminal (analogue of the Windows command line) by finding it in the application menu or by pressing the key combination Ctrl + Alt + T, or Alt + F2. In the window that opens, you will need to type the command sudo fdisk -l. Immediately, the utility will scan all disk partitions and display information about each of them. Even information about other operating systems installed on the computer will be shown. You can find out the name of the partition, its location, size, and the type of its file system. Provided that you did the partitioning manually when installing Ubuntu, you can easily figure out which partition is bootable and which is root. For automatic partitioning, be guided by the name Linux. It is he who will be the root of your system. The partition name usually consists of the abbreviation sdc or sda and a number with a sequential number.
  3. Next, you need to mount the root file system to the / mnt folder. The command sudo mount / dev / sda1 / mnt will help you with this, where instead of sda you need to write the name of your partition.

Starting from this stage, there are two ways to restore Grub on Linux.

Method 1

  1. Enter the bootloader repair command: sudo Grub-install -root-directory \u003d / mnt / dev / sda.
  2. Reboot the Computer using the sudo reboot command. As a result, the OS selection menu should appear.
  3. If this menu displays outdated information, update the MBR boot record. To do this, start Linux normally, open a terminal and use the sudo update-Grub command. If that doesn't work, apply sudo update-Grub –output \u003d / mnt / boot / Grub / Grub.cfg and then repeat the previous one.
  4. Restart your computer again.

Method 2.

  1. After mounting the root of the file system to the / mnt partition, you need to additionally mount the folder with the boot files, as well as other components of interaction with the kernel. To do this, one by one, run the commands:

sudo mount / dev / sdc2 / mnt / boot

sudo mount –bind / dev / mnt / dev

sudo mount –bind / sys / mnt / sys

sudo mount –bind / proc / mnt / proc

  1. Next, you need to run the chroot shell. To do this, add chroot / mnt / bin / bash in the terminal. The first parameter draws attention to the root directory, and the second to a special shell for converting user commands.
  2. Next, you need to apply the commands to get into Ubuntu and use almost all of its applications, except for services and the graphical interface:

source / etc / profile.

  1. Now you can start restoring Grub directly. To do this, you need to use several commands:
    • To re-install the boot loader on the hard drive: sudo Grub2-install / dev / sdc (the last parameter is the name of your partition).
    • To create a new config file: sudo Grub2-mkconfig -o /boot/Grub/Grub.cfg.
    • To update the boot menu: sudo Grub-update.
  2. To complete the procedure, exit the chroot shell using the exit command, and also unmount the previously mounted file system partitions:

sudo umount / mnt / dev

sudo umount / mnt / proc

sudo umount / mnt / sys

sudo umount / mnt

sudo umount / mnt / boot.

  1. Reboot via reboot.

Through the bootloader repair utility

Since the previous method may not be for everyone, we will use the feature of Ubuntu that it can work fully when launched from a USB flash drive. To do this, we will use a special boot-repair utility. What should be done?

  1. Start Ubuntu from a USB stick and make sure you have an active internet connection.
  2. Find a terminal and run the following commands one by one in it:

sudo add-apt-repository ppa: yannubuntu / boot-repair

sudo apt-get update

sudo apt-get install boot-repair.

  1. In the application menu, find "Boot Loader Repair" and enable the utility.
  2. Click on the button "Recommended recovery method" and wait for the end of the procedure.
  3. In most situations, these steps are sufficient for the Grub Linux boot loader to work properly.

Through the command line with partial access to the file system

Sometimes the Grub bootloader is not so badly damaged that the entire system cannot boot. For example, the boot partition remains intact, but the utility itself does not have access to it. In this case, a program shell is opened, which is somewhat similar to the command line, and the following message is displayed: Minimal BASH like line editing is supported. Using this command line, you can try to boot Ubuntu.

You are expected to be sure and know exactly which of the hard drives hosts the system and kernel. There are only four commands available, they must be applied sequentially:

  1. To have the system scan disks and partitions, issue the ls command. As a response, you will receive a list of hard drives (for example, hd1, hd2), as well as the type of file system on them (for example, msdos1, msdos2). For example, let's assume that the boot partition is located at / dev / sda1.
  2. Next, you need to select the section with which you want to work. In our case, the command will be written as follows: set root \u003d (hd1,1).
  3. Boot a regular Grub shell: insmod ext2, insmod normal, normal.
  4. Start Linux kernel: linux / boot / vmlinuz.
  5. Boot the system: boot.
  6. After starting Ubuntu in normal mode, open a terminal and finish the boot loader repair procedure with the following commands:

sudo Grub2-install / dev / sda

sudo Grub2-mkconfig -o /boot/Grub/Grub.cfg.

  1. Reboot and enjoy normal work.

Conclusion

Although at first glance, restoring the Grub bootloader in Ubuntu may seem like something very difficult, and many Linux users will immediately begin to reinstall the operating system with such a problem, with the normal instructions everything is done very easily and without any complications. We hope we were able to help you avoid losing important information. Bookmark this page and share this information with your friends and acquaintances. Leave your questions in the comments.

This article should have been written six months ago, but still nothing.

It will be about how to install the second OS Linux on new laptops with UEFI and pre-installed Windows. Provided that the usual installation does not give the desired result, namely, after the correct installation of Linux "next to" Windows, only Windows is loaded anyway.

To begin with, as has already become a tradition, let's put all the dots on E.

Problem.

We have a laptop (possibly a desktop, but the author dealt only with a laptop)that uses UEFI and has Windows preinstalled (most likely 8.1, although now it's already 10)... We want to install Linux on this laptop (I'll talk about Linux Mint, but for the rest the situation should be similar) second operating system (dual boot: the ability to use both Windows and Linux at the user's choice)... Install Linux in the usual way * (about which I will also write someday, but there are a lot of similar instructions on the Internet), reboot and find our actual problem:

stubborn Windows always boots, no Grub, not a hint of some kind of dual boot.

* There are actually at least two important considerations for installing Linux on UEFI computers. 1) Before installing in this very UEFI, you must disable the secure boot option - Security Boot Control (or something similar, depending on the UEFI version). Otherwise, the storage medium with the Linux distribution will almost certainly not be able to start. 2) The bootloader (Grub) must be installed on an EFI \\ ESP partition, usually named sda2, not just sda, as it was before, in the BIOS era. This option is adjusted during the Linux installation process, usually somewhere around the disk partitioning step.

Fast solutions for the lucky ones.

First, try to go to UEFI (F2 or DEL button BEFORE starting Windows). There, find the section with the download list. It must contain elements: at least a hard drive and Windows Loader... The latter usually has the highest boot priority. Review the rest of the items in the given list if there is something like Ubuntu Loader(or whatever, depending on the Linux distribution you are installing), then we smile and wave, set it to the highest priority and reboot. After rebooting, the long-awaited Grub interface should appear with a choice of OS to boot.

If there are no other "loaders", then you are out of luck, like me: your laptop sold its soul to Microsoft and does not want to see other boot loaders. Or, less likely, the Grub bootloader is not installed correctly. (read the notes to the previous section and do everything in Feng Shui).

Mat.part and necessary knowledge.

About what UEFI and BIOS are, why they are needed. The difference between MBR and GPT, as well as their meaning, is described in detail. We will not repeat ourselves. This information should be enough to understand this article.

Also, the reader will be required to have basic knowledge of Linux OS installation. We read somewhere in the same place.

You will also need basic skills in this OS, in particular, managing the file system using the Midnight Commander (MC) ( overview of the main features and commands) and the very basics of working in the Linux console ( for Ubuntu-like Linux a good guide for beginners).

You will need to install MC (in the same Mint Linux it is not by default), run it as root (administrator), make changes to the text file and execute a couple of simple commands in the console.

If all this is within your power and without the above instructions, I'm happy for you, we can move on. These instructions are given just in case, in order to avoid questions consecrated in them.

Decision.

Please note that the entire algorithm is built for Linux Mint OS. In other Linuxes (not based on Ubuntu or Debian) directory names and commands may differ slightly.

  1. Install Linux next to Windows using the appropriate option in one of the first steps of the installation, or (if this option did not appear) partitioning the hard drive properly (deserves a separate article, it has already been written about this on the ubuntu wiki).
  2. DO NOT RESTART your computer after installation. If you rebooted, it's okay, you just have to boot from live-cd \\ usb \\ dvd again (after all, you can't start Linux?).
  3. Just in case, run the command in the console sudo update-grub (by entering an empty password when prompted).
  4. Open console \\ terminal or by other means (for example, using the program manager in Ubuntu \\ Linux Mint) install mc. In the console (for systems with apt) this is done as follows: sudo apt-get install mc (after which you will need to enter a password, let me remind you that there is no password in live mode, just press Enter and agree to install).
  5. Run mc as root: sudo mc (and again an empty password if asked).
  6. Find the following directory in the file system: / boot / efi / EFI.
  7. Rename directory (combination of ctrl + F6 in mc) Microsoft into something else, like Microsoft2.
  8. Create a new directory named Microsoft (F7 key).
  9. We go into the newly created Microsoft directory and partially (see below) create a hierarchy of folders inside it similar to the old Microsoft (to what was renamed)... In my case, it had a folder structure like this: / boot /then a bunch of folders and a file bootmgfw.efinext to them. It is necessary to recreate the folder structure exactly before this file. Those. everything that lies next to him is not needed, but everything that comes before him (i.e. parent folders, adjacent to them are also not needed) recreate in our new Microsoft folder. In my case, I only needed to create the boot folder, the final path to the new directory came out like this: / boot / efi / EFI / Microsoft / boot .
  10. We find in the directory from step 6 a folder with the name of our Linux distribution, in our case it is ubuntu... Copy (we leave the originals of the files and the ubuntu folder just in case, they will not interfere)all files from given to folders in the final directory created in the previous step (in / boot / efi / EFI / Microsoft / boot) .
  11. In the resulting file system (in the directory created at the 9th step and the files moved to it at the 10th step) find the file grubx.efi or grubx64.efi (there will be only one of them: depending on the bitness of the installed Linux)... Rename it to bootmgfw.efi .
  12. Find the file /boot/grub/grub.cfg ... We open it for editing (F4 key)... Inside it we find (the F7 key calls the text search form) the word "Microsoft" in the context of a line starting with "chainloader" and replace this word (there should be only one occurrence and it is in the line with "chainloader", so you can't go wrong) to the name of the directory that we renamed Microsoft in the 7th step (i.e. on Microsoft2 in our example)... Save changes to the file (F2 key - save).

That's all. It looks very difficult, but if you follow everything exactly in steps (which are painted in as much detail as possible!), then everything will work out without any problems. And, after rebooting and then booting from the hard drive (not from live media)we will see the coveted screen with the OS selection menu. Hurray, comrades!

What have we just done?

Let me explain. As you can see, the manufacturer of your (and mine, I have an Acer if that) laptop sold his soul to Melkosoftam, as I said earlier. Namely, a laptop at the UEFI level does not want to load anything other than a file / boot / efi / EFI / Microsoft / boot bootmgfw.efiwhere the Windows bootloader is located. Such is the discrimination!

By replacing the file with Grabowski, we thereby deceived both the laptop and Microsoft. Forced to load our beloved Grub, instead of the evil and stubborn Windows.

What to do next? + Precautions for updates.

Live and rejoice. But exactly until grub wants to update. Or, you don't want to sin and update your Windows

First about updating Grub.

The fact is that after the update, Grub runs the update-grub command, which does not find the Windows bootloader in the folder hierarchy we created. (for reasons I don't understand)... And, thus, after updating grub and then restarting the PC, there will be no harmful Windows in the OS selection list (and rightfully so!). The solution is confusing, but the algorithm is familiar

  1. Rename the Microsoft folder (in which the files from the hornbeam and Linux are now) to something temporary, for example, MicrosoftLinux.
  2. You rename the good old Microsoft2 folder (which contains the Windows bootloader) to simply Microsoft, thereby returning it to its original state.
  3. Execute the command sudo update-grub.
  4. Return the folder names, giving them the look from the solution. Those. Rename MicrosoftLinux back to Microsoft, Microsoft back to Microsoft2.
  5. We repeat step 12 from the solution and again we are glad that Windows appears in the OS list when the computer boots.

Yes, so far only so. This business would be automated, but so far I was very lazy. After all, grub is not updated very often. And a manual description of the solution will never be superfluous, then it will be useful for automation.

Now what you need to know if you are going to update Windows .

Most Windows updates require a restart. After such a reboot, Windows 8.1, as expected, failed to boot, because it did not find its bootloader at / boot / EFI / Microsoft (Linux now lives there)... Therefore, be sure to replace the bootloader before installing Windows updates. Those. to the Microsoft folder in our example. Yes, after that the whole problem will return, because only Windows will be loaded again, but after all, it will be easier to execute the algorithm from the solution a second time?;)

Original: How To Repair Grub Boot Loader On Ubuntu Linux 16.04 /15.10 / 15.04
Author: Aun
Publication date: June 21, 2016
Translation: A. Krivoshey
Date of translation: October 2016

Grub (GRand Unified Bootloader) is the default bootloader for most Linux / Unix systems. It allows you to load different operating systems (you can install multiple systems on your computer), or load different versions of the kernel if you are running Linux. If this program is damaged in any way, you will receive error messages during the boot process, and as a result, you will most likely not be able to load your operating system. Typically, the only way to restore normal operation in such a case is to repair or reinstall the Grub boot loader. If done correctly, this procedure avoids data loss. Today we are going to learn how to repair / reinstall Grub bootloader on Ubuntu system. The steps below were performed on Ubuntu 16.04, but should also work on any fairly recent version of Ubuntu. To accomplish our task, we will use the well-known "Boot Repair" utility.

Installing Boot Repair in Ubuntu

Boot Repair is most commonly used to fix bugs related to the Grub bootloader. First you need to boot your computer from the Live CD / DVD / USB for Ubuntu (if you are looking for a way to restore Grub, then most likely you can no longer boot your installed operating system).

$ sudo add-apt-repository ppa: yannubuntu / boot-repair

After adding the PPA, update the package list:

$ sudo apt-get update

Now you can install Boot Repair:

$ sudo apt-get install -y boot-repair

After successful completion of the installation, launch Boot Repair from Applications\u003e Boot Repair:

Using Boot Repair to Fix Grub Errors

After starting Boot Repair, you will see the start window of the program:

The very first option (Recommended repair) can fix Grub errors, click it and it will start the repair / reinstall process shown in the screenshot below.

According to the instructions in the screenshot, open a terminal and run the following three commands:

After completing these commands, click “Forward” to proceed to the next step in the recovery process. This is what you will see in the next step:

Follow the instructions to execute the three commands below in the correct order. During this step, a window will appear asking you to confirm the removal of Grub 2, select "Yes".

$ sudo dpkg --configure -a $ sudo apt-get install -fy $ sudo apt-get install -y --force-yes grub-pc linux-generic

Click “Forward” after completing the process, below is a screenshot of the next step.

As instructed, run the command below in a terminal and, when prompted, specify the hard drive where grub will be installed.

$ sudo apt-get install -y --force-yes grub-pc linux-generic

Now you need to wait a couple of minutes for the necessary operations to be performed, and you should see the message below:

Reboot your system and you should see the bootloader menu.

Conclusion

Grub can be broken for a variety of reasons, especially if you have multiple operating systems installed, various errors can occur when updating or installing them. Therefore, it is useful to have such a great and free program to fix bootloader problems on hand.