ComputersOS

GRUB operating system loader: setup, description. Installing and Repairing GRUB

Not one dozen new users of operating systems, other than Windows, with a fair amount of doubt and skepticism meet the phrase "bootloader" these days. And there is an absolutely logical reason: most beginners before their transition to the use of other less common on the market operating systems in everyday life used the same Windows. In it, this loader is implemented as primitively and transparently as possible. And although this to some extent adds convenience to the average user, it also cuts the functionality of the already popular and universal OS. Therefore, all those who decided to pay attention to other products of the IT industry, you should certainly familiarize yourself with the universal loader GRU, which in the future will significantly help in working with several OS installed on one computer.

Universal tool for non-universal systems

First of all, let's start with the name GNU GRUB. This abbreviation from English GRand Unified Bootloader is translated as "the main unified loader". Its creator is the nonprofit organization "Project GNU", which became famous in the IT field with its freely distributed software. GRUB itself is essentially a menu for selecting the boot required by the user OS from a whole list of supported systems:

  • Linux.
  • FreeBSD.
  • Solaris.

In this case, GRUB can work even with Windows. However, to start such systems that are not directly supported by this bootloader, there are some special nuances that we will learn in more detail later.

The way of technology development

Continuously growing popularity of GRUB was a fundamental reason prompting to develop and improve the loader in the future. The very first version of the bootloader, called GRUB Legacy, is still doing very well with the tasks of the unified bootloader for UNIX-like systems. The wide support of serious companies (like RedHat and Novell) and server distributions provided it with a long life in general.

However, even this circumstance had absolutely no effect on the further development of the bootloader, so users got the latest version of GRUB 2 at the given time. Being rewritten from a clean string, GRUB 2 hardly has anything in common with the obsolete GRUB Legacy, except for the name itself . Today, being by default used from version 9.10 of the operating system Ubuntu, GRUB second revision due to its more advanced and powerful structure completely stopped any further development of already well-proven Legacy in the past.

However, from the very beginning, the beginner should understand that GRUB 2 is more complex than the previous version, the bootloader. Therefore, in order to protect users from possible difficulties and problems, then all the smallest details will be explained simply and in detail, understanding of which will allow full use of all innovations by the latest version, and there are quite a few of them:

  • Script support (cycles, conditions, variables and functions).
  • The graphical interface adds the possibility of flexible changes in the appearance of the loader to the user's individual taste (GRUB 2 can be easily changed from a black-and-white table to a stylish multi-colored window).
  • The ability to dynamically load modules. This will expand the functionality not at the assembly stage, but directly at runtime.
  • Compatibility with different architectures.
  • Added support for Mac OS boot.
  • Stable work with such file systems as FAT16 , FAT32 , NTFS , any version ext , XFS and ISO
  • Cross-platform type of installation will give the opportunity to install GRUB2 from a different architecture
  • Introduction of safe mode in case of problematic situations.
  • Fixed bugs from the old GRUB Legacy, which initially could not be fixed due to the requirements of backward compatibility.

Note that further under the name GRUB for convenience it will be understood exactly the version of GRUB 2, which we will understand in full for each inexperienced user.

Ever heard of LILO?

Of course, not only GRUB is limited to choosing users among the OS loaders. A similar analog is LILO, the Linux bootloader (LInux LOader), which still does not lose its relevance. However, in favor of GRUB, there are several distinctive features that the direct competitor can not yet boast of:

  • LILO supports only 16 boot configurations, when GRUB has support for an unlimited number of such configs.
  • GRUB can boot on the local network, which can not be said about LILO.
  • Finally, LILO does not have the same command interactive interface, to the convenience of which users of the latest version of GRUB have long been accustomed to.

The only common feature of both loaders is the need to compile every time you make any changes to the menu. The automatic saving function has not been available in the Linux bootloader for a long time. GRUB 2 also can not boast such a convenient feature. But even taking into account this nuance, which is inconvenient for everyday use, LILO loses to its competitor on several points, due to which it gets more and more widespread among users' home computers.

Installing GRUB: All the nuances and details of the process

