GRUB2. Start

    0. What is this?


    I'll tell you about the new version of the most popular bootloader. It appeared optionally in the stable Debian 5.0 Lenny, which means we can conclude about some stability. Unfortunately, according to the developers themselves, there is no time for documentation, so everything is still working by typing, logic and comments in the code :)
    Speaking of versions. The first and so far the main branch is considered 0.9x (which has already been dubbed GRUB Legacy), and version 1.xx is officially called GRUB 2.
    So, what is the difference between this version and the good old default bootloader of everything and everything? The official website says something like this :
    • Support for scripts, in particular loops, conditions, variables and functions
    • GUI
    • Dynamic module loading, which allows expanding functionality not at the assembly stage, but right at runtime
    • Portability to different architectures
    • Internationalization
    • True memory management making GNU GRUB more flexible
    • Modular, hierarchical, object-oriented framework for file systems, files, devices, drives, terminals, commands, partition tables and loaders of operating systems
    • Cross-platform installation that allows you to install GRUB from a different architecture
    • Safe mode for difficult cases. Stage 1.5 eliminated
    • Correction of errors that were made during the design of GRUB Legacy, and could not be fixed due to backward compatibility requirements. For example, the method of numbering partitions


    As you can see, a lot of changes. Here I want to dwell on some practical points that I have encountered in my life.
    Traditionally, I warn you: I did all the work on stable Debian Lenny. Your commands or file location may differ (although it should not).

    1. How to edit the menu?


    This is a natural question when working with the bootloader. In the new version, they approached him from the other side. If you open the analogue of the old menu.lst file /boot/grub/grub.cfg, you will be surprised. The file header reads: That is, you can edit it with your hands, but this is not according to the rules. According to the rules, the menu is now automatically generated based on the scripts in /etc/grub.d and the settings from the / etc / default / grub config. Having searched for the script description, we find the file /etc/grub.d/README, which sheds a ray of light to the tricky device of the new bootloader. We will find out what the prefixes for script names are for:
    #
    # DO NOT EDIT THIS FILE
    #
    # It is automatically generated by /usr/sbin/update-grub using templates
    # from /etc/grub.d and settings from /etc/default/grub
    #




    • 00_ *: Reserved for 00_header
    • 10_ *: Boot Records
    • 20_ *: Third-party programs (e.g. memtest86 +)

    You can see the scripts themselves, written in a regular shell language. They should not cause much difficulty. These scripts simply look for compiled kernels and init.rd images in the probable directories, respectively.
    If you decide to compile the kernel yourself, everything will be extremely simple: using the appropriate manual, you will get a deb package. During installation, it will put everything in place and start the bootloader update. When the scripts work, in /boot/grub/grub.cfg there will be an updated menu with a new kernel. Without a single editing configs.

    2. Warnings.


    Now let's take a look at the other side: what bad can happen with such a scheme of work?
    • For specific kernels you need to write special scripts.
    • You don’t have to go far for an example - look at the Xen kernels. They start up slightly different from the standard ones, so the standard menu item for the Xen kernel will not launch anything good. If anyone is interested, I will write more about this. ( UPD : Wrote )
    • If you still change the menu manually due to “some kind of” scripts not working, the next time (when updating the kernel or GRUB itself) the scripts will crash with an error and the grub-pc package will be considered unconfigured. We'll have to redo everything according to the rules.
    • As mentioned above, the normal documentation is sorely lacking. You have to interrupt blog posts and wiki pages.


    3. Conclusion


    As you can see, GRUB has changed a lot. Whether we like it or not, after a while more and more developers will add it to their distributions. This means that you need to test, test and just help the community move to a new generation of bootloaders. Good luck!

    Also popular now: