Installing the Grub boot loader. How to Make Windows Boot First in Grub Installing Boot Repair on Ubuntu

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

Grub (GRand Unified Bootloader) is the default bootloader for most Linux/Unix systems. It allows you to boot different operating systems (you can install multiple systems on your computer), or boot different versions of the kernel if you're 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 boot your operating system. As a rule, the only way to restore normal operation in this case is to restore or reinstall the Grub system bootloader. If done correctly, this procedure can prevent data loss. Today we will learn how to repair/reinstall the Grub bootloader in Ubuntu system. The steps below were performed on Ubuntu 16.04, but should also work on any reasonably recent version of Ubuntu. To complete our task we will use the well-known "Boot Repair" utility.

Installing Boot Repair on Ubuntu

Boot Repair is most often used to fix errors related to the Grub bootloader. First you need to boot your computer from a Live CD/DVD/USB for Ubuntu (if you are looking for a way to restore Grub, then there is a high probability that 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 the installation is successfully completed, run Boot Repair from Applications > Boot Repair:

Using Boot Repair to Fix Grub Errors

After boot launch Repair you will see the program start window:

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

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

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

Per the instructions, run 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 per the instructions, run the below command in a terminal and when prompted, specify HDD, on which 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 complete and you should see the message below:

Reboot your system and you should see a working bootloader menu.

Conclusion

Grub not working can be caused by various reasons, especially if you have more than one installed. operating systems, various errors may occur when updating or installing them. Therefore, it is useful to have such an excellent and free program to solve problems with the bootloader.

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

We will talk about how to install Linux OS as a second OS on new laptops with UEFI and before. installed Windows. Provided that the usual installation does not give the desired result, namely, after correctly installing Linux “next to” Windows, only Windows OS will still load.

To begin with, as has already become a tradition, let’s dot all the E’s.

Problem.

We have a laptop (possibly a desktop, but the author only dealt with a laptop), which uses UEFI and has Windows pre-installed (most likely 8.1, although now it’s already 10). We want to install Linux OS on this very laptop (we will talk about Linux Mint, but for others 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 the usual way * (which I will also write about someday, but the Internet is full of similar instructions), reboot and discover our actual problem:

Stubborn Windows always boots, no Grub, not a hint of any kind of dual boot.

*In fact, there are at least two important features for Linux installations on computers with UEFI. 1) Before installing in this same 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 the EFI\ESP partition, usually named sda2, and 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.

Quick solution for the lucky ones.

First, try logging into UEFI (F2 or DEL button BEFORE starting Windows). There, find the section indicating the download list. It must contain the following elements: at least a hard drive and Windows Loader. The latter usually has highest priority downloads. Look through the rest of the items in this list if there is anything like Ubuntu Loader(or something else, depending on what you're installing Linux distribution) , then we smile and wave, set it as the highest priority and reboot. After the reboot, 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 has sold its soul to Microsoft and does not want to see other bootloaders. Or, much less likely, Grub is not installed correctly. (read the notes to the previous section and do everything according to Feng Shui).

Mathematical part and necessary knowledge.

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

The reader will also need basic knowledge of installing Linux OS. We read somewhere there.

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

You will need to install MC (mint Linux does not have it by default), run it as root (administrator), make changes to text file and run a couple more simple commands in the console.

If you can do all this without the above instructions, I’m happy for you, we can move on. These instructions are given just in case, in order to avoid the questions covered in them.

Solution.

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

  1. Install Linux next to Windows using the appropriate option in one of the first installation steps or (if this option does not appear) properly partitioning the hard drive (deserves a separate article, this is also written about on the Ubuntu wiki).
  2. DO NOT reboot your computer after installation. If you rebooted, it’s okay, you’ll just have to boot from live-cd\usb\dvd again (after all, Linux won’t start for you?).
  3. Just in case, run the command in the console sudo update-grub(by entering a blank password when prompted).
  4. Open a console/terminal or 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 the installation).
  5. Run mc as root: sudo mc (and again a blank password if asked).
  6. Find the following directory in the file system: /boot/efi/EFI.
  7. Rename directory (combination ctrl+F6 in mc) Microsoft into something else, like Microsoft2.
  8. Create a new directory named Microsoft (F7 key).
  9. We go to the newly created Microsoft directory and partially (see below) create a folder hierarchy within it similar to the old Microsoft (to the one that was renamed). In my case it had this folder structure: /boot/, then a bunch of folders and a file bootmgfw.efi next to them. You need to recreate the folder structure exactly up to this file. Those. everything that lies next to it is not needed, but everything that comes before it (i.e. parent folders, those adjacent to them are also not needed) we recreate it in our new Microsoft folder. In my case, I only needed to create the boot folder, the final path to the new directory was 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 original files and the ubuntu folder just in case, it won’t hurt) all files from this folder into the final directory created in the previous step (V /boot/efi/EFI/Microsoft/boot) .
  11. In the resulting file system (in the directory created in step 9 and the files moved to it in step 10) 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. Finding the file /boot/grub/grub.cfg. Open it for editing (F4 key). Inside it we find (F7 key opens the text search form) the word "Microsoft" in the context of the line starting with "chainloader" and replace this word (there should be only one occurrence and it should be on the line with “chainloader”, so you can’t go wrong) to the name of the directory into which we renamed Microsoft in step 7 (i.e. on Microsoft2 in our example). Save changes to file (F2 key - save).

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

