Learn about Lilo and grub

Source: Internet
Author: User
Tags md5 encryption home screen root access

Transfer: Http://www.ibm.com/developerworks/cn/linux/l-bootload.html

Source: Laurence Bonney, WebSphere mq jms test team lead, IBM

From Common Desktop Users to Linux system administrators, most Linux users have used a tool named Boot Loader. Different variants of these tools provide support and functions at different levels. In many cases, the boot loader installed by default in the Linux release is not always suitable for your needs. The same applies to the default settings of each boot loader. In this article, Laurence Bonney discusses the advantages and disadvantages of two popular boot loaders-Lilo and grub-, and suggests many configurations to fully explore the potential of the machine.

Which tool does all Linux users use without considering their work or expertise? Bootstrap loader. This article describes how the boot loader works and how the two popular Boot Loader programs work.Lilo(Linux Loader) andGNU grub(Grand uniied Boot Loader), and study their respective advantages and disadvantages.

What is a bootstrap loader?

To put it simply,Boot Loader)Will guide the operating system. The BIOS reads the first 512 bytes (knownMaster Boot Record (MBR)). In a single MBR, only one operating system boot record can be stored. Therefore, when multiple operating systems are required, problems may occur. Therefore, more flexible boot loader is required.

The Master Boot Record itself contains two types of content: partial (or all) boot loader and Partition Table (which contains information about how to divide the rest of the media into partitions ). When the BIOS boots, it looks for the data stored in the first sector (MBR) of the hard drive. The BIOS uses the data stored in the MBR to activate the boot loader.

Because the BIOS can only access a small amount of data, most boot loaders perform boot in two phases. In the first phase of boot, the BIOS directs part of the boot loader, that isInitial program loader, IPL). IPL queries partitioned tables to load data at any location on different media. First, use this step to locate the second-stage Boot Loader (including the rest of the loader ).

The second phase of the boot loader is the main body of the boot loader. Many people think that this is the real part of the boot loader. It contains the part where the loader needs more disk space, such as the user interface and kernel boot program. From simple command lines to graphic GUI, these user interfaces are widely used.

Boot Loader is usually configured in either of two ways: either as the primary boot loader or as a secondary boot loader ).Main Bootstrap programIs the first-stage Boot Loader installed on MBR (see previous descriptions ).Level 2 Boot LoaderIs the first-stage Boot Loader installed in a bootable partition. A separate Boot Loader must be installed on the MBR and configured to forward control to the second-level boot loader.

Many newer Linux boot loaders are especially useful because they provide different degrees of interaction, such as advanced GUI and encrypted passwords, and the ability to boot by selecting an operating system. In this way, multiple operating systems can coexist on the same machine with multiple physical disks. This setting is more and more common, because it helps many users retain valuable data previously generated by Windows machines when installing a new Linux. I personally think this kind of configuration is wonderful; you can have both Linux and Windows on only one machine.

With the passage of time, the boot loader has been enhanced and many features have been introduced to users. Different boot programs have different functions and configurations, but the basic goal is the same.

Now let's look at two popular boot loaders: Lilo and grub.

Lilo

Linux Loader (lilo)Has become a standard component of all Linux releases. As an older/oldest Linux boot loader, its growing Linux community support enables it to develop over time, and always act as an available modern boot loader. There are some new features, such as enhanced user interfaces and the use of new BIOS features that can break through the 1024-cylindrical limitation.

Although lilo is still evolving, the basic concept of Lilo's working principle remains unchanged.

Use LILO as the Boot Loader

To use LILO as the boot loader, the things that need to be done depend on whether to perform a new installation or change the installed Linux to Lilo. If you want to perform a new installation, you can directly jump to the Section configuring Lilo. If you have installed a Linux release, you can usually install and configure lilo (and boot the machine to a new Linux installation ).

To migrate an existing Linux instance to Lilo, you must first obtain the latest version of lilo (see references ). Before doing anything else, we recommend that you have a Linux boot disk at hand-it can be of great help to restore to the initial Linux configuration if something is wrong occasionally! After installing lilo in the system, it is very easy to take over MBR. Enter the following as a root user:

# /sbin/lilo -v -v

This will use the current lilo default value to erase all the current content in the MBR. However, please read the configuration lilo to ensure that it can be guided as expected. Note that if you want to run Windows and Linux on the same machine, you should first install Windows OS and then install linux OS, the boot loader selected during Linux installation will not be overwritten by the Windows boot loader. Unlike Linux boot loaders, most window boot loaders do not support Linux boot. If you have installed Linux first, you only need to create a Linux boot disk. After installing windows, you can go back to Linux installation and rewrite MBR.

Configure lilo

Lilo configuration is completed through a configuration file located in/etc/Lilo. conf. Listing 1 provides an example configuration that uses my home machine and supports Dual Boot for Linux and Windows machines. After learning about the basic configurations of my workstation, you can imagine how these configurations are associated with the actual machine:

  • Windows XP is installed on the primary HDD (physical disk 1 ). In Linux, this HDD is/dev/hda (hd0, 0 in grub ).
  • Red Hat Linux is installed on HDD (physical disk 2). The root partition is located in the third partition of the hard drive, that is,/dev/HDB3 (in grub terminology hd1, 3 ).

Listing 1. Lilo. conf sample file

boot=/dev/hdamap=/boot/mapinstall=/boot/boot.bprompttimeout=100compactdefault=Linuximage=/boot/vmlinuz-2.4.18-14label=Linuxroot=/dev/hdb3read-onlypassword=linuxother=/dev/hdalabel=WindowsXP

Options in Listing 1:

  • boot=To tell lilo where to install the boot loader. In the above example, it will be installed to the MBR of the first hard disk. You can also install lilo to/dev/HDB3 (LINUX partition in the example). In this case, you need to install another boot loader to/dev/hda and direct it to the Lilo boot loader; then you only need to let lilo load the program as a second-level boot. Generally, the boot loader is located in/dev/hda. You can also point this parameter to a floppy disk drive (the most common one is/dev/fd0) to make a lilo floppy boot disk.
  • map=Point to the internal ing file used by lilo during boot. When using/sbin/liloCommand to install Lilo, it will automatically generate this file, which contains the Descriptor Table (and other content ). Do not change this file!
  • install=Is one of the files used internally by lilo during the boot process. It also contains the primary and secondary components of the boot loader. A segment of the boot. B file is written to MBR (the main part of the boot loader), which points to the ing and then points to the second-level boot loader. Similarly, do not change it!
  • prompt=Tell lilo to use the user interface (two options are provided in this example: Linux and Windows XP ). In addition to the prompt/user interface, you can also specify specific parameters for the Linux kernel, as appropriate. If this option is not specified in the configuration file, Lilo directs to the default OS without any user interaction or waiting. (However, note that if shift is pressed during boot, you can still get a prompt, which is very useful if you do not want to expose the boot loader to common users ).
  • timeout=Is the waiting time before the boot prompt is automatically guided to the default OS (in this example, Linux) (in the unit of 10 s ). If not specified in Lilo. confpromptThis parameter is ignored.
  • compactOption can greatly accelerate the boot process, which combines consecutive disk read requests into a separate request. However, this may be a mixed blessing, because I have seen many posts on the Forum about this option. This option is especially useful when you want to boot from a floppy disk.
  • default=Indicates which image lilo uses for boot by default, such as waiting for timeout. This is associated with the labels of an image in the Lilo. conf file. If this option is not specified in the configuration file, it will be the first image specified in the boot file.
  • For each Linux version that allows the user to boot, you must specifyimage=And the following three options. The image option specifies the kernel version to boot.
  • label=Indicates the OS that you want to boot from the user interface during running. In addition, this label is used to specify the default OS for the boot. (Note: Avoid spaces in the tag name. Otherwise, unexpected errors may occur when the file is booted .)
  • root=Tell lilo OS where the file system is actually located. In our example, It is/dev/HDB3, which is the third partition on the second hard disk.
  • read-onlyTells lilo to boot to the file system in read-only mode. Once the OS is fully booted, it will be mounted in read/write mode.
  • password=Allows you to set a password for the specific OS to be booted. Unfortunately, this password is saved in the Lilo. conf file as readable text, so everyone can read it. If needed, you can also set a password for each operating system you want to boot from (in our example, only one password is set for Linux boot ).
  • other=The action is similar to the combination of the image and root options, but used for operating systems other than Linux. In our example, it tells lilo where to find Windows OS (located in the first partition of the first hard disk ). If you first install windows and then install Linux, this is usually the case.
  • label=It is the same as all other label options.

Many other parameters can be used in the Lilo. conf file, but the parameters in Listing 1 are enough to make the machine available. For more information about Lilo. conf and other parameters, see man Lilo. conf ). Because Lilo. conf is not read during boot, you need to "Update" the MBR when this file is changed. If you do not complete this step, then the changes to Lilo. conf will not be reflected at startup. Similar to writing lilo to MBR, run:

$ /sbin/lilo -v -v

-v -vThe tag will give you a very detailed output. Many parameters can be specified when we run lilo as we do. Refer to the manual page for further information (man lilo ).

Initial Boot Process

When lilo is initially guided, it prints every letter in order --L-I-L-O. If all the letters are displayed, the first-stage boot is successful. If any content is missing, the following error occurs:

  • L: the first-stage boot loader has been loaded. If lilo stops here, a problem occurs while guiding the second-stage boot loader. This usually comes with an error code. A common problem at this stage is a media issue, or an incorrect disk parameter is specified in the Lilo. conf file.
  • Li: The second-stage boot loader has been loaded. Lilo stops here, indicating that the second-stage Boot Loader cannot be executed. Similarly, this may be caused by a problem similar to displaying only l: Loading, or loading failed because the boot. B file is damaged, moved, or deleted.
  • LIL: The second-stage boot loader is being executed. In this case, a media problem may occur again, or the problem may occur when you look for the descriptor table in the ing file (as specified in the Lilo. conf file.
  • Lil? : Load to the same stage as above. This usually means that the second-stage Boot Loader uses an incorrect address. The most common cause is that the location of boot. B is different from that specified in the Lilo. conf file.
  • Lil-: load to the same stage as above. A problem occurs when a descriptor table is loaded. The most common cause is a descriptor table error.
  • Lilo: lilo is loaded successfully, and no error occurs.

Additional configuration during boot

After lilo is loaded successfully, the LILO prompt is displayed. Use the Lilo. conf file in the preceding example. There are two options, which may not be intuitive to new Lilo. First, you can set lilo timeout (10 seconds later). This will guide/dev/HDB3, that is, LINUX partition. In addition, you can press the tab key to list the operating system options to be booted. In our example Lilo. conf, the options are "Linux" and "Windows ". Which OS will be directed. If you specify the Linux loading option, a password is prompted. In this examplelinux. If the entered password is incorrect, the LILO prompt is returned.

Unfortunately, Lilo does not support interactive configuration during boot, so it can only be run in Lilo. conf or/sbin/liloSpecifies the option.

The last suggestion for trying Lilo for the first time is: I found that using a floppy disk is safer than using a hard disk for Lilo configuration. To do this, you must useboot=/dev/fd0Replaceboot=/dev/hda. In this way, if any configuration in the Lilo. conf file is disrupted, the boot disk can be taken out and booted to Linux as before. You can change Lilo. conf backboot=/dev/hdaAnd then run/sbin/liloTo upload and modify.

GNU grub

Recently,Grand uniied Boot Loader(Usually calledGrub) Seems to replace Lilo's dominance in the boot loader. Based on the original grub Program (originally created by Erich Stefan Boleyn), GNU grub is under active development by the Free Software Foundation.

Use GRUB as the Boot Loader

Similar to Lilo, the steps required to use GRUB as an active Boot Loader depend on whether the new OS is installed or Linux has been installed and is planned to be transferred to grub. For completely new installation, you can directly jump to the Section configuring grub. If you have installed a Linux release, you can usually choose to install and configure grub (and boot the machine to a new Linux installation ).

Currently Linux users who plan to migrate to grub need to obtain the latest grub version (see references ). Similarly, like Lilo, you need to prepare a Linux boot disk at hand before doing anything else. This disk is not required when using the interactive mode (described later), but it is best to have one for use in urgent need. After installing lilo in the system, it is very easy to take over MBR. Enter the following as a root user:

# /boot/grub/grub

A command prompt similar to Bash will be loaded. You can use the grub command here:

grub> install (hd1,3)/boot/grub/stage1 (hd0) (hd1,3)/boot/grub/stage2 p (hd1,3)/boot/grub/menu.conf

This command uses the grub installation command. You need to give it the location of the first stage image and the location of MBR (install (hd1,3)/boot/grub/stage1 (hd1)). The location of the Second Stage Image ((hd1,3)/boot/grub/stage2). Finally, optionalp (hd1,3)/boot/grub/menu.confThe location of the grub GUI configuration file.

In the previous example,hd1Is my LinuxDisk,hd0It is my windows disk. This will use the current grub default value and erase all the current content in the MBR (please read the configuration grub to ensure it can be booted as expected ).

Configure grub

Grub configuration is completed through a configuration file in/boot/GRUB/grub. conf. Listing 2 provides an example configuration that uses my home machine and supports Dual Boot for Linux and Windows machines:

Listing 2. Example grub. conf file

default=0timeout=10splashimage=(hd1,3)/grub/splash.xpm.gzpassword --md5 $1$opeVt0$Y.br.18LyAasRsGdSKLYlp1title Red Hat Linuxpassword --md5 $1$0peVt0$Y.br.18LyAasRsGdSKLYlp1root (hd1,3)kernel /vmlinuz-2.4.18-14 ro root=LABEL=/initrd /initrd-2.4.18-14.imgtitle Windows XPpassword --md5 $1$0peVt0$Y.br.18LyAasRsGdSKLYlp1rootnoverify (hd0,0)chainloader +1

Options in Listing 2:

  • default=Option to notify grub which image is used for boot by default after timeout. This option is associated with an image in the grub. conf file. 0 indicates that the first is specified, 1 indicates that the second is specified, and so on. If this option is not specified in the configuration file, it will be the first image specified in the boot file.
  • timeout=The number of seconds that the boot prompt will wait before the default OS is automatically booted (in this example, it is Red Hat Linux.
  • splashimage=Is the position of the image used as the grub GUI background.
  • passwordOption specifies the MD5-encrypted password used to access grub interactive boot options. Note that this does not prevent the user from booting the defined OS; For each-titleSet it. To generatemd5Password. Rungrub-md5-cryptTool (as root ). It will prompt you to enter a password you want to encrypt. Then output the password encrypted with MD5. Copy the password to grub. conf.password -md5But on the same line. Generally, this password can be set to the root password, because only root can read the grub. conf file in any case.
  • titleIndicates the specific OS that can be booted from the user interface during running. Unlike Lilo, the name can contain spaces.
  • passwordIs set in the same way as the previous password. If you plan to share this machine with other users, do not set this password as the root password.
  • rootTell the actual location of the grub OS file system. It can be seen that grub references a media in a different way than Lilo. In the Lilo example,/dev/HDB3 is the third partition in the second hard disk. Grub references this hard disk as (hd1, 3), that is, the third partition of the second hard disk (Disk 0 is the first hard disk ).
  • kernelThe vmlinuz-X.X.XX-XX is the name of the default Boot Image in the root directory.
  • initrd: The initrd-X.X.XX-XX.img is the name of the default initrd image in the root directory.
  • titleIt is the same as all other title options.
  • password: See other password options.
  • rootnoverifyTell grub not to change the OS root. In this way, no boot error occurs when the file system is not supported by grub.
  • chainloader +1Tell grub to use a chain loader to load the OS. This option is required when Windows is loaded.

Many other parameters can be used in the grub. conf file, but the parameters in Listing 2 are enough to make the machine available. For more information about grub. conf and other parameters, see man grub. conf ).

Unlike the Lilo configuration file, grub. conf is read during boot and does not need to be updated when it is modified.

Initial Boot Process

Similar to Lilo, when grub is initially loaded, the first stage program is loaded from MBR. After loading, it enters the intermediate stage between the pilot loader in the first and second phases (for convenience of discussion, it can be called stage 1.5 ). The reason for the existence of stage 1.5 is to allow regular file system access to the grub configuration file in/boot/grub, rather than accessing disk blocks. Then, go to the second stage of the boot loader. Grub loads the grub. conf file.

Now we should be able to see grub GUI. For users familiar with windows, this looks more friendly than Lilo. However, do not assume that grub has a GUI as a boot loader that cannot process data. There are amazing options. (See the prompts in the additional configuration during boot .)

If you configure it as I do, you can now see two options on the screen: boot to Red Hat Linux or boot to Windows XP. By default, Linux is loaded. The result of selecting any one is self-evident.

Now let's look at some good things.

Additional configuration during boot

In grub GUI, pressing any key will stop time-out. Press the P key to enter the GRUB Password and obtain full access to the grub interactive boot option. Press one of the following keys to use one of the three options:

  • To edit the command before booting, press E. This allows you to edit specific options for the selected OS. Grub only displays the options related to the OS boot, and you can edit them properly. This is especially useful when an error HDD is specified for the root file system. If you need to access the machine in single-user mode (you can obtain the root access permission without specifying a password !), Select Linux OS on the grub home screen. Then, as before, press E and move it to the kernel line (in my examplekernel /vmlinuz-2.4.18-14 ro root=LABEL=/). Then addsingleAnd press B to use the modified grub. conf for guidance. Any modifications made in the editing mode are not saved to the grub. conf file.
  • To modify the kernel parameters, press. If you are an experienced linux user, you can adjust the kernel parameters as needed.
  • To obtain a command line interface similar to bash, press C. This small command line interface allows you to find the grub configuration file in the system, load another configuration file, edit the lines in the configuration file, and directly enter the grub command. If the configuration changes (such as deleting a partition) Make the system unable to boot, this interface may be used. If you want to direct the system to the single-user mode, or set the running level to 3 instead of the normal running level, you may also use it.

These options have many functions, but they are beyond the scope of this article.

It can be seen that grub truly opens the possibility of a boot period. However, this may be a mixed case, because grub also potentially allows attackers to access the system before the OS is loaded. The main open areas that will be misused are:

  • Single-user access mode. All users loaded into the single-user mode will get the root access permission, so that Linux can be abused at will.
  • Access other operating systems. Any operating system that is configured with no password, such as DOS, will be open.
  • Access the grub editor. This allows you to have full access permissions to modify grub configurations.

In grub configuration, setting security is very important. Setting a password and using MD5 encryption can ensure the security of the entire system.

The future of grub

Grub will be replaced by grub2. The original grub will be renamedGrub legacyIn addition to fixing bugs, it will not be actively developed. Grub2 will completely rewrite the original grub. So far, the following features are the core of changes:

  • Stage 1.5 is replaced by creating a compressed core image
  • Supports dynamic loading of core images
  • Strive to make the entire grub framework object-oriented
  • Supports internationalization, such as non-ASCII character sets
  • Supports different hardware architectures and platforms (different from Linux platforms)

Please refer to the grub web site (see the references section below) for the latest progress.

Comparison between grub and Lilo

As described at the beginning of this article, all boot loaders work in a similar way to achieve a common purpose. However, there are many differences between Lilo and GRUB:

  • Lilo does not have an interactive command interface, but grub does.
  • Lilo does not support network boot, but grub does.
  • Lilo physically stores information about the bootable operating system location in MBR. If you have modified the Lilo configuration file, you must rewrite the first-stage boot loader of lilo to MBR. Compared with grub, this is a more dangerous option, because wrong configuration of MBR may make the system unable to boot. If grub is used, if the configuration file is incorrectly configured, it is only forwarded to the grub command line interface by default.

Conclusion

Like all software, it is the best choice for a user, not everyone. As for the two boot loaders involved here, I personally like GNU grub. It is a very good and comprehensive load program, combining a flexible user interface and a large number of functions. However, many people who have used Lilo and are loyal to lilo still choose lilo as the boot loader. Fortunately, if you are just starting to get started with Linux boot loading, it will not be too much of a problem to use.

For security, anyone who can access the boot disk/CD can bypass all the security measures mentioned in this article by using grub. conf or Lilo. conf without security settings. Especially when grub is used, it is a serious security vulnerability because it can be guided to the single-user mode. One easy way to solve this problem is to disable boot through CD and floppy disk in the BIOS of the machine, and ensure that a password is set for the bios so that others cannot modify these settings.

Good luck!

 

 

About the author

Laurence Bonney is a software engineer at the IBM hursley lab in the UK. He is the Technical Team Leader of the test team dedicated to WebSphere mq jms products. In his spare time, he enjoys playing the guitar (although it is very bad). He will try his best to surf through the holidays and enjoy video games. You can contact Laurence through a bonneyl@uk.ibm.com.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.