From the very beginning, make sure that you have either installed Ubuntu, or there is its boot disk (LiveCD). Having started the system, it is necessary to call the terminal with the combination of keys Ctrl + Alt + F2, then register the following commands in it:

- sudo add-apt-repository ppa: cjwatson / grub,

- sudo add-get update && sudo add-get install grub2,

- sudo update-grub2.

And even if you do not have Ubuntu installed, but there is a LiveCD, then the procedure remains the same with only one tiny difference. Booting from this boot disk, select the option "Try Ubuntu" - so you start the system without any changes on your computer. After this, continue to install the GRUB loader in the same way from the terminal call phase.

You can check the installed version of the bootloader using the grub-install -v command, as well as directly at the very start of Ubuntu.

GRUB Startup Algorithm

As GRUB Install completes, the bootloader first changes the MBR code to its own. MBR is the sector containing the Master Boot Record, which contains:

  • The code of the main loader (446 bytes);
  • A table of partitions describing both the main and secondary partitions of the hard disk (64 bytes).

Due to the small volume of the MBR sector, the launch of GRUB fits into two conditional stages:

  1. The MBR contains a link to the configuration file (which can be in any hard disk, at the discretion of the user). It is for this that the entire bootstrapping stage, which begins in the second stage, will be determined.
  2. Their configuration file takes into account all the settings and data necessary for the operation of GRUB. If the configuration file was not found at the second stage, the download process will be terminated and the user will have to manually select the boot configuration from the command line.

This load structure allows GRUB to be more configurable and flexible than many other analogues, in which this process is simplified to the maximum compactness.

The most commonly used console commands

A lot of work opportunities in the console mode of the latest version of GNU GRUB, configuration and configuration options will also not leave indifferent users. In order to get into it, it is enough to press the "C" key during the display of the boot menu, after which it will only be right to enter the commands you need:

Commands Description Example input to the console
Ls A universal command for working with lists of hard disks and partitions. Can be used to display the contents of a folder. Ls / boot / grub
Its use will give complete information about absolutely any section. This will specify the type of file system on it, its label, UUID, and the date of making the latest changes.

Ls (hd *, *)

*, * - the disk number and the partition number on it, respectively

Cat Output information about the contents of a specified file. Cat / path / filename
Linux The analog of the kernel-command GRUB from the old-good version of Legacy, which allows to load the specified Linux kernel.

Linux kernel_file

Option1 = value

Option2 option3

Chainloader Transfer the load control to another loader along the chain. The loader will only be searched for in the partition that is set as root (of course, with a specific executable file).

Chainloader / path / filename

Root When using a command without any parameters, the user will receive information about the root partition, as well as the type of file system on it. Root
Less often (because of the probability of incorrect work) is used to transfer root to another partition.

Root (hd *, *)

*, * - the disk number and the partition number on it, respectively

Set Most often due to its stability and efficiency it is used to reassign the root partition on the disk.

Set root = (hd *, *)

*, * - the disk number and the partition number on it, respectively

Search

A command to search for a UUID partition, a label, or a specific file. The following keys are used to set the search parameters:

  • U (or --fs-uuid) - search for a partition by UUID;
  • L (or --label) - search by topic label;
  • F (or --file) - search for a specific file;
  • N (or --no-floppy) - skip when checking the floppy drive;
  • S (or --set) - set the found partition as the value of the specified variable.

The command is useful in case the numbering of disks and partitions "flies", because of what the set root command either leads to nowhere, or to the wrong partition of the wrong disk.

Search -u uuid_necessary_name

Search -l partition label

Search -f / path / filename

Lsfonts Displays the list of currently loaded fonts. Lsfonts
Help Used to display the entire list of available console commands. Help
Or to output commands that begin with a certain combination of characters.

Help s - output help to all commands starting with s.

Help set - Displays help about the set command.

Terminal_output.console Switch to black and white color scheme of the display. Terminal_output.console
Background_image

Change the background image in real time. Helps only in the selection of such variant of registration of fonts, so that they were distinguishable on a given background.

Note: the command does not change the settings of the design - the image remains on the background only in the current session until the next shutdown.

Background_image / path / filename

