banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

Boot Up With Grub2


by Peter Kelly (critter)

Introduction

When you turn on your computer to start up an operating system, the process is handled by a program known as a boot loader. The PCLinuxOS distribution of Linux uses a boot loader known as Grub (Grand Unified Bootloader) from the GNU Project. This has worked just fine for many years and has proved itself to be both a reliable and effective method of starting up the system.

The default version of this program used by PCLinuxOS is version 0.97, which is no longer actively maintained and has had to have several patches applied to enable it to keep up with recent developments in hardware, software and firmware. To overcome these obstacles and any future restrictions, a new system has been written from the ground up which is quite a lot different in use from the original. To distinguish between the two versions, it is common to refer to the original as grub-legacy and the new version as grub2.

Many distributions have now switched over to Grub2 and, despite the initial uptake being rather slow and cautious, it now dominates the Linux distribution scene. Although grub-legacy still performs its function for PCLinuxOS, its days are numbered, at least as a preferred application.

With grub2 reaching full version 2.00 status (some distributions adopted it as early as V.1.97 I think, which is considered by many to denote a sort of V.2 'beta' release), Texstar (PCLinuxOS' lead developer) has introduced it to the repositories as an option. The inclusion of Grub2 in the repository occurs perhaps with just a little reticence, judging by a comment he made on twitter. Meanwhile, the plans are to keep grub-legacy as the distribution default.

I liked grub-legacy and understood its operation quite well, which enabled me to always get to a bootable system no matter how much I abused my system with partition changes and installations of other 'distros'. There are many PCLinuxOS users who feel strongly about the transition and at first glance, Grub2 does seem to be alien and unfriendly. I believe that moving to Grub2 is inevitable, and therefore, I decided that rather than take a Luddite approach, I would meet the beast head on. The outcome? I like it, I really do. It is not unfriendly, although it is capable of some rather advanced tricks if you want to use them. It is very, very customisable -- much more so than its predecessor. If you like eye candy, you'll love Grub2.

The recommended method of booting PCLinuxOS is still grub-legacy, so if you decide to try Grub2, then you may get little support from the forum if something goes wrong. You should not, therefore, try this on a production machine. I used a virtual-box installation for my trials, but have now switched over to Grub2 on all of my machines, after a full system backup.


Installation

Installation is, like anything released by Texstar to the repositories, simple and functional. You should also install the grub2-theme-pclinuxos package to get a flavour of the theming capabilities in Grub2. There are two versions of Grub2 in the repositories, grub2 and grub2-efi. As I don't have any systems that need efi support, I can't comment on the second one, but I would expect that if it made it to the repository, then it will work just fine.

Grub2 should preferably be installed to the Master Boot Record (MBR) of the boot drive. Although it is possible to install it to a partition, this is discouraged. I mean here the core boot image, not the grub configuration files, which will normally be stored in the /boot directory. With the packages installed from the PCLinuxOS repositories, the MBR will still contain grub-legacy code and this must be over-written with grub2 code by using, as root, the command

grub2-install /dev/sda

Replace /dev/sda with the destination of the drive that you use to boot from. This will hopefully terminate with the message

Installation finished. No error reported.

Follow this with the command

update-grub2

Which will generate output similar to this:

Generating grub.cfg...
Found theme: /boot/grub2/themes/pclinuxos/theme.txt
Found linux image: /boot/vmlinuz-3.15.7-pclos1
Found initrd image: /boot/initrd-3.15.7-pclos1.img
Found linux image: /boot/vmlinuz-3.14.5-pclos2
Found initrd image: /boot/initrd-3.14.5-pclos2.img
Found linux image: /boot/vmlinuz-3.14.4-pclos2
Found initrd image: /boot/initrd-3.14.4-pclos2.img
done

The actual output will depend upon your installation, but here grub has found the theme files, three kernels, and their respective initrd.img files, so things are looking good. A reboot shows this.



Here we can see the nice theme that Tex has provided, and we can select to boot from any of the three kernels displayed.

Now, that wasn't too unfriendly, was it?

The graphic appearance of a screen is a rather subjective thing, and the one above may not be to your taste. Fortunately with Grub2, this is easy to change. I will show you several ways to accomplish this using a simple text editor and your favourite graphics utility.You don't even need any artistic ability, just common sense.

To get started I'll adjust a few colors. I find the lower two options difficult to read with my poor old eyes, so I am going to apply a few tweaks. The file that I am going to edit is

/boot/grub2/themes/pclinuxos/theme.txt

This file is owned by root, and as an ordinary user I am not allowed to edit it. I must do this as root. Be sure to first make a backup of the file. This is only the theme, nothing that will hurt the system, and in the worst case, you could simply re-install the theme package from the PCLinuxOS repository.

I tend to use the command line a lot but if you are more comfortable using graphical applications, then most of the editing that follows can be done from your file manager by right clicking the file, then choosing the option 'open as administrator.' If you are unsure about doing this, then you should seek assistance as we are soon going to be working with some system files that control how, and more importantly if, your system boots up.

Even if you are confident editing system files, practicing in a VirtualBox environment is a good idea when you first start out.

As root:

cd /boot/grub2/themes/pclinuxos
cp theme.txt theme.txt.bak

This puts you in the theme directory where the only files are theme files, not system critical files (pclinuxos is the name of this theme), and then makes a backup copy of the Grub configuration file. Next, I need to open the file in a text editor. Use whatever you are comfortable with: vim, nano or a graphical one such as Kate. As I am using the mate DE, I shall use the Pluma text editor.



Scroll down to the section named boot_menu, and change the font name in selected_item_font from DejaVu Sans Regular 14 to DejaVu Sans Bold 14. Next, change selected_item_color from #ffffff to #00008a, and then add a new line item_color #ffffff.

Save the modified file and close the editor.

To change the background color of the boot menu, we need to use a graphics editor to modify the file boot_menu_c.png. This file is used to fill the working area of the boot menu. I use GIMP for this, but again, I would make a backup of the original file.

cp boot_menu_c.png boot_menu_c.png.bak
gimp boot_menu_c.png



The image is only one pixel square, so you will have to zoom in to see it. That's the 5 key in Gimp. Using the Bucket Fill tool, change the color of the image. Overwrite the original .png file (that's why I made the copy). Reboot to see the effect.