What did we just do?

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

By replacing the file with Grabov's, we thereby deceived both the laptop and Microsoft. They forced us to load our beloved Grub, instead of the angry and stubborn Windows.

What to do next? + Precautions for updates.

Live and be happy. 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 boot loader in the folder hierarchy we created (for reasons unknown to me). And, thus, after updating grub and then rebooting the PC, there will be no harmful Windows in the OS selection list (and it serves it right!). The solution is confusing, but the algorithm is familiar

  1. Rename the Microsoft folder (which currently contains files from Grab and Linux) to something temporary, for example MicrosoftLinux.
  2. Rename the good old Microsoft2 folder (in which the Windows bootloader is located) 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 appearance from the solution. Those. MicrosoftLinux is renamed back to Microsoft, Microsoft back to Microsoft2.
  5. We repeat step number 12 from the solution and again rejoice at the appearance of Windows in the OS list when the computer boots.

Yes, that's the only way for now. I would like to automate this thing, but for now I was very lazy. After all, grub isn't updated that often. And a manual description of the solution will never be superfluous; later it will be useful for automation.

Now here's what you need to know: if you are planning to update Windows .

Majority Windows updates requires a reboot. My Windows 8.1, as expected, failed to boot after such a reboot, because it did not find its boot loader at /boot/EFI/Microsoft (Linux lives there now). Therefore, before installing Windows updates, be sure to return its bootloader to its place. Those. to the Microsoft folder in our example. Yes, after this the whole problem will return, because only Windows will load again, but it will be easier to execute the algorithm from the solution the second time?;)

To select and launch the operating system when the computer boots, a specialized program is used - the bootloader. The most popular bootloader is Grub. When installing multiple operating systems, for example, Linux over Windows, the most recently installed OS will be the first in the bootloader menu.

This will not cause problems for users who use Linux as their main system, for them it is even a more preferable option. But if you are still a beginner and want to use Linux as a second system, and Windows is still the main one, until you get the hang of it, you probably want Windows to be the first. In this article we will look at how to make Windows boot first in Grub. Let's consider two ways: using the Grub Customizer program and manually, through the Grub bootloader configuration files.

Grub Customizer

Grub Customizer is a program that allows you to customize various settings of the Grub boot loader. Including the position and order of loading points. You can install the program from the official repositories. For example, on Ubuntu you need to use ppa:

sudo add-apt-repository ppa:danielrichter2007/grub-customizer
$ sudo apt-get update
$ sudo apt-get install grub-customizer

To run the program, open a terminal (Ctrl+Alt+T) and type grub-customizer:

For the program to work you need root rights, on some systems you may have to use the following command:

gksu grub-customizer

The program can also be launched from the main menu. The main window looks like this:

A few seconds after launch, the program will scan installed operating systems, then in the same window we will be able to move the Windows boot to the first place. To do this, right-click on the desired item to open a context menu:

From the menu, select Move up. This step will need to be repeated several times until Windows is first on the list. Windows will now boot to the default grub.

If you later want to lower Windows back down, there is a reverse action - Move down.

To save your settings, simply click the Save button. Ready. You can restart your computer and see what happens.

But I want to touch on a couple more settings that may be useful. Instead of making Grub boot Windows first, you can change the default startup item. Go to the tab basic settings:

There is a list here to select the default item used by default Engage:

In addition, you can load the last loaded OS by default; there is a checkbox for this:

Changing Grub boot order via terminal

As I promised, now we will look at how to make WIndows boot first into Grub using configuration files. The Grub configuration is located in the /boot/grub/grub.cfg file.

gksu gedit /boot/grub/grub.cfg

Typically, menu bars look like this:

menuentry item_name --options (
...

For example, Windows item:

menuentry "Windows 8 (loader) (on /dev/sda1)" --class windows --class os $menuentry_id_option "osprob
er-chain-FC324E26324DE66C" (
....

Now, to change the order of menu items, just cut everything up to the back closing bracket, along with this line, and paste it before all other items. Then you can save the file and you're done. Reboot and watch. Windows boots by default. The only downside of this method is that when updating the Grub configuration, all settings will be lost.

Similar to how we configured the default loaded item in Grub Customizer, this can also be done in the terminal.

Open the file /etc/default/grub.

gksu gedit /etc/default/grub

Here we are interested in the line:

Replace 0 with the desired item to load; you can also specify the name of the item instead of a number, for example:

GRUB_DEFAULT="Windows 8 (loader) (on /dev/sda1)"

You can view available download points without opening the configuration file with the command:

sudo grep menuentry /boot/grub/grub.cfg

You can also configure the loading of the last loaded system; to do this, add the line

GRUB_SAVEDEFAULT=true

And in GRUB_DEFAULT specify saved:

GRUB_DEFAULT=saved

The obvious advantage of this method is that the settings will not be lost when updating the Grub configuration, since during the update the information is taken from this file. Now let's update the configuration and save the settings with the command:

This option does not work on all systems, so you can use another command:

grub2-mkconfig -o /boot/grub/grub.cfg

That's all. Now you know how to make Windows boot first in Grub. But the information presented in this article can be used for broader purposes. It will be useful not only for Windows, but also for any other several systems whose boot order needs to be controlled.

Related posts:


This tutorial will walk you through the installation Ubuntu 16.10 And Ubuntu 16.04 multiboot with the Microsoft operating system on machines that come pre-installed Windows 10 .

For new installation Ubuntu 16.04/16.10, read our Ubuntu 16.04 Desktop Installation Guide and

This manual assumes that the machine comes pre-installed Windows 10 OS or more old version Microsoft Windows, such as Windows 8.1 or 8 .

In case your equipment uses UEFI then you have to change EFI settings and disable the function secure boot.

If your computer does not have another operating system installed and you plan to use only the Windows option, along with Ubuntu 16.04 / 16.10, you must first install Microsoft Windows and then proceed with the installation.

In this particular case, step by step Windows installations, when formatting your hard drive, you must allocate at least 20 GB of free space on the disk to use it later as a partition for installing Ubuntu.

Requirements

Download ISO image Ubuntu 16.04 And Ubuntu 16.10 according to the system architecture using the following link:

Step 1: Preparing Windows for a Dual Boot Machine

1. The first thing you need to take care of is to create free space on your computer's hard drive in case the system is installed on a single partition.

Login to your Windows machine using account administrator and right click on start menu-> Command line(Admin) to enter the Windows command prompt.

2. Open the utility Disk management. From here, right-click on the C: partition and select Shrink Volume to resize the partition.

C:\Windows\system32\> diskmgmt.msc

3. To reduce space on C: enter a value to reduce in MB (using at least 20000 MB depending on the partition size C:) and press the key Shrink to start resizing the partition as shown below.

Once the space has been changed, you will see new unallocated space on your hard drive. Leave it as default and restart your computer to begin installing Ubuntu 16.04.

Step 2: Install Ubuntu 16.04 with Windows OS

4. Now it's time to install Ubuntu 16.04. Follow the link at the beginning of the article and download the image ISOUbuntu Desktop 16.04.

Burn the image to DVD or create a bootable one USB flash drive using a utility such as Universal USB Installer(BIOS compatible) or Rufus(UEFI compatible).

Place the USB flash drive or DVD in the drive, reboot the machine and point to BIOS/UEFI to boot from DVD/USB by pressing a dedicated function key (usually F12 , F10 or F2 depending on the technical characteristics supplier).

After this, the media downloader will show a new loading screen on your monitor. From the menu, select Install Ubuntu and press the key Enter, to continue.

5. After the bootable media has finished booting into RAM you will be completely working with a functional Ubuntu system.

Click on the second icon from the top, install Ubuntu 16.04 LTS, the installation utility will start. Select the language in which you want to install and click the button Continue.

7. Now it's time to choose your installation type. You can install Ubuntu together with OS Windows Boot Manager, an option that will automatically take care of all partition steps.

Use this option if you do not require a custom partition layout. In case you want a custom section layout, check something else option and click on Continue button to move on.

Option Disk Erase and installing Ubuntu should be avoided on multiboot because it is potentially dangerous and will wipe out your disk.

8. In this step we will create our custom section layout for Ubuntu 16.04. This guide recommends creating two partitions, one for root and one for home and no partition for swap (use swap partition only if you have limited RAM resources or are using a fast SSD).

To create the first partition, the root partition, select the free space (the free space from Windows created earlier) and click on the + icon below. In the settings section, use the following configuration and click the button OK to apply the changes:

  1. Size = at least 20000 M.B.
  2. New partition type = Primary
  3. Space for new partition = Beginning
  4. EXT4
  5. Mount point = /

Create a home partition using the same steps as above. Use all available free space to size your home partition. The section settings should look like this:

  1. Size = all remaining free space
  2. New partition type = Primary
  3. Space for new partition = Beginning
  4. Use as = file system journaling EXT4
  5. Mount point = /home

9. Once completed, click the button Install Now to apply the changes to the disk and begin the installation process.

A popup should appear to inform you about the space swap. Ignore the warning by pressing the button Continue.

The next new pop-up window will ask you if you agree to commit the changes to disk. Click Continue to write the changes to disk and the installation process will begin.

10. On the next screen, set up a city in your installation, next to it on the map. Next click Continue.

11. Then select a layout keyboards and press the button Continue.

12. Enter the username and password for the administrative account SUDO, enter a descriptive name for your computer and click Continue to complete the installation.

These are all the settings needed to configure the installation Ubuntu 16.04. From now on, the installation process will start automatically until it reaches the end.

13. After the installation process reaches the end, click on the button reboot now to complete the installation.

The machine will reboot into the menu Grub, where within ten seconds, you will be presented with a choice of which OS you want to use at the moment: Ubuntu 16.04 or Microsoft Windows .

Windows access partitions from Ubuntu 16.04

That's all! In case you need to switch back to Windows OS, just restart your computer and select from the menu Grub OS Windows.

Original: GRUB 2: Heal your bootloader
Posted by Mayank Sharma
Published date: September 10, 2015
Translation: A. Panin
Translation date: December 16, 2015

There are not many things that can be as annoying as the system bootloader not working. That is why we will learn to make the most of all the capabilities of the GRUB 2 system boot loader, maintaining it in working order.

What is it for?

    GRUB 2 is the most popular boot loader, used in almost every Linux distribution.

    The system boot loader is an important software component, which, however, may not work correctly in some cases.

    GRUB 2 is an extensible and flexible boot loader that supports many configuration options.


The Linux boot loader, called GRUB 2, is a high-quality and flexible software component. Although this bootloader is not the only bootloader that supports Linux, it is the most popular and is used by almost all well-known distributions. The process of functioning of the GRUB 2 system boot loader can be divided into two phases. First, it displays a menu with the names of all the operating systems installed on your computer and allows you to select one of them. Secondly, it boots the Linux kernel when you select an operating system based on the corresponding kernel using the boot menu.

Obviously, when using an operating system based on the Linux kernel, you simply cannot do without a boot loader. At the same time, the system boot loader is perhaps the most mysterious component of the Linux distribution. In this guide, we will introduce you to some of the capabilities of this system boot loader and teach you how to solve problems associated with its incorrect functioning.

The most important component of the GRUB 2 boot loader is a collection of text files and several scripts. shell. The first component of this set that is worth getting acquainted with is located in the /etc/default/grub directory. This is a text file that allows you to set the values ​​of configuration variables and other GRUB 2 menu options (see the Custom Boot Menu Options section).

Another important directory associated with GRUB 2 is the /etc/grub.d directory. This directory contains all the scripts that form the description of each menu item. These script names must be prefixed with two digits. These prefixes are intended to establish the order in which the scripts will be executed, as well as the order in which the corresponding items will appear in the GRUB 2 menu. The 00_header file is read first, followed by the /etc/default/grub configuration file. After this, menu items are generated for the Linux kernels of the current system using the 10_linux script. This script creates one normal boot menu item for a Linux kernel and one system recovery menu item for the same Linux kernel from the /boot partition.

Next, scripts are executed to search for other operating systems, such as 30_os-prober and 40_custom. The os-prober script creates menu items for other kernels and other operating systems that are found on other hard drive partitions. It is able to recognize installed Linux, Windows, BSD and Mac OS X systems. If you use a partition configuration of your hard drive that is too exotic for the os-prober script, preventing recognition of the installed distribution, you can add a description of this distribution to the 40_custom script (see section " Custom boot menu items").

GRUB 2 does not require manual editing of configuration files to change system boot options: instead, it allows you to generate a configuration file /boot/grub/grub.cfg using the grub2-mkconfig utility. This utility allows you to parse scripts from the /etc/grub.d directory, as well as the /etc/default/grub configuration file to automatically generate a description of the system boot parameters.

Restoring the system boot loader in graphical mode

The vast majority of problems associated with the GRUB 2 boot loader can be simply resolved by pressing the Boot Repair application's single button. This sleek, simple application has an intuitive user interface and allows you to scan and recognize different types of disks and disk partition layouts, and can also locate and correctly identify operating systems installed within those partitions. The utility can work both on regular computers with Master Boot Records (MBR), and on new computers with UEFI and GUID Partition Tables (GPT).

The simplest way to use the Boot Repair utility is to install it as part of a Live session of the Ubuntu distribution. Run a live Ubuntu distribution on a machine with a broken bootloader and install the Boot Repair application, first adding the appropriate PPA using the command:

Sudo add-apt-repository ppa:yannubuntu/Boot Repair

After that, update the list of repositories using the command:

Sudo apt-get update

Finally, you can install the application using the command:

Sudo apt-get install -y Boot Repair

Once the installation process is complete, you will be able to launch the application. It will scan your hard drive before displaying a user interface that consists of several buttons. To perform the actions suggested by the application, you can simply click on the "Recommended Repair" button, which will fix most problems related to the system bootloader. After restoring your system bootloader, the utility will display a link that you should remember. By clicking on this link you will be able to familiarize yourself with detailed information about your disks, including their partitions, as well as the contents of important GRUB 2 configuration files, such as the files in the /etc/default/grub directory and the /boot/grub/grub.cfg file. If the application fails to restore your bootloader, you can post this link on your distribution's forum so that visitors can view your hard drive's partition layout and provide useful advice.

Restoring the system bootloader

Problems with the GRUB 2 boot loader can cause the system to go into various states. The text displayed on the screen instead of the boot loader menu indicates the current state of the system. If the system fails to boot at the grub> prompt, it can be concluded that the GRUB 2 modules were loaded, but the grub.cfg configuration file could not be loaded. This prompt is displayed in a full-featured bootloader command shell, with which you can perform a lot of actions aimed at booting the system. If you see the grub rescue> prompt, then it is easy to conclude that the system boot loader cannot detect its modules, as well as files describing the system boot parameters. However, if only the word "GRUB" is displayed on your computer screen, you can draw a disappointing conclusion that the system boot loader was unable to detect even the basic information that is usually stored in the master boot record.

You can fix these GRUB 2 problems by using either a Live CD from any distribution or a GRUB 2 shell. If you're lucky and your boot loader displays the grub> prompt, you can use the full power of GRUB 2's built-in shell to fix any errors.

The following commands will work both at the grub> prompt and at the grub rescue> prompt. The set pager=1 command allows you to enable the text scrolling mechanism to prevent it from automatically scrolling. You can also use the ls command, which allows you to list all visible GRUB 2 hard disk partitions in a similar way:

Grub> ls (hd0) (hd0,msdos5) (hd0,msdos6) (hd1,msdos1)

As you can see, this command allows you to display information about the partition table layout of the hard drive along with information about the partitions themselves.

Alternatively, you can use the ls command against each hard drive partition to find the partition with your root file system:

Grub> ls (hd0.5)/ lost+found/ var/ etc/ media/ bin/ initrd.gz boot/ dev/ home/ selinux/ srv/ tmp/ vmlinuz

You can discard the msdos partition type identifier when writing the partition name. Also, if you omit the slash at the end of the partition name and run, for example, a command such as ls (hd0.5), you will get information about the partition, including information about the file system type, its total size and the time of last modification. If you have multiple root partitions on your hard drive, you can read the contents of the /etc/issue file using the cat command to identify the distribution in a similar manner: cat (hd0.5)/etc/issue .

Assuming you have found the correct root filesystem in the (hd0,5) partition, you should ensure that this filesystem contains a /boot/grub directory and a Linux kernel image with a name similar to vmlinuz-3.13.0-24- generic you wish to load. Now to boot the system you just need to enter the following commands:

Grub> set root=(hd0,5) grub> linux /boot/vmlinuz-3.13.0-24-generic root=/dev/sda5 grub> initrd /boot/initrd.img-3.13.0-24-generic

The first command passes information to the GRUB 2 system boot loader about the partition of the hard drive on which the distribution files to boot are located. The second command passes it information about the location of the kernel image file within the specified hard disk partition, as well as information about the location of the root file system. The last line allows you to specify the location of the initial disk image file, the contents of which are stored in memory and used during the kernel boot process. You can use the auto-completion feature, which will save you a lot of time and effort when entering the names of the kernel files and the initial disk image.

Entering these lines must be completed by entering, after the next grub> greeting, the boot command, which initiates loading of the specified operating system using GRUB 2.

The lice action should be slightly different if you encounter the grub rescue> greeting. Since the system boot loader was unable to detect and load any of the required modules, you will have to download them manually:

Grub rescue> set root=(hd0,5) grub rescue> insmod (hd0,5)/boot/grub/normal.mod grub rescue> normal grub> insmod linux

Obviously, as before, after successfully using the ls command to find the Linux root partition, you will have to mark that partition using the set command. Next, you need to load the normal module, after which you will return to standard mode with the grub> greeting. The following command allows you to load the linux module if it was not loaded automatically. After loading this module, you can proceed to transfer information to the system boot loader about the location of the kernel image files and the initial disk image and initiate loading of the distribution using the boot command.

After successfully loading the distribution, do not forget about the need to re-generate the GRUB 2 configuration file using the command:

Grub-mkconfig -o /boot/grub/grub.cfg

You will also have to install a copy of the system boot loader into the master boot record using the command:

GRUB 2 and UEFI

Machines with UEFI firmware (that is, virtually all machines sold over the past few years) have added a new level of complexity to the process of diagnosing GRUB 2 boot loader problems. Even though the procedure for restoring the GRUB 2 boot loader installed on the machine is with UEFI firmware, does not differ significantly from the procedure for restoring the same bootloader on a machine without UEFI firmware; various changes are made to new firmware versions, which cause different results in the process of restoring the system bootloader.

On UEFI based systems you won't have to install anything into the Master Boot Record. Instead, you will have to install an EFI-enabled Linux boot loader in system partition EFI (EFI System Partition, ESP) and set it as the default boot loader using a tool such as efibootmgr on Linux or bcdedit on Windows.

At the moment, the GRUB 2 system bootloader should be installed correctly during the installation of any of the popular Linux distributions, which allows the latter to successfully coexist with Windows 8. However, in the event that you end up with an inoperative system bootloader, you can restore the system with using a live image of a Linux distribution. When downloading a live distribution image, you should make sure that you are booting in UEFI mode. The computer boot menu should contain two items for each of the removable media - for booting in normal mode and in UEFI mode. Use the latter mode to organize access to EFI variables through files from the /sys/firmware/efi/ directory.

From the live environment, you should mount the root file system of the unsuccessfully installed distribution in the manner described in this guide. You will also have to mount the EFI System Partition (ESP). Assuming that the device file /dev/sda1 corresponds to this partition, then you can mount this partition using the following command:

Sudo mount /dev/sda1 /mnt/boot/efi

You must then load the efivars kernel module using the modprobe efivars command before creating a chroot environment with the root filesystem of the failed distribution in the manner described in this guide.

Now, if you are using Fedora distribution, you can reinstall the boot loader using the following command:

Yum reinstall grub2-efi shim

After this, you should run the command to generate a new boot loader configuration file:

Grub2-mkconfig -o /boot/grub2/grub.cfg

Ubuntu users can perform the same operation using the command:

Apt-get install --reinstall grub-efi-amd64

After restoring the system boot loader, you should exit the chroot environment, unmount all mounted hard drive partitions and reboot the computer by going to the GRUB 2 menu.

To deactivate the script in the /etc/grub.d directory, you just need to clear the execution bit using a command similar to chmod -x /etc/grub.d/20_memtest86+, which removes the "Memory Test" line from the boot menu

Dude, where's my GRUB?

A positive feature of the GRUB 2 system boot loader is the ability to reinstall it whenever necessary. This way, if you lose your GRUB 2 boot loader, for example, after Windows replaces it with its own boot loader, you can restore GRUB 2 by performing a few operations in the live environment. Assuming you installed the distribution on the hard drive partition represented by the /dev/sda5 device file, you can reinstall the GRUB 2 boot loader by first creating a directory to mount the distribution's root filesystem using the command:

Sudo mkdir -p /mnt/distro

After this, you should mount the file system from this partition using the command:

Mount /dev/sda5 /mnt/distro

You can then reinstall the GRUB 2 boot loader using the command:

Grub2-install --root-directory=/mnt/distro /dev/sda

This command will overwrite information in the master boot record area of ​​the /dev/sda device, which contains the file system of the installed Linux distribution, as well as GRUB 2 boot loader files such as grubenv and device.map.

There is another problem that often arises when operating computers with several distributions installed. When installing a new Linux distribution, its boot loader must retrieve information about already installed distributions. In case it does not retrieve such information, you can simply download the latest installed distribution and run the command:

Grub2-mkconfig

Before executing this command, you should make sure that the partitions with the root file systems of the installed distributions that are not presented in the boot menu are mounted. If the distribution you want to add to the boot menu has the /root and /home filesystems on separate hard drive partitions, you should mount only the /root filesystem before running grub2-mkconfig.

Although the GRUB 2 boot loader can detect most distributions, attempting to add a boot loader menu entry for Fedora while running an Ubuntu distribution requires one additional step. If you used the default settings when installing your Fedora distribution, the installer will create the LVM partitions. In this case, before calling the os-prober script included with the GRUB 2 boot loader to add Fedora to the boot menu, you will first have to install the lvm2 driver using the distribution's software package management system using a similar command:

Sudo apt-get install lvm2

Quick Fix

If running grub2-install does not make any difference and you are unable to boot your Linux distribution, you will have to completely reinstall and reconfigure the boot loader. To perform this task, you can use the useful chroot utility, which allows you to temporarily replace the root directory of the live environment with the root directory of the installed Linux system, the functionality of which needs to be restored. You can use the Live CD of any Linux distribution that has the chroot utility for this purpose. However, you should make sure that you are using the Live CD for the same CPU architecture as the distribution installed on your hard drive. Thus, if you wish to use the chroot utility to restore the functionality of a 64-bit installed system, you will need a Live CD for 64-bit systems.

After loading the Live environment, first of all you should check the partitions of the machine’s hard drive. Use the fdisk -l command to list all partitions on your hard drive and find out the number of the partition on which the GRUB 2 boot loader is installed that you want to restore.

Let's assume that you need to restore the system boot loader of a distribution installed on the hard disk partition, which is represented by the device file /dev/sda5. Open a terminal emulator and mount this partition:

Sudo mount /dev/sda5 /mnt

Now you will have to mount directories that must be accessible to the GRUB 2 system boot loader in order to correctly detect other operating systems installed on the computer:

$ 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

Now you can leave the live environment and go to the environment of the distribution installed on the partition represented by the device file /dev/sda5 using the chroot utility:

$ sudo chroot /mnt /bin/bash

You are now ready to install, verify and update the GRUB 2 boot loader. As before, to reinstall the boot loader you should use the command:

Sudo grub2-install /dev/sda

Since the grub2-install command does not touch the grub.cfg configuration file, you will have to create it manually using the following command:

Sudo grub-mkconfig -o /boot/grub/grub.cfg

This sequence of commands should help fix bootloader problems. Your machine will now have a new copy of the GRUB 2 boot loader installed with a list of all operating systems and distributions installed on it. Before rebooting your computer, you should leave the chroot environment and unmount all used file systems in the following order:

$ exit $ sudo umount /mnt/sys $ sudo umount /mnt/proc $ sudo umount /mnt/dev/pts $ sudo umount /mnt/dev $ sudo umount /mnt

You can then safely reboot the machine, which should once again be under the control of the GRUB 2 boot loader, which is under your complete control!

Custom Boot Menu Options

The GRUB 2 boot loader uses a large number of configuration variables. This section describes some of these variables that you will likely want to modify as you review the contents of the /etc/default/grub configuration file. The GRUB_DEFAULT variable allows you to specify the boot menu item that will be selected by default. its values ​​can be numbers, such as the number 0, corresponding to the first menu item, as well as the string “saved”, which allows you to automatically select the menu item used the last time the computer booted. The GRUB_TIMEOUT variable allows you to set the length of time to wait before booting using the default menu item, and the GRUB_CMDLINE_LINUX variable allows you to specify a list of parameters that will be passed to each of the Linux kernels when using the corresponding boot menu items.

If the GRUB_DISABLE_RECOVERY variable is set to true, boot menu items for system recovery will not be generated. These elements allow you to boot distributions in single-user mode, in which you can use any available tools with the interface command line to restore the system. Another useful variable is the GRUB_GFXMODE variable, which allows you to set the screen resolution that will be set when the boot menu is shown. The value of this variable can be any description of the resolution supported by your graphics card.

Custom Boot Menu Items

If you wish to add an item to your bootloader menu, you must add the appropriate stanza to a script named 40_custom . You can use this boot menu item, for example, to boot a Linux distribution installed on a removable drive with USB interface. Assuming that the distribution partition on your removable USB drive is represented by the device file /dev/sdb1 , and the vmlinuz kernel image file and initrd file are in a subdirectory of the root directory (/), you will have to add the following stanza to the 40_custom script file:

Menuentry "Linux on USB" ( set root=(hd1,1) linux /vmlinuz root=/dev/sdb1 ro quiet splash initrd /initrd.img )

For better compatibility, you can use the hard disk partition UUID instead of the device and partition IDs as follows:

Set root=UUID=54f22dd7-eabe

Take advantage sudo command blkid to obtain all UUIDs of hard drives and their partitions attached to the system. Similarly, you can add entries to the boot menu corresponding to any distributions identified by the os-prober script but installed on the hard drive, of course, if you know what disk each distribution is installed on and what path its kernel image files are located on and an image of the initial file system.


Top