📜 ⬆️ ⬇️

Configuring the launch of the GRUB bootloader menu when installing Linux from Windows on one computer with a GPT partition table

Hi, Habr! Today we will look at the situation when, with a double installation of Linux & Windows, the GRUB boot loader does not start, giving the opportunity to choose an OS, and Windows is automatically loaded. A bit of theory:

GRUB (GRand Unified Bootloader) is an operating system loader program.
GRUB can boot any compatible operating system. Among them: Linux, FreeBSD, Solaris and many others. In addition, GRUB is able to transfer control to another bootloader, which allows it to load Windows (via NTLDR bootloader), MS-DOS, OS / 2 and other systems.

This means that we have dealt with theory a bit (I think this will be enough), but now we will look at the pitfalls when installing Dual Boot Windows and Linux on one computer.

image


The experiment was performed on a workstation with the following characteristics:
')
Base Board Information


Memory Device


HDD


It has been proven that there were no problems with installing Debian 8.6 Jessie with Windows 10. Debian is correctly written to autoload, GRUB runs without errors, and the two operating systems also work fine.

But, as practice has shown, this does not happen with all distributions. When installing Ubuntu 16.04.1 instead of Debian, the first pitfall came out on the same workstation - GRUB did not start, and Windows 10 automatically started downloading.

The solution to the problem was found after three or four weeks (then it was already tired of counting how long it was killed to solve the problem). It turned out to be unexpected, but at the same time the whole system started working. So, if you encounter the same problem, the instructions below may come in handy and save a lot of time.

Important! Before starting the instructions, you need to prepare a LiveCD with the Linux Mint distribution kit - we will perform all the operations on it (I chose this distribution because it is easy to install the Midnight Commander, which is difficult to do on the LiveCD with Ubuntu, so we get space for maneuvers). It is also worth noting that the command from under the update-grub console does not help you, since it is designed for the case when GRUB starts up, but does not see other OSes other than Linux. I also recommend creating backup copies of files / directories over which you make even the slightest changes.

  1. Via the terminal, with root rights, mount the partition with EFI in the / mnt folder. In my case, this was the mount / dev / sda2 / mnt command.

  2. Enter the command sudo -s and confirm the password (it is empty by default) for subsequent operations (many advise not to do this, but to enter sudo and the command to be executed - I support this opinion, but the instruction is intended for experienced Linux users who understand that do everything at your own peril and risk).

  3. Start Midnight Commander with the mc command.

  4. Locate the following directory in the file system: EFI in the / mnt folder.

  5. Rename the Microsoft directory to something else, such as Microsoft2.

  6. Create a new directory named Microsoft.

  7. Go to the newly created Microsoft directory and partially create within it a folder hierarchy similar to the old Microsoft (as it was renamed). In my case, it had the following folder structure: / boot /, then a bunch of folders and a bootmgfw.efi file next to them. You need to recreate the folder structure exactly before this file. Those. everything that lies next to it is not needed, and everything that comes to it (i.e., parent folders, neighboring ones are not needed either) will be recreated in our new Microsoft folder. In my case, I only needed to create the / boot folder, the final path to the new directory was: / EFI / Microsoft / boot. You can just copy all the folders and files - checked, it works and you can not create everything manually.

  8. We find in the directory from step 6 a folder with the name of our Linux distribution, in our case it is Ubuntu. Copy (the originals of the files and the ubuntu folder just in case we leave, do not interfere) all the files from this folder into the final directory created in the previous step: / EFI / Microsoft / boot.

  9. In the resulting file system, we find the file grubx.efi or grubx64.efi (there will be only one of them: depending on the bit width of the installed Linux). Rename it to bootmgfw.efi.

  10. Find the file / boot / grub / grub.cfg in the file system of the installed Linux. Open it for editing. Inside it, we find the word “Microsoft” in the context of the line starting with “chainloader” and replace this word (there should be only one entry and exactly in the line with “chainloader”, so you can't go wrong) with the name of the directory that we renamed Microsoft ( Ie on Microsoft2 in our example). Save the changes to the file.

Also, in this file you can change the names in the list, which displays GRUB. For example, instead of openSUSE Leap 42.2 27.01 in part of the code:

menuentry 'openSUSE Leap 42.2 27.01' --class opensuse --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-996b3ed5-150f-4de3-a40c-6d385e27d6de' { load_video set gfxpayload=keep insmod gzio insmod part_gpt insmod ext2 set root='hd0,gpt6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt6 --hint-efi=hd0,gpt6 --hint-baremetal=ahci0,gpt6 996b3ed5-150f-4de3-a40c-6d385e27d6de else search --no-floppy --fs-uuid --set=root 996b3ed5-150f-4de3-a40c-6d385e27d6de fi echo ' Linux 4.4.36-8-default …' linuxefi /boot/vmlinuz-4.4.36-8-default root=UUID=996b3ed5-150f-4de3-a40c-6d385e27d6de ro resume=/dev/sda7 splash=silent quiet showopts echo '    …' initrdefi /boot/initrd-4.4.36-8-default } 

Write openSUSE The best choice! :) :

 menuentry 'openSUSE The best choice!:)' --class opensuse --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-996b3ed5-150f-4de3-a40c-6d385e27d6de' { load_video set gfxpayload=keep insmod gzio insmod part_gpt insmod ext2 set root='hd0,gpt6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt6 --hint-efi=hd0,gpt6 --hint-baremetal=ahci0,gpt6 996b3ed5-150f-4de3-a40c-6d385e27d6de else search --no-floppy --fs-uuid --set=root 996b3ed5-150f-4de3-a40c-6d385e27d6de fi echo ' Linux 4.4.36-8-default …' linuxefi /boot/vmlinuz-4.4.36-8-default root=UUID=996b3ed5-150f-4de3-a40c-6d385e27d6de ro resume=/dev/sda7 splash=silent quiet showopts echo '    …' initrdefi /boot/initrd-4.4.36-8-default } 

Though a trifle, but nice! I advise you not to touch the rest of the code.

If it is difficult to understand the management of Midnight Commander (there’s nothing terrible, I also had problems with this program for the first time), all operations can be performed in the Nautilus file manager (or in another, it’s not important), but initially running it root user rights.

After that, go to the reboot and enjoy the result. But, as it turns out, there is such a problem with the distribution kit of OpenSUSE Leap 42.2. As practice has shown, if the OpenSUSE distribution kit with Windows 10 is installed on the computer, the above instruction will not help. More precisely, it will help, but only it needs to be supplemented. After completing the main part, perform the following steps:

  1. After performing all the operations, go to the folder / EFI / opensuse / x86_64-efi / (the name of the final folder x86_64-efi may be different depending on the PC architecture)
  2. Copy the grub.efi file (if you have the Secure Boot option enabled, there will be another shim.efi file, then I advise you to copy them together)
  3. Go to the folder / EFI / Boot and delete all the files that are there (when updating the bootloader, they will appear again, but there is nothing to worry about)
  4. Insert the file (or files) that we copied and calmly go to reboot.
    That's all the instructions. I think someone will come in handy ...

PS If everything is fine with you, GRUB starts with OpenSUSE, but does not see Windows, rejoice - the problem is solved with just one command: grub2-mkconfig -o /boot/grub2/grub.cfg , and if you have Ubuntu, you just need to update-grub .

For those who are interested in this topic, I recommend reading the article: “The GRUB 2 bootloader is a complete guide . ”

Source: https://habr.com/ru/post/321374/


All Articles