That is how easy it is to change some of the elements of a theme: however, if you want to do more, then read on.

You do not need to use a theme to decorate the Grub2 menu screen, although there are many themes available for download that you may use or modify as shown. Grub2 allows you to apply background images and cosmetic changes at a very basic level. Themes are much more powerful, though.

To display a background image in Grub2 without using a theme is quite simple. There are a couple of ways to accomplish it, but the preferred way is simple enough, so I will stick to that. Edit the following file (as root)

/etc/default/grub

Locate or add a line that sets a grub parameter to the full pathname of your file like this:

GRUB_BACKGROUND=/boot/grub2/my_background.png

Files need to be .png, .jpg or .tga format. If the /etc/default/grub file contains a line pointing to a theme file, then comment it out like this:

# GRUB_THEME=/boot/grub2/themes/pclinuxos/theme.txt

Save the file, and then run the following command as root

update-grub2

This command must be executed every time you make some changes so that the configuration files can be re-generated.

Other features, such as fonts, can be changed in a similar manner by editing the /etc/default/grub file. That's what it is for.

If you prefer to go along the theme route, then the documentation in the manual is quite good. However, I find it a lot easier to take an existing theme and modify it, retaining any references to the previous developer(s) of the original.

A theme comprises two parts, the text or script that describes the positioning and properties of the graphical elements and the graphics themselves. Most of the usual graphical elements are supported including text labels, images and progress bars, but Grub2 makes use of so-called 'styled boxes' to display some graphic components. A styled box consists of 9 divisions or slices, a central slice and 8 peripheral slices sited at, and named after, the compass points: N, S,W,E,NW, NE, SW, and SE. Styled boxes are used to display the boot menu, the horizontal progress indicator, the slider and the slider thumb, although not all slices need to be used to display an element. The four corner slices are not scaled, but the cardinal slices, (N, S, E, and W) which will normally require only a dimension of one pixel in the scaling direction, will be scaled or stretched to fill the gap between the corners. The central slice is a fill slice that will occupy all of the space inside the other slices, and is typically one pixel square. The slider thumb is an example of an exception to this general rule comprising of only the north, south and central slices, with the latter being the full width of the other slices. See the diagram below of a styled box for a boot menu named 'bm.'



