Configuring the launch of the GRUB bootloader menu when installing Linux from Windows on one computer with a GPT partition table
Hello, Habr! Today we will consider the situation when, when installing Linux & Windows twice, the GRUB bootloader does not start, giving you the opportunity to choose the OS, and Windows automatically boots. A bit of theory:
So we figured out the theory a bit (I think this will be enough), now let's look at the pitfalls when installing Dual Boot Windows and Linux on the same computer.
The experiment was carried out on a workstation with the following characteristics:
Base Board Information
Memory device
HDD
It has been proven that no problems installing Debian 8.6 Jessie with Windows 10 were found. Debian correctly registers at startup, GRUB starts without errors, and two OSs also work fine.
But, as practice has shown, not with all distributions this happens. When installing Ubuntu 16.04.1, instead of Debian, the first pitfall crawled out on the same workstation - GRUB did not start, and Windows 10 automatically booted.
A solution to the problem was found three to four weeks later (then I was tired of taking into account how much time was spent on solving the problem). It turned out to be unexpected, but at the same time the whole system worked. So, if you encounter the same problem, the instructions below may come in handy and save you a lot of time.
Important!Before you start executing the instructions, you need to prepare a LiveCD with the Linux Mint distribution - we will perform all operations on it (I chose this distribution because it’s easy to install Midnight Commander on it, which is difficult to do on a LiveCD with Ubuntu, so we get more space for maneuvers). It is also worth noting that the command from under the update-grub console will not help you, since it is designed for the case when GRUB is launched, but does not see other operating systems except Linux. I also recommend creating backup copies of files / directories over which you make even the slightest changes.
Also, in this file you can change the names in the list that GRUB displays. For example, instead of openSUSE Leap 42.2 27.01 in the code part:
Write openSUSE The best choice! :) :
Though a trifle, but nice! I advise you not to touch the rest in the code.
If it’s difficult to understand the management of Midnight Commander (this is not a big deal, 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 doesn’t matter), but by starting it under as root user.
After that, we go to reboot and enjoy the result. But, as it turns out, the OpenSUSE Leap 42.2 distribution has such a problem. As practice has shown, if an OpenSUSE distribution kit with Windows 10 is installed on the computer, then 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:
PS If everything is fine with you, GRUB with OpenSUSE starts up, but does not see Windows, rejoice - the problem is solved only by one command: grub2-mkconfig -o /boot/grub2/grub.cfg , and if you have Ubuntu, you just need to do update-grub .
For those who are interested in this topic, I recommend reading the article: "GRUB 2 bootloader - a complete guide . "
GRUB (GRand Unified Bootloader) is a bootloader for operating systems.
GRUB can load any operating system compatible with it. Among them: Linux, FreeBSD, Solaris and many others. In addition, GRUB is able to chain transfer control to another bootloader, which allows it to boot Windows (through the NTLDR bootloader), MS-DOS, OS / 2 and other systems.
So we figured out the theory a bit (I think this will be enough), now let's look at the pitfalls when installing Dual Boot Windows and Linux on the same computer.
The experiment was carried out on a workstation with the following characteristics:
Base Board Information
- Manufacturer: Acer
- Product Name: Aspire XC600
Memory device
- Size: 4096 MB
- Type: DDR3
- Speed: 1333 MHz
- Manufacturer: Kingston
- Rank: 2
HDD
- product: ST500DM002-1BD14
- vendor: Seagate
- physical id: 0.0.0
- bus info: scsi @ 0: 0.0.0
- logical name: / dev / sda
- size: 465GiB (500GB)
- capabilities: gpt-1.00 partitioned partitioned: gpt
It has been proven that no problems installing Debian 8.6 Jessie with Windows 10 were found. Debian correctly registers at startup, GRUB starts without errors, and two OSs also work fine.
But, as practice has shown, not with all distributions this happens. When installing Ubuntu 16.04.1, instead of Debian, the first pitfall crawled out on the same workstation - GRUB did not start, and Windows 10 automatically booted.
A solution to the problem was found three to four weeks later (then I was tired of taking into account how much time was spent on solving the problem). It turned out to be unexpected, but at the same time the whole system worked. So, if you encounter the same problem, the instructions below may come in handy and save you a lot of time.
Important!Before you start executing the instructions, you need to prepare a LiveCD with the Linux Mint distribution - we will perform all operations on it (I chose this distribution because it’s easy to install Midnight Commander on it, which is difficult to do on a LiveCD with Ubuntu, so we get more space for maneuvers). It is also worth noting that the command from under the update-grub console will not help you, since it is designed for the case when GRUB is launched, but does not see other operating systems except Linux. I also recommend creating backup copies of files / directories over which you make even the slightest changes.
- Through the terminal, with root privileges, mount the partition with EFI in the / mnt folder. In my case, it was the mount / dev / sda2 / mnt command .
- Enter the sudo -s command and confirm the password (it is empty by default) for subsequent operations (many advise not to do this, but enter sudo and the command to execute - I support this opinion, but the instruction is for experienced Linux users who understand that do everything at your own peril and risk).
- Launch Midnight Commander with the mc command .
- Find the following directory in the file system: EFI in the / mnt folder.
- Rename the Microsoft directory to something else, such as Microsoft2.
- Create a new directory with the name Microsoft.
- We go into the newly created Microsoft directory and partially create inside its folder hierarchy similar to the old Microsoft (the one that was renamed). In my case, it had the following folder structure: / boot /, then a bunch of folders and the bootmgfw.efi file next to them. You need to recreate the folder structure exactly to this file. Those. everything that lies next to it is not necessary, and everything that comes to it (i.e. parent folders, neighboring ones are also not needed) is recreated in our new Microsoft folder. In my case, it was necessary to create only the / boot folder, the final path to the new directory came out like this: / EFI / Microsoft / boot. You can simply copy all the folders and files - checked, it works and you can not create everything manually.
- We find in the directory from step 6 a folder with the name of our Linux distribution, in our case it is Ubuntu. We copy (we leave the original files and the ubuntu folder just in case, they won’t hurt) all the files from this folder to the final directory created in the previous step: / EFI / Microsoft / boot.
- In the resulting file system, we find the file grubx.efi or grubx64.efi (there will be only one of them: depending on the length of installed Linux). Rename it to bootmgfw.efi.
- We 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 beginning with “chainloader” and replace this word (there should be only one occurrence and exactly in the line with “chainloader”, so you won’t be mistaken) with the name of the directory into which we renamed Microsoft ( i.e. on Microsoft2 in our example). Save the changes to the file.
Also, in this file you can change the names in the list that GRUB displays. For example, instead of openSUSE Leap 42.2 27.01 in the code part:
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 in the code.
If it’s difficult to understand the management of Midnight Commander (this is not a big deal, 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 doesn’t matter), but by starting it under as root user.
After that, we go to reboot and enjoy the result. But, as it turns out, the OpenSUSE Leap 42.2 distribution has such a problem. As practice has shown, if an OpenSUSE distribution kit with Windows 10 is installed on the computer, then 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:
- After completing all the operations, go to the / EFI / opensuse / x86_64-efi / folder (the name of the final x86_64-efi folder may be different depending on the PC architecture)
- Copy the grub.efi file (if you have the Secure Boot option enabled, there will also be a shim.efi file, then I advise you to copy them together)
- We go into the / EFI / Boot folder and delete all the files that are there (when the bootloader is updated, they will appear again, but there is nothing to worry about)
- Paste the file (or files) that we copied and calmly go to reboot.
That’s the whole instruction. I think someone will come in handy ...
PS If everything is fine with you, GRUB with OpenSUSE starts up, but does not see Windows, rejoice - the problem is solved only by one command: grub2-mkconfig -o /boot/grub2/grub.cfg , and if you have Ubuntu, you just need to do update-grub .
For those who are interested in this topic, I recommend reading the article: "GRUB 2 bootloader - a complete guide . "