Boot Download the computer. Boot
Reboot To restart a computer. Reboot

Halt

Turn off computer. Halt

After installation GRUB: setting up and useful in the work of software

The main configuration file in GRUB2, unlike the previous version of Legacy, is not /boot/grub/menu.lst , but already /boot/grub/grub.cfg. However, directly editing it is meaningless - it will be generated with every saved change in the settings file / etc / default / grub and in the /etc/grub.d scripts directory.

In / etc / default / grub, the setting is basically limited to changing the standard boot point and / or the time for displaying the menu:

  • The GRUB_DEFAULT parameter corresponds to the first point of the changes, the value of which is indicated by the item number in the boot menu. Selecting any other item, the user should know its order from the general list (for this you need to browse the contents of /boot/grub/grub.cfg and find the required record by the account). In this case, do not forget the numbering rule: the first item is assigned the value 0, the second is assigned to 1, the third is assigned to 2, and so on.
  • For the delay in displaying the boot menu, the GRUB_TIMEOUT parameter is specified , whose quoted value indicates the number of seconds that this splash screen will appear. In editing this parameter there is one tricky feature: setting the value "-1", the splash screen will hang exactly until the user selects an item.

A set of scripts in /etc/grub.d find on the computer all the installed systems and kernels, creating a boot menu in grub.cfg. For the search for kernels and other operating systems, respectively, there are two main ones: 10_linux and 30_os-prober. The 40_custom file allows you to modify GRUB by adding your own boot items, which is useful for working with special types of system startup (note that with any changes it must end with an empty string, otherwise the last download item from all suggested will not be displayed trivially).

However, an even easier way to edit GRUB in the Ubuntu system is the Grub-Customizer utility. Due to its simplicity and intuitive interface, this is the best option for setting up the bootloader, most suitable for inexperienced beginners. To install, start the terminal (Ctrl + Alt + T), then alternately enter the following commands in it:

- sudo add-apt-repository ppa: danielrichter2007 / grub-customizer,

- sudo add-get update,

- sudo add-get install grub-customizer.

And although the translation of the program Grub-Customizer leaves much to be desired, it's very easy to understand it:

  • List configuration - menu settings when the system boots. Here, the order of its points is changed.
  • Basic settings - select the system to be loaded by default, and define the timeout.
  • Appearance - editing the external design of the boot menu.

In addition to all the variety of settings, the user should definitely pay attention to the well-proven software for working with GRUB, setting and diagnostics of which will become significantly more comfortable:

  • Super Grub Disk - a simple and convenient tool for quick recovery of the loader. At the same time, it can work not only with GRUB and LILO, but even with Windows itself. Runs from CD, flash drives or floppy disks.
  • GParted - the editor of partitions of disk partitions, which runs directly from the CD. With it, you can perform such operations with partitions and file systems on them, like: creation, deletion, resizing, checking, moving and copying.
  • SystemRescueCD is a Linux distribution that is specifically designed for disaster recovery.
  • TestDisk is a utility that allows to diagnose and restore both separate partitions and boot disks entirely.

How does the boot loader handle Windows?

Directly, unfortunately, GRUB can in no way load Windows x86 (the 64bit version is also no exception), due to which it is necessary to create an appropriate chain start mechanism. To do this, in the grub.cfg configuration file, add several lines of specific commands:

- title Windows,

- rootnoverify (hd *, *),

- makeactive,

- chainloader +1,

- boot.

An example and a detailed description of the latter was just given in the table of console commands. Now the same practical case has come, when it is useful in work. However, before it there is a couple of equally important Windows startup lines:

  • Rootnoverify (hd *, *) - the same analogue set root . It informs GRUB about the location of the partition on which the next part of the boot code resides, but does not mount it (for the clear reason that it is impossible for GRUB). Note once again that the part (hd *, *) is the disk number and partition number, respectively, on which Windows OS is installed.
  • Makeactive - the command provides the specified root partition with the bootstrap status.

Now the same command chainloader +1, which transfers all further boot control directly to the Windows loader.

Finally, the final boot command implements the start of the boot, after which you can safely run in the selected operating system.