If you would prefer to display a circular progress indicator, then you will need to supply two graphics, a center graphic and a tick graphic. The center image will be displayed centrally within the bounds of its left, top, width and height properties but will be not be scaled to fit that space. Therefore, the values should be selected to wholly contain the center graphic. The tick graphic will be used to update the progress along the circumference of the indicator, and this will be neither scaled or rotated, and so should be drawn so that the lack of rotation is not detrimental. The circular progress element has the following properties that should be set in its definition:

left
top
width
height
id = "__timeout__" This parameter ties the indicator to the GRUB_TIMEOUT value.
center_bitmap
tick_bitmap
num_ticks
start_angle
ticks_disappear

The last three need a little explanation. num_ticks is the total number of ticks that will be drawn to make a full circle, and start_angle is the angle to start drawing, measured from the positive x-axis clockwise. Seems simple, eh! Hold on there, not so fast. The angle is measured in parrots. At least that's what they are called on one website I visited, and while the definition given there seems accurate, this is a unit I have never before heard of. True or false, I like the idea, so I shall call them parrots. A parrot is apparently 1/256 of a full circle, so that to start at top-dead-center (12 o'clock), you would need to supply a value of -64. Knowing this, life becomes simple again.

Normally, the ticks are progressively drawn to complete the circle. Setting ticks_disappear to true starts with a full set of ticks, and it slowly wipes them out until none remain.





I have found Inkscape to be extremely useful for creating theme graphics, as you have complete control over pixel size and position. The four corners of a styled box can be created by using a combination of rotation and reflection, and the side slices made by selecting a single row of pixels from each of the corner slices.

The naming of the individual slices is important, and they are called from the script with a single line, such as:

menu_pixmap_style="bm_*.png"

Items to appear on the boot screen are defined by type, properties and content. For example, an image to be displayed might be defined as:



These definitions are collected together in horizontal, vertical or rectangular 'canvas' containers in the script. This controls the layout of the boot screen. In the PCLinuxOS theme the rectangular container 'canvas' is used to hold all of the boot menu items which are positioned relative to the bounds of the container. Every item defined between the first brace of the canvas definition and the closing brace of that definition will be contained within the boundaries of the canvas. Items outside of that definition may appear elsewhere on the screen.

To create my new theme, I made a copy of the PCLinuxOS theme, gave it the catchy title of pclinuxos2, and then changed the entry in /etc/default/grub to point to that theme.

I prefer a lighter, uncomplicated theme that allows me to concentrate on the business at hand, which is simply to choose an operating system to boot into. Geometry, particularly circles, can become distorted by different screen aspect ratios, so I looked for either an abstract design or something fairly linear. I finally settled on a beach scene. After an hour or so in GIMP, I had mangled the original graphics to fit my design (which I previously drafted in Inkscape to get the positional data).

In order to get the menu items to display an associated icon, one line in each stanza must be edited to contain a statement such as

--class os-name

where os-name is the name of the operating system. This should also be the first --class statement on the line. There must also exist in /boot/grub2/themes/theme-name/icons an icon with the corresponding 'os-name.png' type name, such as pclinuxos.png or, if you really must, windows.png.

That just left me the theme.txt script to re-arrange. The result is shown below.



What! No MS Windows?

Want to add some graphics to it? No problem, simply add a definition or two at the end of the theme.txt script, or in the appropriate place. The images should be in the theme directory, or the full path given.



Don't forget to execute

update-grub2

Then reboot.



