How to install grub

How to install grub

Ubuntu Documentation

GRUB 2 is the default boot loader and manager for Ubuntu since version 9.10 (Karmic Koala). As the computer starts, GRUB 2 either presents a menu and awaits user input or automatically transfers control to an operating system kernel. GRUB 2 is a descendant of GRUB (GRand Unified Bootloader). It has been completely rewritten to provide the user significantly increased flexibility and performance. GRUB 2 is Free Software.

How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

Improvements

GRUB vs GRUB 2

The main Grub 2 configuration file, normally located in the /boot/grub folder, is grub.cfg. It is the product of various scripts and should not normally be edited directly.

grub.cfg is overwritten by certain Grub 2 package updates, whenever a kernel is added or removed, or when the user runs update-grub.

The menu list of available Linux kernels is automatically generated by running update-grub.

The user can create a custom file in which the user can place his own menu entries. This file will not be overwritten. By default, a custom file named 40_custom is available for use in the /etc/grub.d folder.

The primary configuration file for changing menu display settings is called grub and by default is located in the /etc/default folder.

Partition numbering has changed. The first partition is now 1 rather than 0. The first device/drive is still hd0 by default (no change). These designations can be altered if necessary in the device.map file in the /boot/grub folder.

Automated searches for other operating systems, such as Windows, are accomplished whenever update-grub is executed. Operating systems found will be placed in the Grub 2 menu.

Changes made in the configuration files will not take effect until the update-grub command is executed.

Upgrading to GRUB 2 From GRUB

GRUB 2 is the default bootloader for Ubuntu. Users who still have Grub 0.97 installed on their Ubuntu systems can upgrade to GRUB 2 by installing the currently-supported releases of Ubuntu or by enabling repositories which contain the GRUB 2 package grub-pc.

Please visit the Grub2/Upgrading community documentation for more information and instructions.

File Structure

GRUB 2 incorporates a totally revised directory and file hierarchy. The major GRUB 2 folders include /etc/grub.d, which contains the main GRUB 2 scripts, and /boot/grub, which contains the GRUB 2 modules and menu file (grub.cfg). User customization’s are normally made to the /etc/default/grub file.

The description of the major GRUB 2 folders and files is located on the Grub2/Setup community documentation page.

Configuring GRUB 2

Configuration changes are normally made to the /etc/default/grub file and to the custom scripts located in /etc/grub.d. No changes are made to the GRUB 2 menu until the update-grub command is run as root. This command runs the GRUB 2 configuration scripts and updates the /boot/grub/grub.cfg file.

Descriptions of the GRUB 2 options and how to change them are presented on the Grub2/Setup community documentation page.

Boot Display Behavior

GRUB 2 loads before any operating system. Its modular components are loaded on an as-needed basis. Menu display behavior is generally determined by settings in /etc/default/grub. Review the «Configuring GRUB 2» section above for specific entry and formatting guidance.

Initial Default

Timed Display

The default entry is determined by the GRUB_DEFAULT= setting in /etc/default/grub; the first «menuentry» has a value of «0».

Hidden

The time the screen remains blank but available for display is determined by a setting in /etc/default/grub (GRUB_HIDDEN_TIMEOUT)

Saved

Saving an OS can be achieved by running sudo grub-set-default if GRUB_DEFAULT=saved is set in /etc/default/grub. It may also be saved if GRUB_SAVEDEFAULT=true is also set in /etc/default/grub. In this case, the default OS remains until a new OS is manually selected from the GRUB 2 menu or the grub-set-default command is executed.

Last Boot Failed or Boot into Recovery Mode

If the last boot failed or after a boot into Recovery Mode the menu will be displayed until the user makes a selection.

For >=1, menu will display for the specified number of seconds.

Run update-grub after the change have been made.

In some cases trick with GRUB_RECORDFAIL_TIMEOUT doesn’t work. In such a case edit /etc/grub.d/00_header and change value of timeout in line 236 (this line is in the make_timeout() function)

to the the value as described above.

Run update-grub after the change have been made. Special thanks to McCunha on Ubuntu Forums for the above tip.

The above change, however, still causes GRUB2 to boot into text graphics mode. Thus, an additional change is required. Edit /etc/grub.d/10_linux and change line 188 to

Once again, run update-grub after the change has been made.

Password Protection

GRUB 2 is capable of password-protecting menu editing, access to the GRUB 2 terminal, and specific or all menu entries. It can also limit access to specific entries for specific users, and can encrypt plain-text passwords for increased security. Please refer to the Grub2/Passwords community documentation.

Custom Menu Entries

GRUB 2 allows users to create customized menu selections which will be automatically added to the main menu when sudo update-grub is executed. A 40_custom file is available in /etc/grub.d/ for use or to serve as an example to create other custom menus. Information on building and using custom menus in GRUB 2 is located in the Grub2/CustomMenus community document.

Troubleshooting

GRUB 2 provides excellent capabilities for troubleshooting and correcting boot problems from the boot menu or GRUB 2 terminal. Troubleshooting and recovery procedures are detailed in the Grub2/Troubleshooting community document which also includes a section Selected_Problems_and_Bugs.

Fixing reboot/shutdown freezes

If your machine freezes upon attempts to shutdown or reboot, try modifying /etc/default/grub. Open the file with gksudo gedit /etc/default/grub (graphical interface) or sudo nano /etc/default/grub (command-line). Any other plaintext editor (Vim, Emacs, Kate, Leafpad) is fine too. Find the line that starts with GRUB_CMDLINE_LINUX_DEFAULT and add reboot=bios to the end.

If done properly it should result in something like GRUB_CMDLINE_LINUX_DEFAULT=»quiet splash reboot=bios»

