Linux LILO and Runlevels

Posted: September 24, 2010 in Uncategorized
There is a LILO mini howto located on Linux websites such as The Linux Documentation Project and Metalab’s Index of Linux publications. Also these howtos are likely to be on your system in the /usr/doc/HOWTO directory.

LILO is a boot loader that resides on your hard disk that can boot several operating systems. It runs when the system boots from the hard drive and boots the Linux kernel image stored there. To select an operating system other than the default at bootup, press <TAB> at the boot prompt and select from a list of operating systems that the system knows about.

The file /etc/lilo.conf is used to set the configuration up for the boot loader program what will be installed on the boot sector of a partition. When the command “lilo” is issued, the contents of the configuration file is read and a binary executable program is installed on the boot record based on the contents of the configuration file.

Installing and Configuring LILO

To install LILO, edit the configuration file, /etc/lilo.conf. The command “/sbin/lilo” rewrites the modified lilo.conf configuration to the boot sector of the hard disk, and must be run every time you modify lilo.conf or your kernel.

Some options you may want are:

  • vga= ask
    LILO will prompt the user for a video mode at boot time. Normal is standard 80X25 display, extended is 80×50. To select a mode, run with the option “vga=ask”, then select one of the listed modes, then set “vga=mode” where “mode” is one of the numeric values listed. On my system I have the following modes listed.

    • 0 – 80×25
    • 1 – 80×50
    • 2 – 80×43
    • 3 – 80×28
    • 4 – 80×30
    • 5 – 80×34
    • 6 – 80×60
    • 7 – 132×25
    • 8 – 132×43

    To select 132×43 I will set the mode “vga=8”.

  • initrd=/boot/initrd-2.2.14.img
    This command allows the kernel to boot from a RAM disk image. This is necessary if the kernel requires a device supported by a module in order to boot. The kernel version in this example is 2.2.14, but your version may be different. The image file can be created using the “mkinitrd” command. Read the section about compiling the kernel for more information.
  • append=”mem=128M”
    Used for some cases when a system has more than 64M of memory (128M in the example) in the case of older systems (kernels) that need this option to use more than 64M of memory. If you have a multiple boot Linux system, you will need to run LILO on each system to get this option to work on each system. See if enough memory is available to your system by using the “free” command to tell if you need this option.
  • linear
    The option “linear” may be needed if you have a partition with more than 1024 cylinders or a SCSI drive. This option generates linear sector addresses rather than sector, head, cylinder addresses. This is useful for large drives but should not affect a system that works properly.

The LILO configuration file contains a section for each operating system that you can boot. The best way to demonstrate this is with an example. The lilo.conf file below is for a system which has a Linux root partition on /dev/hda2 and a MS-DOS partition on /dev/hda1.

boot = /dev/hda # Tell LILO to install the boot loader on the /dev/hda disk boot record
vga = normal # Set a normal video mode
delay = 60 # The time in tenths of seconds to press <SHIFT> to get the LILO prompt
# Equivalent would be “prompt” on one line, and “timeout=60” on
# another line.
default=msdos # Sets the default boot to DOS, Without this line, the default is the first stanza
install = /boot/boot.b # The file containing the boot sector to use
compact # Have LILO perform some optimization.
map = /boot/map #Specifies the map file LILO creates when installed
# Section for Linux root partition on /dev/hda2.
image = /vmlinuz # Location of kernel
label = linux # Name of the OS that is displayed in the LILO boot menu
root = /dev/hda2 # Location of root partition, if this isn’t here the kernel image must have
# this set using the rdev command
read-only # Mount read only on startup, Can also be set by rdev
# Section for MSDOS partition on /dev/hda1.
other = /dev/hda1 # Location of partition
table = /dev/hda # Location of partition table for /dev/hda1
label = msdos # Name of OS (for boot menu)

The first operating system is normally the default operating system for LILO to boot, but the default command was used to change this. There’s no need to use the rdev program to set the root partition in the kernel image if you use the “root=” command as in this example.

The options used above are described in the lilo.conf man page invoked by typing “man.lilo.conf”. The option “boot = /dev/hda” is very important and defines what partition boot record the LILO boot loader will be installed on. The table option in the section “other” is optional, but if used, lilo must be reinstalled anytime your drive partitions are changed. Other than that, the comments above explain the options well.

If you install Windows 95 or 98, the LILO boot manager will be overwritten by windows. If you are going to do this after installing LILO, create a boot disk first. Boot Linux with the boot disk and re-install LILO after the Windows installation is done. LILO is re-installed by typing, as root, the command “lilo”. Partitions with Windows 95 or 98 can be configured to boot with LILO using similar lilo.conf entries to those to boot DOS.

To run Linux in single user mode from lilo, at the boot prompt type “rhl single” where rhl is the name of the linux selection under lilo that you want to boot. This mode will not normally require a password for access. To prevent others from running the operating system in single user mode without a password, add the following lines at the end of the image section:

password=”my_password”
restricted

Where “my_password” is the actual password to be entered when the user enters single user mode. This makes lilo ask for a password any time a user boots to this image in single user mode. If you do this you will want the “/etc/lilo.conf” file to be readable only by root so normal users can’t get the password.

NOTES:
DOS should always be installed before Linux due to differences in the DOS and Linux LILO boot sectors.
To copy your MBR to a floppy using 512 character blocks, “dd if=/dev/had of=/fd/MBR bs=512 count=1”
To restore the boot record: “dd if=/fd/MBR of=/dev/had bs=446 count=1”

Setting parameters for Disk Drives

Some systems may have difficulty with hard disks that do not allow the disk parameters (heads, sectors per track, and cylinders) to be read. If disk errors make the LILO installation fail, the disk parameters may be the problem. This is especially true with SCSI and large drives. It may be necessary to manually enter the disk parameters in the “/etc/disktab” file to solve this problem. BIOS numbers your disks depending on the type of device. Numbers are in hex. Some documentation I have read indicates the numbers for various disks start as follows:

Floppy drives - 100.  
The first hard disk - 301.  
The second HD  - 341.
SCSI - 801.
Second SCSI - 811.

Some documentation indicates these numbers, however I am not sure how accurate this is. According to the LILO man page the BIOS numbers hard disks starting at 0x80. If you have a problem in this area you may need to do some experimentation to get it to work.

Example file:

  	disk=/dev/sda
		bios=0x80
	disk=/dev/hda
		bios=0x81

Other possible format (A SCSI drive with 2 partitions):

# Dev. Num BIOS code Secs/track Heads/cyl Cyls Part. Offset
0x800 0x80 32 64 1714 0
0x801 0x80 32 64 1714 1001

Removing LILO

To remove LILO from MS-DOS type “fdisk /MBR”.
To remove LILO from linux type “lilo -u /dev/hda”, or “dd if=/boot/boot.0300 of=/dev/hda bs=446 count=1”. Only 446 bytes should be copied to the mbr. If the hard drive is scsi, the filename is boot.0800. Make sure when LILO was installed that this is the correct copy of the MBR and not a bogus copy from a Linux distribution.

Changing Runlevels

A runlevel is a software configuration of the system that allows only a selected group of processes to exist. Init can run the system in one of eight runlevels. The main runlevels are 0-6. The system runs in only one of these runlevels at a time. Typically these runlevels are used for different purposes. For Redhat Linux version 6, they are:

0 halt
1 Single user mode
2 Multiuser, without NFS (The same as 3, if you don’t have networking)
3 Full multiuser mode
4 unused
5 X11
6 Reboot

These runlevels can be configured by the administrator. The “/etc/inittab” file instructs init which runlevel to start the system at and describes the processes to be run at each runlevel. For a deeper explanation, read my article on “How Linux Works” or “The Linux Startup Reference Manual”

A running system can be taken to single user mode by using the telinit command to request run level 1 as follows:

telinit 1

It can be entered when the system boots by giving the word “single” or “emergency” on the kernel command line. This can be done at the LILO prompt after pressing the <TAB> key and entering your selection with the word “single” after it. The kernel sends the command line to the init program and it doesn’t use the default run level. The kernel command line entry is dependent on how you boot the system.
Entering single user mode is necessary when a damaged filesystem needs repaired. You can run the program fsck to check the filesystem when the damaged partition is not mounted or running.

LILO and the rdev program

You may have noticed that there are some parameters in LILO that can also be set by a program called rdev. The rdev program is a program that is used to set the following:

  • The root partition (root device) The command “rdev -s vmlinuz /dev/hda2” will set the root device to be /dev/hda2 on the kernel image vmlinuz. In LILO the command, “root=/dev/hda2”, will set the root device.
  • The video mode. The command “rdev -v vmlinuz 1” will set the video mode as though the key 0(the first selection) were pressed at the video mode prompt. In LILO the command, “vga=ask”, will cause the system to prompt for video mode. You are better off to use LILO to set the video mode.

The commands shown above are examples and the actual names and values used may be different for your system. The program rdev is used to modify the kernel image file so that it will know where such things as the root device are without LILO passing this information to the kernel. Therefore if you set these parameters in your kernel image file using rdev, you will not need to set it using LILO. Conversely if you do not set these commands using rdev, you will need to set them in your /etc/lilo.conf file and update LILO when you do a kernel recompile or make other changes affecting one or more of these parameters.

One system parameter LILO can set that rdev cannot set is the amount of system memory with the command, append=”mem=128M”. This command sets the memory to 128M.

In addition, rdev provides the ability to set the following parameters that LILO can’t set.:

  • The swap partition (swap device). The command “rdev -s vmlinuz /dev/hda3” will set the swap device. There is no command in LILO to do this.
  • Set the RAMDISK size in kilobytes. The command “rdev -r vmlinuz 627” will set a RAM disk of 627K.
  • Some root flags
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s