It also happens that on the hard drive is installed not one, but two or even more versions of Windows. And then to implement a stable launch without additional hide / unhide commands is simply not feasible. The bottom line is that if in the GRUB configuration file there is a hiding of some partition of the drive, Windows will not be able to read it trivially. And if the section is visible, then it can be loaded accordingly.

If you have multiple operating systems, first determine which particular instance you want to load, then check its exact location - you need to know which partition of the hard drive it is installed on. For example, there are two different versions of Windows, located respectively on the first and second sections of the same drive, and the user needs to download the second one. To do this, enter the following changes in the menu.lst file:

- title Windows,

- hide (hd0,0),

- unhide (hd0,1),

- rootnoverify (hd0,1),

- makeactive,

- chainloader +1,

- boot.

In comparison with the previous sample code, the commands hide and unhide were added, thanks to which the user will be able to load the required operating system from a given partition of the hard disk.

Reinstalling GRUB in case of critical problems

Even in the case of technical problems, it is quite easy to restore GRUB. To start, download the installation LiveCD, open the terminal by pressing CTRL + ALT + T.

After this, we enter the following commands one by one:

  • Sudo grub-install / dev / sda - installs GRUB directly into the MBR (sda - boot disk);
  • Sudo update-grub - search for other boot records on the hard disk (for example, Windows).

Now it only remains to reboot the computer and make sure that the reinstalled bootloader is fully operational.

The issue of protection against reboot looping

The need for such a protection system integrated into the GRUB boot loader appears when the log sizes located in the / var / log directory due to uncontrolled writing of information in them grow up to unacceptable volumes. In a normally functioning system, special services are provided, archiving and wiping these logs in automatic mode. Thus, in most cases, the user absolutely does not need to spend time monitoring their volume.

However, these same services are started only after the operating system is loaded. Prior to this, the size of the log files is absolutely not monitored at all, which is why in the event of an unexpected system fall and subsequent reboots, the logs will only grow in size. And this uncontrolled growth will continue exactly as long as the reboot lasts due to a failure in the system. Subsequently, this all can lead to the full filling of the partition on which the / var / log directory is located, which is fraught with the system hang-up and can not even start the recovery mode.

It is from this catastrophic situation that the GRUB system, integrated in GRUB, protects against cyclic reboots, the output of the "hung" GRUB menu, waiting for the user's explicit intervention. The protection itself is guided by the value of the variable recordfail, which is specified in the script /boot/grub/grub.cfg. During each download, it is set as a recordfail = 1 , and at the final bootstrapping stage it is reset to recordfail = 0 . And if such a reset did not happen, automatic loading is completely prevented and the same GRUB protection is activated.

To do this, in / etc / defaul / grub we find the variable GRUB_RECORDFAIL_TIMEOUT and assign it the value in the number of seconds during which the GRUB menu will wait for user intervention if there is no reset of the recordfail from 1 to 0. Then we save the changes with the sudo update-grub command, Thereby disabling the protection from the loopback reboot.

To whom it can be useful? Only for stations and servers in which there is no keyboard for I / O information. Without it, in the case of such problems, the system can not be booted at all. Cycles of download cycling are not so common and mostly arise either because of power problems or because of software problems.

Uninstalling GRUB and returning to Windows: quickly, simply and painlessly

In case you have a question "How to remove GRUB and leave the boot loader of another operating system?", First of all the user will need its installation disk / flash drive. We'll analyze everything on a concrete simple example: the user removes Linux from his computer, leaving only Windows alone, but can not download it due to a Grub error . To completely solve the problem, you need to restore the Windows x86 / 64 bit loader:

  1. Boot from the installation drive, pre-setting it at the first priority when booting into the BIOS
  2. Booting from the installation media, select the system recovery partition.
  3. From the appeared list of tools we choose the command line, in which we will assign the following commands one by one:
  • BOOTREC.EXE / FixBoot.
  • BOOTREC.EXE / FixMbr.

Since you can uninstall GRUB for several actions, after all the successfully performed operations we reboot the computer and without any problems we work already in the Windows-system.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.unansea.com. Theme powered by WordPress.