This was my re-worked theme.txt script. Note that the image bug.png has been replaced by a block of boot menu background color to repaint the missing progress bar after a visit to the command line. The rest you should be able to figure out for yourself.







Operation

This text describes grub version 2.00 under PCLinuxOS as displayed by the command

grub2-install -v

There may be small differences in other versions or other distributions implementations.

Note: from the manual we are advised - "Currently autogenerating config files for multi-boot environments depends on os-prober and has several shortcomings. Fixing it is scheduled for the next release."

This may obsolete some of the following methods, but the principles of booting a system remain the same. Keeping a backup copy your grub.cfg file, and using the information that follows, should enable you to recover from most situations.

If ever we have a problem with booting, we need to know the basics of how Grub2 operates and is configured, as this differs greatly from the old grub-legacy where you, or the system administrator, wrote the commands and boot stanzas in a text file saved as

/boot/grub/menu.lst.

The configuration files are now found in three places:

  • The file /etc/default/grub is used to set certain grub2 parameters which control the default operation of Grub2. This also the place to change your theme if you have more than one.

  • The directory /boot/grub2 holds files and directories for use by Grub2 during the boot process. The file grub.cfg should not be edited by users although it is safe to do so. This file is automatically generated by the update-grub2 command, which runs a series of executable scripts stored in the directory /etc/grub.d. Therefore, any changes that you make by editing this file will be overwritten the next time the system is updated by the update-grub2 command. The file is quite complex and difficult to follow, even for experienced script hackers, so is best left alone. Changes should instead be made by editing the scripts in /etc/grub.d. This is not as difficult as it sounds, and there are a few cheats that you can use to make life easier.

  • The scripts used to generate the /boot/grub2/grub.cfg configuration file are stored in the directory /etc/grub.d. Each of the executable scripts are run in turn (sorted in shell expansion order so 20_linux_xen is executed before 20_ppc_terminfo), and their output is put into the file /boot/grub.cfg. At the time of writing, this directory contains the following files:

00_header
10_linux
20_linux_xen
20_ppc_terminfo
30_os-prober
40_custom
41_custom
90_persistent
93_memtest
README

When you are used to the /etc/boot/grub/menu.lst configuration file of grub-legacy and you first see a grub.cfg for Grub2, you will be appalled. It is horrible. Only masochists would want to write this stuff. Well, good for them. Happily, we don't have to since the update-grub2 utility will write them for us. We can make use of some of the stuff in here though, even if we don't understand how it works.

The /etc/default/grub file as installed by PCLinuxOS looks like this.

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash=silent"
GRUB_DISABLE_OS_PROBER=false
GRUB_DISABLE_RECOVERY=true
GRUB_TERMINAL_OUTPUT=gfxterm
GRUB_DISABLE_SUBMENU=y
GRUB_DISTRIBUTOR=PCLinuxOS
GRUB_GFXMODE=1024x768
GRUB_GFXPAYLOAD_LINUX=keep
GRUB_TIMEOUT=10
GRUB_THEME=/boot/grub2/themes/pclinuxos2/theme.txt

So, let's look at a line by line explanation:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash=silent"

This is a list of arguments to be appended to the Linux kernel line. In grub-legacy, we used to write these on the kernel line of each stanza. But, in Grub2 this will be done for us. Just add any kernel parameters that you need to this one place.

GRUB_DISABLE_OS_PROBER=false

If this is set to false, as it is here, then when the update-grub2 command is issued, Grub2 will use the os-prober utility to look for other operating systems, and then add them to grub.cfg to be displayed in the menu. More correctly, the script /etc/grub.d/30_os-prober will be executed (if it has execute permissions set).

GRUB_DISABLE_RECOVERY=true

This doesn't really mean what it seems to say. If set to true, then the 'safe-mode' entries, the ones that drop you to a single user prompt, will not be generated.

GRUB_TERMINAL_OUTPUT=gfxterm

This sets the terminal output device, which in this case, is a graphical terminal to enable our nice themes and backgrounds to be displayed. Not many will want/need to change this.

GRUB_DISABLE_SUBMENU=y