Then save the file, run sudo update-grub and reboot in any way that’s possible for you. After that, reboots and shutdowns should start working properly.

With certain hardware (notably DELL) the kernel parameter that you add needs to be reboot=pci (instead of reboot=bios), the procedure remains the same.

Displays

GRUB 2 can do more than provide a simple black & white menu. Its menu can be customized by the user to present a more visually-appealing menu by changing font colors, backgrounds and resolutions.

For information on using splash images and changing font colors and menu resolutions, please refer to the Grub2/Displays community documentation.

Themes

GRUB 2 Theming is still under development, as is integration with gfxmenu. Theme elements will include colors, fonts, progress indicators, menus, and labels. Both of these hold great promise but are not ready for release with Ubuntu 9.10. Check the Links section at the bottom of this page for references.

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    Installing/Reinstalling/Moving GRUB2

    Please visit the Grub2/Installing community documentation. Information concerning upgrades from GRUB 0.97 (Legacy) to GRUB 2 is now located at Grub2/Upgrading.

    Booting an ISO from a Menuentry

    Ubuntu ISOs, as well as many utility ISOs and some other Linux operating systems, can be booted from a hard drive via a GRUB menuentry. This eliminates the need to create a CD/DVD and allows bootable image files to be stored only on the hard drive.

    For information on this Grub 2 feature, please visit the Grub2/ISOBoot community documentation page.

    Security

    Preventing booting via Grub command-line

    The ability to manually boot using the Grub command-line constitutes the biggest security risk in Linux. Any OS can be booted in this manner from any USB or CD/DVD drive, circumventing BIOS restrictions. Placing passwords or locking menu items (in the Grub configuration files) does not prevent a user from booting manually using commands entered at the grub command-line. (Once a foreign OS is booted, of course, it can be used to access any part of an unencrypted hard drive).

    There are currently no options to prevent the command-line usage of Grub. Doing so would restrict boot-loading to just the menu options and that is not considered wise

    Miscellaneous

    Booting from a serial console

    If you want GRUB to operate over a serial line, you will need to uncomment GRUB_TERMINAL in /etc/default/grub and set it to serial (instead of the console default). Alternatively, you can add GRUB_TERMINAL=»console serial» to have the grub menu on both serial and local console. The default serial console settings are to operate on the first serial port (ttyS0) at a 9600 bit/s transfer rate with 8 data bits, 1 stop bit and no parity.

    If you want to use another serial port or if your console uses different settings, you must add a GRUB_SERIAL_COMMAND line to specify additional parameters to the serial command. The serial command in GRUB 2 uses the same syntax as its GRUB Legacy counterpart (documented here). For example, for a very common 9600 bit/s (baud) serial line with 8 data bits, 1 stop bit and no parity:

    An example is a 4800 bit/s (baud) serial line with 7 data bits, 1 stop bit and even parity:

    Booting FreeBSD, NetBSD, and chainload or multiboot OSes

    Please refer to the article Grub2OtherOs community documentation page.

    Установка загрузчика Grub

    Для инициализации ядра и запуска операционной системы Linux используется загрузчик. Это программа, которая запускается после завершения проверки оборудования BIOS, подготавливает оборудование к работе, задает нужные параметры ядра и позволяет выбрать операционную систему. Основная задача загрузчика дать пользователю выбрать операционную систему для загрузки.

    Раньше для загрузки Linux использовалось несколько загрузчиков, это isolinux, lilo, grub. Но сейчас чаще всего применяется Grub или полное его название GRand Unified Bootloader. В этой статье будет рассмотрена установка загрузчика Grub через терминал. Также мы поговорим как установить grub на компьютер с UEFI, тоже вручную.

    Немного теории

    В MBR вариантов немного, Grub записывается в область MBR на диске. Размер сектора MBR занимает первых 512 байт и этого вполне достаточно для того, чтобы установить туда загрузчик.

    GPT предоставляет более широкие возможности. Во-первых, для совместимости в GPT эмулируется сектор MBR, и мы можем установить GRUB туда, но такой вариант очень ненадежный и не рекомендуемый. Во-вторых, теперь появилась возможность устанавливать Grub на раздел диска. Мы просто создаем раздел на диске размером 1 Мб и записываем туда то, что раньше записывалось в MBR, это делает установку загрузчика более надежной и защищенной от сбоев.

    Для установки Grub будет использоваться команда grub-install, во всех случаях. Давайте кратко рассмотрим ее синтаксис и параметры. Синтаксис:

    $ grub-install опции диск

    Параметров здесь достаточно много, но нам будут нужны только некоторые:

    Основу разобрали. Теперь перейдем к установке. Дальше я буду предполагать, что все действия выполняются из системы, для которой нужно установить загрузчик или из chroot окружения этой системы.

    Установка загрузчика Grub в MBR для BIOS

    Начнем с самого просто и привычного. Данная инструкция как установить загрузчик Grub подойдет для любого дистрибутива, поскольку команды везде почти одинаковые. Здесь не нужно устанавливать никаких дополнительных пакетов или создавать разделов. Установка Grub на жесткий диск выполняется командой:

    sudo grub-install /dev/sda

    sudo grub2-install /dev/sda

    Готово. По поводу двойки здесь такое же замечание. Если вы хотите установить Grub на флешку в MBR, то тут тоже нет проблем просто примонтируйте флешку и выполните такую команду:

    Установка загрузчика Grub в GPT для BIOS

    Во-первых, мы можем ничего не менять и установить Grub так, как описано в предыдущем способе. Но тогда он будет установлен в область совместимости с MBR, а это не надежно. Поэтому рекомендуется установить grub так, как описано ниже, на отдельный раздел.

    Нужный нам раздел можно создать в установщике любого дистрибутива, если вы выполняете установку в графическом интерфейсе или с помощью gparted. Нам нужен раздел размером 1 Мегабайт без файловой системы и с меткой grub_bios:

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    Дальше примените изменения, нажмите на разделе правой кнопкой, выберите manage flags и добавьте флаг grub_bios:

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    Готово. Если у вас нет под рукой доступа к графическому интерфейсу, вы можете создать такой раздел через терминал. Утилита fdisk не поддерживает работу с gpt, поэтому будем использовать gfdisk. Сначала запустите утилиту:

    sudo gdisk /dev/sda

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    Чтобы создать новый раздел нажмите n и выберите номер раздела:

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    Соглашаемся с начальным сектором, будет использован первый же свободный:

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    Готово, осталось нажать w для записи изменений на диск:

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    Установка grub на жесткий диск дальше выполняется точно так же, как и в предыдущем способе:

    sudo grub-install /dev/sda

    Осталось создать конфигурационный файл grub:

    Теперь переходим к самому сложному, как установить grub efi.

    Установка GRUB UEFI GPT

    Установка Grub UEFI чем-то похожа на установку в GPT, тут у нас тоже будет отдельный раздел, только на этот раз не для загрузчика, а раздел EFI. Если у вас уже установлена Windows, то, скорее всего, он уже существует. Этот раздел обычно занимает 100 Мб, имеет файловую систему fat32 и флаг ESP. Вот так он будет выглядеть:

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    Если же такого раздела нет, мы можем его создать с помощью gparted. Для этого создаем раздел с такими параметрами:

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    Размер 100 Мегабайт, имя раздела ESP, файловая система fat32. Дальше примените изменения и установите для раздела флаг ESP:

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    То же самое вы можете сделать в Gdisk, только на этот раз нужно устанавливать HEX Code раздела ef00. После того как раздел был создан, подключаем его к нашей файловой системе:

    sudo mkdir /boot/efi
    $ sudo mount /dev/sda2 /boot/efi

    sudo apt install grub-efi efibootmgr

    Дальше останется только установка grub efi. Система сама определит нужный раздел и скопирует туда все файлы:

    Установка Grub efi на MBR все выглядит точно так же, только тут есть несколько ограничений. Раздел ESP нужно создавать только в начале диска. В режиме EFI тоже можно установить GRUB на флешку, и это не очень сложно. Для этого используется команда:

    Выводы

    Теперь установка Grub не вызовет у вас проблем. Мы разобрали не только как установить Grub2 в MBR но и в EFI. Кроме того, всю приведенную здесь информацию вы можете использовать для восстановления Grub. Так вы будете лучше понимать что происходит во время восстановления. А настройку параметров и ручное создание конфигурационного файла мы рассмотрим в одной из следующих статей.

    How can I reinstall GRUB to the EFI partition?

    12 Answers 12

    Boot from the Ubuntu installation medium and select ‘Try Ubuntu without installing’.
    (Boot your install medium in EFI mode, select the Ubuntu entry with UEFI in front.)

    Once you are on the Live desktop, open a terminal and execute these commands :

    Note : sdX = disk | sdXX = efi partition | sdXY = system partition

    To identify the partitions use GParted, the tool is included in the installation medium.
    After having run the commands GRUB will be installed in the separate EFI partition.

    this is the only way that worked for me: (System: sdb8, boot: sdb6, efi: sdb2)

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    This is how I did it on a standard x86_amd64 EFI desktop, without chrooting, assuming you have a partition containing Ubuntu on your hard drive and possibly an EFI partition where GRUB should be installed.

    This should give:

    Installing for x86_64-efi platform.

    Installation finished. No error reported.

    Then reboot and you should be done. You may have to tell your BIOS which drive to use, or which EFI partition to use, or which EFI binary to use.

    If you created a new EFI partition, you may have to add it to /etc/fstab to have update-grub working correctly.

    Thanks to @cl-netbox for the instructions!

    After I upgraded (Linux Mint 18.2 Sonya to 18.3 Sylvia) my system wouldn’t boot so I followed the instructions above but still no success. I noticed however that my machine has /boot in a separate partition (possibly because I am using LVM) so my slightly modified process was:

    Note : sdX = disk | sdXX = efi partition | sdXY = boot partition | sdXXX = system partition

    Also, if booting from live cd to recover it might happen that you are missing grub-efi-amd64-bin package and then line

    In this case run this outside of chroot

    and then add /usr/lib/grub/x86_64-efi to chroot mounts.

    BTW «/dev/sdb» param is obsolete and is being ignored.

    During the last months there have been some updates to the libraries involved.

    The steps below were useful for me. They took ideas from old answers as well as from other forums.

    Make sure that you booted using EFI

    Run grub-install

    Make sure that efibootmgr lists your Linux as an entry

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    If you happen to lose your EFI partition, it’s easy to get it back. You can use a partitioning tool such as fdisk or parted to create a new partition sdXY (e.g. sda1) with type «EFI partition (1)» and format it with:

    then mount it with:

    and you can reinstall GRUB by running:

    as mentioned in other solutions.

    But today I got two errors in chroot from grub2, I never experienced before :

    The zfs-fuse error seems not to matter but for Efivars I had to add one more mount :

    in addition to ci-netbox answer.
    If your pendrive OS version does not match the one that is installed on the disk, grub-install may have difficulties to identify the right grub installation:

    Try to identify manually the installation to use

    Then restart grub-install :

    Just used this tool https://help.ubuntu.com/community/Boot-Repair on Ubuntu. That was the easiest way and all was automatic.

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    The simplest for me was to use this small tool (20 Mb) that will let you boot the broken grub system (I used Ventoy to boot the tool):

    And once the tool has made its magic and booted your linux systen, do:

    I used Grub-Customizer. I know some of you don’t like this program, but in some cases it comes in very handy ( renaming Ubuntu in Kubuntu ( don’t have to do that in ‘etc/grub.d/10_Linux_Proxy’ ), add a theme, or in this case.

    And all was done.

    I don’t use Linux based OS’s that long ( 7 or 8 months now ), and if I have to write everything down to use in the command-line, it not only takes a long time ( mostly the writing down ), but I can make errors that way.

    I had my Windows Bootloader in partition 1 and grub2 in another EFI partition ( 8 )( didn’t want to mess up Windows Bootloader ), so every time I wanted to use my Kubuntu ( daily ) or Mint OS I had to press F11, wait, select USB ( don’t ask me why ), select Ubuntu, then wait again for Grub and then select my Linux based OS. Now I get Grub2 almost instantly.

    Update 211111/1135 Like Organic Marble commented ‘MBR doesn’t sound right for a UEFI system’, he is right. It worked, but only once. What I did is install Grub2Win in my Win10 installation. From Kubuntu I could export my ‘grub.conf´ to the ‘My Documents’-partition ( NTFS, so Win10 can read that ) and imported it in Grub2Win. Now it is working like it is suposed to.

    PS. I saved this page, so I know how to do it when I get rid of Windows.

    Ubuntu Documentation

    This page details the procedures for installing and reinstalling GRUB 2. The information applies to most versions of GRUB 2, but is specifically written for version 1.99. GRUB 1.99 is included on Ubuntu releases 11.04 (Natty Narwhal) and later. For more information on a variety of GRUB 2 topics, please visit the GRUB2 main page. For information on converting to or from GRUB Legacy, please view the Grub2/Upgrading community doc.

    The GRUB 2 bootloader is included on all currently-supported versions of the Ubuntu family. GRUB 2 can accomodate traditional computer firmware such as BIOS as well as the newer EFI/UEFI standards. It is compatible with MBR, GPT and other partitioning tables.

    All references to GRUB pertain to GRUB 2. Where GRUB 0.97 is discussed, it will be referred to by version number or as GRUB Legacy.

    GRUB 2 Initial Installation

    GRUB 2 installation is automatically incorporated into a normal Ubuntu installation. Input required by the user for the initial setup is very simple. If the installation will use the entire disk no specific GRUB selections are necessary. If the user wants to use a specific partition for Ubuntu the user must select the Ubuntu partition and the drive on which to embed the bootloader information.

    The main GRUB 2 folder locations include /boot/grub/ and /etc/grub.d/. User preferences are stored in the /etc/default/grub file. The GRUB 2 menu is built by information contained in /boot/grub/grub.cfg.

    Installation Options (LiveCD)

    Using the Entire Drive ( «Erase disk and install Ubuntu» ):

    Install on entire drive: The user should select a drive on which Ubuntu and GRUB 2 will be installed. GRUB 2 will overwrite the drive’s boot information and place the GRUB 2 files in the appropriate locations.

    Installing Ubuntu to a Specific Partition («Something Else»):

    When using the «Something Else» option, you will be offered to choose the «Device for bootloader installation». Please select: * either the disk (eg /dev/sdX, not /dev/sdXY) on which the BIOS is setup to boot (recommended for normal use) * OR the partition (eg /dev/sdXY, not /dev/sdX) on which Ubuntu (/boot, else /) will be installed (only if you want to chainload it from another bootloader; if any doubt, do NOT choose this)

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubNever choose any other partition! (this may break the boot of your other systems, see Bug #1049549).

    How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

    BIOS/MBR Notes

    GRUB 2 normally writes its bootloader information to an area just beyond the Master Boot Record and before the first partition. Some software on non-Linux operating systems also used this embedded area and broke the system by overwriting the GRUB 2 information on dual-boot systems. GRUB 2 now can recognize this potential problem and avoid it.

    The bootloader information does not have to be installed to the embedded area of the MBR. It may also bypass the MBR entirely and be installed to a specific partition. In doing this, the location of the GRUB 2 files are specified by using blocklists. This option is not available via an Ubuntu GUI installation but can be made via the terminal after installation. Even then this method is not as reliable as writing to the MBR and is not recommended by the GRUB developers.

    BIOS/GPT Notes

    If the BIOS is setup to boot the disk in Legacy/mbr mode, installing GRUB2 on a GPT (GUID Partition Table) disk requires a dedicated BIOS boot partition with a recommended size of at least 1 MiB. This partition can be created via GParted or other partitioning tools, or via the command line. It must be identified with a bios_grub flag. The necessary GPT modules are automatically included during installation when GRUB 2 detects a GPT scheme.

    GRUB 2 is compatible with EFI/UEFI and will load the necessary modules during installation. For information on this topic, please visit the UEFI community documentation.

    Post-Installation

    To view the GRUB 2 file system and configuration options please refer to Grub 2 community documentation page.

    Reinstalling GRUB 2

    Reinstalling GRUB 2 from a Working System

    If Ubuntu is operating normally, boot into the working installation and run the following command from a terminal.

      X is the drive (letter) on which you want GRUB to write the boot information. Normally users should not include a partition number, which would produce an error message as the command would attempt to write the information to a partition.

      This will rewrite the MBR information to point to the current installation and rewrite some GRUB 2 files (which are already working). Since it isn’t done during execution of the previous command, running sudo update-grub after the install will ensure GRUB 2’s menu is up-to-date.

      Fixing a Broken System

      If a system has become unbootable due to a GRUB 2 failure or corrupted MBR/boot sector, there are various methods for reinstalling GRUB 2. The simplest is listed first, followed by more complicated methods.

      via Boot-Repair Graphical Tool

      Boot-Repair is a GUI application which can fix a variety of GRUB 2 problems. It can be used either from a LiveCD, its own CD, or during a normal Ubuntu session. In addition to providing a simple user interface, Boot-Repair also includes the ability to run a script to gather details of the system which can be used for troubleshooting help on various forums and IRC channels.

      Please refer to the Boot-Repair community documentation for instructions on how to install and run this application.

      via GRUB2 Rescue mode

      GRUB 2 provides a rescue mode which allows the user to attempt to repair GRUB 2 from a special GRUB terminal during boot. Refer to the Grub2 Command_Line_and_Rescue_Mode section for information on GRUB terminal operations.

      via the LiveCD terminal

      This method uses the terminal from a LiveCD. The user must know the device name/partition of the installed system (sda1, sdb5, etc), which is then mounted from the LiveCD. GRUB 2 files are copied from the LiveCD libraries to the proper locations and MBR.

      This operation will write to the MBR and restore the modules and core.img to /boot/grub. It will not replace or restore grub.cfg or fix corrupted files. Boot the LiveCD, select «Try It», and open a terminal.

      How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubWhen using a LiveCD, due to GRUB 2 changes between Ubuntu releases, it is recommended that the user boots a LiveCD of the same release (11.10, 12.04, etc) as the release to be repaired. If the user has installed a different version of GRUB 2, use a LiveCD with the same GRUB 2 version.

      If necessary, use the fdisk command to help determine the partition on which Ubuntu is installed. The fdisk option «-l» is a lowercase «L». Look for one of the appropriate size or formatting. Running sudo blkid may provide more information to help locate the proper partition, especially if the partitions are labeled. The ‘

      In the following commands:

        Use the partition number of the Ubuntu installation with mount command.

        Do not use the partition number with the grub-install command.

        X is the drive letter (a, b, c, etc.); Y is the partition number (1, 5, etc).

        —boot-directory is the folder in which the GRUB folder is located. This is normally /boot but should be changed if the grub folder is located elsewhere.

        On systems with a separate /boot partition, that partition should be mounted to /mnt/boot. For instance: sudo mount /dev/sda6 /mnt/boot

        grub-install will restore missing files in the grub folder but will not restore intentionally deleted or corrupted files. To accomplish these tasks GRUB 2 must be completely removed and reinstalled.

        If Ubuntu is installed on B-tree file system i.e. btrfs then /boot changes to /@/boot in above commands such that :

        For GRUB 2 version 1.98 and earlier (Ubuntu 10.04), the installation command is slightly different. Rather than designating the —boot-directory, the switch is —root-directory. In this case, the location changes to /mnt

        If the user wishes to explore why the system failed, refer to Post-Restoration Commands section below.

        via Partition Files Copy

        This method does not work if GRUB has not already been installed, or if GRUB files have been deleted.

        How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubThis method talks about 9.10, so it may be obsolete.

        From the Places menu, select and click the partition containing your Ubuntu installation to mount it.

          Once mounted, the user should see Ubuntu system directories such as /boot

          Open a terminal by selecting Applications, Accessories, Terminal from the menu bar.

          How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

          When ready to copy the UUID/location, by highlighting it with the mouse. Paste it into the terminal by pressing the middle mouse button. If using the keyboard, use CTRL-SHIFT-arrow to select and CTRL-C to copy the location and CTRL-SHIFT-V to paste it into the terminal.

          The device/drive is designated by sdX, with X being the device designation. sda is the first device, sdb is the second, etc. For most users the MBR should be installed to sda, the first drive on their system. Example:

          If the user gets a «error: Cannot open /boot/grub/device.map» message, add the -m switch and path to the device.map to the command as follows: Example:

          Refresh the GRUB 2 menu with sudo update-grub

          If the user wishes to explore why the system failed, refer to Post-Restoration Commands section below.

          How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubDisk Utility, introduced in Ubuntu 9.10, can easily assign labels to existing partitions. Access Disk Utility from the System, Administration menu or DASH.

          via ChRoot

          Assuming the normal system partition(s) are on a software RAID (otherwise skip this step): make sure the mdadm tools are installed in the Live CD environment (e.g. by executing sudo apt-get install mdadm). Then assemble the arrays:

          If using bcache:

          Determine your normal system partition. The following commands may be helpful. The fdisk switch is a lowercase «L».

          Example 1: sudo mount /dev/sda1 /mnt

          Example 2: sudo mount /dev/md1 /mnt

          Only if you have a separate boot partition (where sdXY is the /boot partition designation):

            Example 1: sudo mount /dev/sdb6 /mnt/boot

            Example 2: sudo mount /dev/md0 /mnt/boot

            Reinstall GRUB 2 (substitute the correct device with sda, sdb, etc. Do not specify a partition number):

            If the system partitions are on a software RAID install GRUB 2 on all disks in the RAID. Example (software RAID using /dev/sda and /dev/sdb):

            Recreate the GRUB 2 menu file (grub.cfg)

            Boot repair after a Windows Upgrade on Ubuntu 14.04 (non-RAID)

            sudo mount /dev/sdXY /mnt [where sdXY has previously been identified using gparted]

            sudo chroot /mnt

            sudo grub-install /dev/sdX [note this is sdX not sdXY!]

            Purging & Reinstalling GRUB 2

            The difference between using the grub-install command and purging & reinstalling GRUB 2 is that the latter completely removes all GRUB 2 files and system settings. Purging GRUB 2 is also a method to reset all configuration settings to the default values on a working system. This may correct GRUB 2 failures due to corrupted files and improper configurations as well as for missing folders/files deleted by the user. The GRUB 2 packages removed and reinstalled via this procedure include grub-pc, grub-common and, in Grub 1.99 and later, grub-gfxpayload-lists.

            How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubDuring this operation the user will be temporarily left with no bootloader. Ensure you have a working Internet connection and access to the repositories before purging the GRUB 2 packages.

            This procedure can be accomplished very simply via Boot-Repair, or via the terminal procedure below.

            Remark: the Boot-Repair procedure will also remove custom files that may block the boot. It is also able to purge and reinstall GRUB2 for UEFI / LVM / RAID systems.

            via Boot-Repair Graphical Tool

            via Terminal Commands

            The commands from a working Ubuntu installation or once within the ChRoot of a LiveCD are the same.

              If using the LiveCD, complete the steps up to and including the sudo chroot command (Step 9) in the previous section.

              The following command will completely remove grub-pc and grub-common. In GRUB 1.99 and later, grub-gfxpayload-lists will also be removed.

                If using the ChRoot procedure, Exit chroot then continue the ChRoot procedure at Step 13:

                Post-Restoration Commands

                Once the user can boot to a working system, the following commands may prove useful in locating and/or fixing the problem.

                  To refresh the available devices and settings in /boot/grub/grub.cfg

                    sudo update-grub

                    To look for the bootloader location.

                      To install GRUB 2 to the sdX drive’s MBR or boot sector (sda, sdb, etc.)

                        sudo grub-install /dev/sdX

                      Moving GRUB 2

                      The command to change the GRUB 2 installation device or boot files is grub-install run as root. This command allows the user to modify the installation by setting the ROOT directory, preload modules, run specific setup files and more. When executed, grub-install may run one or more other commands, such as grub-probe, grub-mkimage, and grub-setup. Here are some considerations when running grub-install:

                        If only the device is specified (sda, sdb, etc), the boot information will be written to the specified device’s boot record. (example: sudo grub-install /dev/sda )

                        If the —boot-directory= switch is used, the grub folder will will become a subfolder of the location specified. The —boot-directory switch is available in GRUB 1.99 and later.

                        If the user attempts to run the command with a specific partition (example: sudo grub-install /dev/sda6 ) a warning will be issued. Specifying a partition is not recommended due to the use of blocklists, which the developers consider unreliable. An option is provided on how to override this recommendation if the user still wishes to do so.

                        An alternative command to install or move GRUB 2 from a particular device is to use the dpkg-reconfigure command. As the command runs, the user will be offered the opportunity to add kernel options on the first page and to specify the devices/drives on the second screen. Use the TAB key to highlight OK and press ENTER to continue.

                          Add the desired kernel options (such as ‘noapic’), TAB to OK when finished, and press ENTER.

                          Select the drive(s) with the SPACEBAR. It is not recommended to select any partition. TAB to OK when finished and press ENTER.

                          GRUB Legacy Upgrades and Downgrades

                          For information on how to switch from GRUB Legacy to GRUB 2, or from GRUB 2 to GRUB Legacy, please refer to the Grub2/Upgrading community documentation.

                          How to install grub

                          GRUB (GRand Unified Bootloader) is a boot loader. The current GRUB is also referred to as GRUB 2. The original GRUB, or GRUB Legacy, corresponds to versions 0.9x. This page exclusively describes GRUB 2.

                          Contents

                          UEFI systems

                          Installation

                          First, install the packages grub and efibootmgr : GRUB is the bootloader while efibootmgr is used by the GRUB installation script to write boot entries to NVRAM.

                          Then follow the below steps to install GRUB to your disk:

                          Remember to #Generate the main configuration file after finalizing the configuration.

                          BIOS systems

                          GUID Partition Table (GPT) specific instructions

                          On a BIOS/GPT configuration, a BIOS boot partition is required. GRUB embeds its core.img into this partition.

                          This partition can be in any position order but has to be on the first 2 TiB of the disk. This partition needs to be created before GRUB installation. When the partition is ready, install the bootloader as per the instructions below.

                          The space before the first partition can also be used as the BIOS boot partition though it will be out of GPT alignment specification. Since the partition will not be regularly accessed performance issues can be disregarded, though some disk utilities will display a warning about it. In fdisk or gdisk create a new partition starting at sector 34 and spanning to 2047 and set the type. To have the viewable partitions begin at the base consider adding this partition last.

                          Master Boot Record (MBR) specific instructions

                          Usually the post-MBR gap (after the 512 byte MBR region and before the start of the first partition) in many MBR partitioned systems is 31 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding GRUB’s core.img (FS#24103). It is advisable to use a partitioning tool that supports 1 MiB partition alignment to obtain this space as well as to satisfy other non-512-byte-sector issues (which are unrelated to embedding of core.img ).

                          Installation

                          Install the grub package. (It will replace grub-legacy AUR if that is already installed.) Then do:

                          See grub-install(8) and GRUB Manual for more details on the grub-install command.

                          Configuration

                          On an installed system, GRUB loads the /boot/grub/grub.cfg configuration file each boot. You can follow #Generated grub.cfg for using a tool, or #Custom grub.cfg for a manual creation.

                          Generated grub.cfg

                          This section only covers editing the /etc/default/grub configuration file. See GRUB/Tips and tricks for more information.

                          Generate the main configuration file

                          If you have not done additional configuration, the automatic generation will determine the root filesystem of the system to boot for the configuration file. For that to succeed it is important that the system is either booted or chrooted into.

                          Use the grub-mkconfig tool to generate /boot/grub/grub.cfg :

                          By default the generation scripts automatically add menu entries for all installed Arch Linux kernels to the generated configuration.

                          To automatically add entries for other installed operating systems, see #Detecting other operating systems.

                          See #Boot menu entry examples for custom menu entry examples.

                          Detecting other operating systems

                          To have grub-mkconfig search for other installed systems and automatically add them to the menu, install the os-prober package and mount the partitions from which the other systems boot. Then re-run grub-mkconfig. If you get the following output: Warning: os-prober will not be executed to detect other bootable partitions then edit /etc/default/grub and add/uncomment:

                          Windows

                          For Windows installed in UEFI mode, make sure the EFI system partition containing the Windows Boot Manager ( bootmgfw.efi ) is mounted. Run os-prober as root to detect and generate an entry for it.

                          For Windows installed in BIOS mode, mount the Windows system partition (its file system label should be System Reserved or SYSTEM ). Run os-prober as root to detect and generate an entry for it.

                          How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubThis article or section is out of date.How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

                          Additional arguments

                          It is not necessary to use both, but can be useful. For example, you could use GRUB_CMDLINE_LINUX_DEFAULT=»resume=UUID=uuid-of-swap-partition quiet» where uuid-of-swap-partition is the UUID of your swap partition to enable resume after hibernation. This would generate a recovery boot entry without the resume and without quiet suppressing kernel messages during a boot from that menu entry. Though, the other (regular) menu entries would have them as options.

                          How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubThis article or section is a candidate for merging with #Installation.How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

                          If you use LVM for your /boot or / root partition, make sure that the lvm module is preloaded:

                          How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubThis article or section is a candidate for merging with #Installation.How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

                          GRUB provides convenient handling of RAID volumes. You need to load GRUB modules mdraid09 or mdraid1x to allow you to address the volume natively:

                          For example, /dev/md0 becomes:

                          whereas a partitioned RAID volume (e.g. /dev/md0p1 ) becomes:

                          To install grub when using RAID1 as the /boot partition (or using /boot housed on a RAID1 root partition), on BIOS systems, simply run grub-install on both of the drives, such as:

                          Encrypted /boot

                          To enable this feature encrypt the partition with /boot residing on it using LUKS as normal. Then add the following option to /etc/default/grub :

                          Without further changes you will be prompted twice for a passphrase: the first for GRUB to unlock the /boot mount point in early boot, the second to unlock the root filesystem itself as implemented by the initramfs. You can use a keyfile to avoid this.

                          LUKS2

                          GRUB 2.06 has limited support for LUKS2. See GRUB bug #55093.

                          Use grub-install as described in the #Installation section. However, the generated EFI binary does not support LUKS2 and needs to be replaced.

                          Add lvm if you use LVM. Replace ext2 by btrfs if needed:

                          Custom grub.cfg

                          How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubThis article or section needs expansion.How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

                          This section describes the manual creation of GRUB boot entries in /boot/grub/grub.cfg instead of relying on grub-mkconfig.

                          A basic GRUB config file uses the following options:

                          Boot menu entry examples

                          For tips on managing multiple GRUB entries, for example when using both linux and linux-lts kernels, see GRUB/Tips and tricks#Multiple entries.

                          GRUB commands
                          «Shutdown» menu entry
                          «Restart» menu entry
                          «UEFI Firmware Settings» menu entry
                          EFI binaries

                          When launched in UEFI mode, GRUB can chainload other EFI binaries.

                          UEFI Shell

                          You can launch UEFI Shell by placing it in the root of the EFI system partition and adding this menu entry:

                          gdisk
                          Chainloading a unified kernel image

                          If you have a unified kernel image generated from following Secure Boot or other means, you can add it to the boot menu. For example:

                          Dual-booting
                          GNU/Linux

                          Assuming that the other distribution is on partition sda2 :

                          Alternatively let GRUB search for the right partition by UUID or file system label:

                          When choosing this entry, GRUB loads the grub.cfg file from the other volume and displays that menu. Any environment variable changes made by the commands in file will not be preserved after configfile returns. Press Esc to return to the first GRUB menu.

                          Windows installed in UEFI/GPT mode

                          This mode determines where the Windows bootloader resides and chain-loads it after GRUB when the menu entry is selected. The main task here is finding the EFI system partition and running the bootloader from it.

                          Alternatively one can run blkid (as root) and read the UUID of the EFI system partition from there.

                          Windows installed in BIOS/MBR mode

                          For Windows Vista/7/8/8.1/10:

                          Using labels

                          Then, add an entry using labels. An example of this:

                          Using the command shell

                          GRUB offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the «normal» shell:

                          If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the «rescue» shell:

                          The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the «normal» module, then starting the «normal» shell:

                          Pager support

                          GRUB supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB command shell type:

                          Using the command shell environment to boot operating systems

                          The GRUB’s command shell environment can be used to boot operating systems. A common scenario may be to boot Windows / Linux stored on a drive/partition via chainloading.

                          Chainloading means to load another boot-loader from the current one, ie, chain-loading.

                          The other bootloader may be embedded at the start of a partitioned disk (MBR), at the start of a partition or a partitionless disk (VBR), or as an EFI binary in the case of UEFI.

                          Chainloading a partition’s VBR

                          For example to chainload Windows stored in the first partition of the first hard disk,

                          Similarly GRUB installed to a partition can be chainloaded.

                          Chainloading a disk’s MBR or a partitionless disk’s VBR

                          Chainloading Windows/Linux installed in UEFI mode

                          insmod fat is used for loading the FAT file system module for accessing the Windows bootloader on the EFI system partition. (hd0,gpt4) or /dev/sda4 is the EFI system partition in this example. The entry in the chainloader line specifies the path of the .efi file to be chain-loaded.

                          Normal loading

                          Using the rescue console

                          See #Using the command shell first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.

                          Before starting, the user must know the location of their /boot partition (be it a separate partition, or a subdirectory under their root):

                          where X is the physical drive number and Y is the partition number.

                          To expand console capabilities, insert the linux module:

                          This introduces the linux and initrd commands, which should be familiar.

                          An example, booting Arch Linux:

                          With a separate boot partition (e.g. when using UEFI), again change the lines accordingly:

                          After successfully booting the Arch Linux installation, users can correct grub.cfg as needed and then reinstall GRUB.

                          To reinstall GRUB and fix the problem completely, changing /dev/sda if needed. See #Installation for details.

                          GRUB removal

                          How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubThis article or section needs expansion.How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

                          In general, in order to remove grub, one has to do the installation steps in reverse order. Perhaps cleaning any left over at the end. However, before doing anything, one has to decide if, and how, the machine will boot after the removal. Assuming one removes grub because they would like to use another boot loader, a safe, though a bit difficult, method is to make sure the other boot loader is working before removing grub.

                          In any case, even when removing grub before installing another boot loader, for the UEFI case, run

                          And verify the other boot loader is listed in the BootOrder line. If grub was not removed, the other boot loader should be listed before grub. If grub is already removed, grub should not be mentioned in that line. But note this is only a necessary, but not sufficient, condition for the machine to boot with the other boot loader. Neither it is a sufficient condition for the full removal of grub.

                          grub-install creates the /boot/grub directory that needs to be removed manually. Though some users will want to keep it, should they want to install grub again.

                          After migrating to GPT/UEFI one may want to remove the MBR boot code using dd:

                          Troubleshooting

                          How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubThis article or section is a candidate for merging with GRUB/Troubleshooting.How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

                          Unsupported file systems

                          In case that GRUB does not support the root file system, an alternative /boot partition with a supported file system must be created. In some cases, the development version of GRUB grub-git AUR may have native support for the file system.

                          While GRUB supports F2FS since version 2.0.4, it cannot correctly read its boot files from an F2FS partition that was created with the extra_attr flag enabled.

                          Enable debug messages

                          msdos-style error message

                          This error may occur when you try installing GRUB in a VMware container. Read more about it here. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read #Master Boot Record (MBR) specific instructions

                          Common installation errors

                          Create a GRUB entry in the firmware boot manager

                          How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grubThis article or section needs expansion.How to install grub. Смотреть фото How to install grub. Смотреть картинку How to install grub. Картинка про How to install grub. Фото How to install grub

                          grub-install automatically tries to create a menu entry in the boot manager. If it does not, then see UEFI#efibootmgr for instructions to use efibootmgr to create a menu entry. However, the problem is likely to be that you have not booted your CD/USB in UEFI mode, as in UEFI#Create UEFI bootable USB from ISO.

                          Drop to rescue shell

                          If GRUB loads but drops into the rescue shell with no errors, it can be due to one of these two reasons:

                          GRUB UEFI not loaded

                          An example of a working UEFI:

                          If the screen only goes black for a second and the next boot option is tried afterwards, according to this post, moving GRUB to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for GRUB should look like this then:

                          Default/fallback boot path

                          Some UEFI firmwares require a bootable file at a known location before they will show UEFI NVRAM boot entries. If this is the case, grub-install will claim efibootmgr has added an entry to boot GRUB, however the entry will not show up in the VisualBIOS boot order selector. The solution is to install GRUB at the default/fallback boot path:

                          Alternatively you can move an already installed GRUB EFI executable to the default/fallback path:

                          Invalid signature

                          If trying to boot Windows results in an «invalid signature» error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move GRUB’s device configuration and let it reconfigure:

                          Boot freezes

                          If booting gets stuck without any error message after GRUB loading the kernel and the initial ramdisk, try removing the add_efi_memmap kernel parameter.

                          Arch not found from other OS

                          Warning when installing in chroot

                          When installing GRUB on a LVM system in a chroot environment (e.g. during system installation), you may receive warnings like

                          This is because /run is not available inside the chroot. These warnings will not prevent the system from booting, provided that everything has been done correctly, so you may continue with the installation.

                          GRUB loads slowly

                          GRUB can take a long time to load when disk space is low. Check if you have sufficient free disk space on your /boot or / partition when you are having problems.

                          error: unknown filesystem

                          GRUB may output error: unknown filesystem and refuse to boot for a few reasons. If you are certain that all UUIDs are correct and all filesystems are valid and supported, it may be because your BIOS Boot Partition is located outside the first 2 TiB of the drive [1]. Use a partitioning tool of your choice to ensure this partition is located fully within the first 2 TiB, then reinstall and reconfigure GRUB.

                          This error might also be caused by an ext4 filesystem having unsupported features set:

                          grub-reboot not resetting

                          Old BTRFS prevents installation

                          Windows 8/10 not found

                          A setting in Windows 8/10 called «Hiberboot», «Hybrid Boot» or «Fast Boot» can prevent the Windows partition from being mounted, so grub-mkconfig will not find a Windows install. Disabling Hiberboot in Windows will allow it to be added to the GRUB menu.

                          VirtualBox EFI mode

                          For VirtualBox Device /dev/xxx not initialized in udev database even after waiting 10000000 microseconds

                          You may need to provide /run/lvm/ access to the chroot environment using:

                          GRUB rescue and encrypted /boot

                          When using an encrypted /boot, and you fail to input a correct password, you will be dropped in grub-rescue prompt.

                          This grub-rescue prompt has limited capabilities. Use the following commands to complete the boot:

                          See this blog post for a better description.

                          GRUB is installed but the menu is not shown at boot

                          Источники информации:

                          Добавить комментарий

                          Ваш адрес email не будет опубликован. Обязательные поля помечены *