If this is set to 'n' then the script that generates the entries for the current OS will create an entry for the current kernel and a sub-menu entitled 'Advanced options for...' where ... is the name of the above OS. Selecting this entry displays a new menu containing entries for the other kernels or kernel options, such as text mode booting. Set to 'y' each entry gets its own line in the main menu. This can be used to keep things tidy when you have a lot of options.

GRUB_DISTRIBUTOR=PCLinuxOS

The value here is added to the first line of the stanzas for the current OS in the format --class PCLinuxOS This provides additional information for menu generation, allowing the use of OS specific icons alongside the menu items.

GRUB_GFXMODE=1024x768

The value here must be one supported by your graphics card using Vesa Bios Extensions (VBE). The value may contain an optional color depth e.g. 1024x768x32, which may be ignored if unavailable. I have found the above to be an acceptable compromise for all of my displays. This is, after all, just a boot menu. To discover which modes are available, from a grub command prompt issue the command vbeinfo. If there are so many that they scroll off the screen before you have a chance to read them, then the command set pager=1 will show them in a more controlled manner, like using less under bash.

GRUB_GFXPAYLOAD_LINUX=keep

Setting this option to 'keep' retains the value set in the option above for the next part of the boot process. An alternative is 'text' for a text only boot, or you can set an alternative resolution. The keep option is a good choice here.

GRUB_TIMEOUT=10

The delay in seconds before the default entry is booted, the countdown is cancelled by pressing any key. Set this to '0' to boot immediately or '-1' to wait for a manual selection.

GRUB_THEME=/boot/grub2/themes/pclinuxos2/theme.txt

This one I have already covered and must be the full path to the theme script.

The scripts in /etc/grub.d may, with root permissions, may be edited to customise the grub.cfg file generated by the update-grub2 utility (which is simply a link to /usr/bin/update-grub, so don't worry if you forget to add the final '2').

Before starting to edit these scripts, it is necessary to understand a little about the new format configuration file grub.cfg that is generated by these scripts.

Ignore the Martian nonsense at the beginning and scroll down to the line

### BEGIN /etc/grub.d/10_linux ###

This is the start of the part generated by the script mentioned, and contains the boot stanzas for the kernels available in the current operating system. This is the first menu entry on my system.


The first line contains the title as it will appear in the menu, and this can be whatever you want. Next, on the same line, are a series of --class statements. If a theme has been specified, then these are read sequentially and grub tries to find an icon of the same name in the themes icon directory. If successful, the following --class statements are skipped and the icon is used in the menu display otherwise no icon is shown. We can ignore for now the rest of this line.

Next are a series of statements to tell grub which modules it needs to load to recognize the operating system. These replace the old grub-legacy stage1_5 files and, as far as I can tell, some of the stage 2 code.

After that, we tell grub where the root device is. Note: drives are counted from 0 and partitions from 1. This is a deviation from grub-legacy. Also, the partition table type is often required. Usually, this will be an mdsos or gpt type partition. Here, it is msdos.

Skip down now to the linux and initrd lines. These are really all that grub needs, and are very similar to those used in grub-legacys' menu.lst stanzas. The rest of the stuff is there to make things run smoothly if your system has special requirements.

Scroll down now to the line

### BEGIN /etc/grub.d/30_os-prober ###

This section contains the stanzas for the other operating systems that the os-prober utility has found. The format here is the same for other linux systems but may vary for other systems. Windows, for example, requires its own boot loader, which must be chainloaded from grub. Below is a stanza that does just that.



Fortunately, these are automatically generated for us.

### BEGIN /etc/grub.d/40_custom ###

If you haven't already modified your system, then this section will be empty. This is where the stanzas that we require to be in the menu will appear.

### BEGIN /etc/grub.d/93_memtest ###

You may have an entry here if the memtest utility has been included in your system. If you do not want it to appear in your menu, remove the execute permissions from the named script, and the next time that you execute update-grub2, it will not be included.

chmod -x /etc/grub.d/93_memtest

The other scripts you can probably ignore.

Grub2, left to its own devices, will do a good job of setting up the available operating systems on your machine, but the resulting menu can soon become untidy and difficult to navigate. This next part is for those who want to take control of the menu and are prepared to do a little bit of administrative maintenance to keep things under their control.

Tidying up the menu is a relatively simple matter.

  1. Run update-grub2 with its default options to populate /boot/grub2/grub.cfg with stanzas for all of your installed operating systems that grub and os-prober can find. Then copy those stanzas for the operating systems which you wish to appear in the menu to the end of /etc/grub.d/40_custom.

  2. Edit the titles of the copied stanzas to your liking, and if you want to use icons, make sure that the first --class statement has the name of the icon to use from your theme/icons directory.

  3. Edit /etc/default/grub and change GRUB_DISABLE_OS_PROBER from false to true.

  4. Remove the execute permissions from /etc/grub.d/10_linux with the command chmod -x /etc/grub.d/10_linux

  5. Run update_grub2 to regenerate the /boot/grub2/grub.cfg file.
This has the disadvantage that the menu will not be updated when a new kernel is installed. In this case, reverse steps 3 & 4 above, run update-grub2 to generate the new stanza, then copy it to the appropriate place in /etc/grub.d/40_custom. The stanza for the previous kernel can be removed once the new kernel has been confirmed to operate correctly. Repeat steps 2 through 5.

System Recovery

Since switching to Grub2, I have had no issues with booting. In fact, I have actually had to work hard introducing errors to test out the procedures outlined below. These methods worked for me, but they are not the only way out. Device and partition ordering are one of the biggest problems in booting. Removing a drive or deleting a partition may cause the system to re-number those remaining. Grub is not notified of this and may on next boot fail to find required components. If you multiboot and often add or remove partitions, then you will benefit from reading the grub manual and from an understanding of the drivemap and grub2-mkrescue commands.

Grub2 is very stable and reliable but, stuff happens...

Unfortunately, there are times when things don't go according to plan and the system, for some reason, will not boot. If the menu displays at all, then grub has successfully loaded, and grub is itself a mini operating system with a powerful command shell. If you have an idea of why the boot failed, perhaps the disk was not recognized, then you can try editing the menu entry by pressing 'e'. From here, the menu entry is displayed in a terminal editor, and limited command completion is supported by pressing the Tab key. You can try changing things here. The changes will not be written to disk, but may enable you to find a bootable configuration.

If your attempts to rectify the menu entry fails, then you can jump to a command line by pressing 'c' from the menu screen. Grub2 has a very powerful command interpreter, with excellent command completion features, which enable you to examine the available disks and their files.

You can even test background images for suitability with the background_Image command. For example:

grub> background_image /boot/grub2/themes/pclinuxos2/my_background.png

You can use command completion to good effect here to enable you to locate suitable images, which must be on a mounted partition. Usually, only the boot partition is available. Typing the background_image command with no file name will clear the image.

To boot a Linux system, grub really only needs to know where the kernel and initrd are. The command for the kernel is 'linux'. The following is a transcript of a successful boot using only the command line. The text in blue is the only typing that I had to do, everything else was completed by grub.



As you can see, grub's command completion gives me all the information needed to locate the files. Of the three partitions displayed, one has no recognizable file system, as this is an extended partition which serves only as a container for logical partitions. Of the other two partitions the labels helps me to choose. I like labels. Once the kernel and initrd image have been located, the single boot command boots the system, and from there I can repair the damaged grub. Booting the system in this manner will give you a very basic, text only (no pretty plymouth theme display) start up, but it should boot.

It is worth bearing in mind that in order for grub to access the files that it needs, they must be in a readable location. Grub cannot access encrypted partitions, or some rarer or newer file systems for which support is not included. Logical volume arrays and raid set-ups may also pose problems. If this is a concern for you, then consider using a separate boot partition. The instructions for setting this up are clearly outlined in the manual, so I will not repeat them here.

There may come a time when grub doesn't get as far as displaying the boot menu, and drops you to a prompt. The reason you get here is because grub has failed to find the grub directory, the grub configuration file, or the modules need to complete the loading of grub, and so we have to help grub to find them.

Apart from the kernel and initrd discussed above, grub needs to know two more things: The location of the root device and the location of the grub2 folder, which it stores in the variables 'root' and 'prefix' respectively.

If this is a normal grub> prompt then you will have a few commands available to help you recover. To see the commands, first type

set pager=1

to prevent them scrolling off the screen then type

help.

For help on a particular command type

help command_name.

From the prompt type

ls

This will list all of the available devices and partitions available

(hd0) (hd0,msdos6) (hd0,msdos5) (hd0,msdos1) (hd1) (hd1,msdos1)

Now you have to do a little detective work to find the files. type

set

to list the variables and their values. Look for root and prefix. We need to know just how much grub already knows. The values in root and prefix, if set, will tell us where grub has been looking for its files. Using the values found, use the ls command to verify that they are actually there. If not, then we need to locate them, and re-direct grub to the correct location by setting the variables to the actual location. Another possibility is that the configuration file has been corrupted, moved or renamed. Corruption is the more serious problem, and a reboot from a bootable cd or pen drive is the easiest solution. From the booted system, the config file can be replaced by mounting the partition and copying a corrected file over.

If the file has simply been moved or renamed, then issue the configfile command with the correct path and location of the actual file. If the file had perhaps lost the final 'g' from the file name, i.e. grub.cf, then the command

configfile (hd0,msdos1)/boot/grub2/grub.cf

will bring up the menu. This file should then be correctly renamed once the system is up and running.

If the variables root and prefix are not, or are incorrectly set to point to the actual device or path, then they need to be set with the set command. This should get you to a working boot menu.


Rescue Mode

A worse case is when you get to a rescue prompt. This is a very limited shell with few useful commands, but recovery is still possible. A rescue prompt is displayed when grub fails to find any of the files that it needs in order to continue in a 'normal' manner. That is, it fails to insert and execute the 'normal' module. We can recover even from this, despite having very few usable commands at our disposal.

The Grub2 manual should take a leaf from Douglas Adams book and, like the 'Hitchhikers Guide To The Galaxy,' have printed in large friendly letters on the front cover, the words 'Don't Panic!' Almost all disasters can be turned into triumphs with a little determination and an understanding of the Grub2 system.

In rescue mode, the prompt looks like this

grub rescue>

This leaves you in no doubt as to how deeply in trouble you are. The first thing to try here is to type

normal

to try to get grub to continue in its normal mode of operation This will probably not work, but is worth trying anyway, as grub may have just had a 'senior moment' during the boot process.

The commands available here include:

boot cat load insmod linux ls normal search & set

and not much else.

The procedure to recover is similar to those previously outlined. Use the ls command to list the available devices and partitions. Use the ls command and a partition as argument to locate a /boot directory. Use the ls command to search the /boot directory for a kernel and initrd. Use the set command to put the correct values into the root and prefix variables.

        set prefix=(hd0,msdos1)/boot/grub2
        set root=hd0,msdos1

Use the insmod command to load the normal module. Issue the command normal to resume grubs normal mode of operation, with the variables correctly set.

Point grub at the kernel and the initrd as in the previous example. When all is correctly set, issue the boot command.

With the system recovered, it is advisable to re-install grub with the

/usr/sbin/grub2-install device_name

command to ensure that grub will be able to find its files after a reboot.

That, and what has previously been set out, should enable you to recover from most emergencies. However, this cannot possibly cover all situations and reading the manual, which is not particularly difficult to follow, is recommended.

The grub manual is available here. An excellent introduction to developing grub2 themes is available here. Explanations of Grub2 command line use is available here.

Grub2 is a powerful and comprehensive system. It comes with many useful utilities not discussed in this article, but waiting to be discovered by more curious and adventurous users. An understanding of the basics outlined here can save much distress when things go wrong, and will allow you to customise completely the look of your system on startup with only a minimum of effort.



Previous Page              Top              Next Page