الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

Boot Loaders Concepts

مغلق
بدأه GreenHat في 13 يوليو 2004 · 0 رد · 1,186 مشاهدة · في نظام تشغيل Unix & Linux
مشاركة: واتساب X فيسبوك تيليجرام
#1

4. Boot Loaders

4.1 Concepts

Invocation

Invocation of the boot loader usually occurs in one of two ways:

BIOS loads the first stage boot loader from the drive's MBR.

BIOS loads another boot loader which then loads the first stage boot loader from a partition's boot sector.

The first stage boot loader is also known as Initial Program Loader (IPL). It must be less than 512 bytes in size, so it is fairly limited. It's primary job is to load a more functional boot loader (a.k.a. the second stage boot loader).

Configuration

There are two different ways to configure a boot loader:

Install the first stage of the boot loader on the MBR. It can then be configured to pass control to any desired operating system.

Install the first stage of the boot loader in the boot sector of a partition. Another boot loader is then installed on the MBR. This other boot loader must be configured to pass control to the Linux boot loader.

4.2 Lilo

Configuration File

/etc/lilo.conf

Sample File:

prompt # Present lilo prompt so user can interact with lilo

timeout=50 # Timeout in milliseconds to wait for user interaction

default=linux # Default image to boot

boot=/dev/hda6 # Specifies boot device (Location to install primary boot loader)

# To install in the MBR, specify /dev/hda

map=/boot/map # Location of map file

install=/boot/boot.b # Location of Second stage boot loader

password=some_passwd # A password required to boot

restricted # Password only required if options are entered at boot prompt

message=/boot/message # Text message or splash screen (PCX) that will be displayed at boot time.

linear

# Image definition

image=/boot/vmlinuz-2.4.7-10 # Specifies location of the virtual memory compressed kernel

label=linux

initrd=/boot/initrd-2.4.7-10.img # Initial RAM Disk

read-only

root=/dev/hda9 # Location of root file system

other=/dev/hda1 # Image definition

optional

label=windows

See lilo.conf man page for an example.

Command Line Options

-t - Test lilo configuration, but don't actually install.

-v - Verbose

Boot Time arguments

Command line options can be entered at the boot prompt by appending it to the image that you are booting. For example:

linux root=/dev/hda5 mem=128M 1

Tells lilo to boot the kernel with a label of "linux" into runlevel 1 using /dev/hda5 as the root filesystem. It also states the machine has 128 MB of RAM.

If lilo has been password protected, you will be required to enter the password before booting.

Errors

The 'LILO' prompt itself can be used to help diagnose boot related errors. The number of letters presented at the LILO prompt can indicate the success or failure of the boot loader.

L = First stage boot loaded and started. Usually indicates disk problems or invalid options in /etc/lilo.conf.

LI = Second stage boot loaded from /boot, but /etc/lilo.conf has invalid parameters or /boot/boot.b was moved without re-running /sbin/lilo.

LIL = Second stage loader started, but the descriptor table can't be loaded due to a bad disk or invalid parms in /etc/lilo.conf.

LIL? = Second stage loaded at an incorrect address because of invalid parms in /etc/lilo.conf or /boot/boot.b was moved without re-running /sbin/lilo.

LIL- = Descriptor table is corrupt. Caused by invalid parms in /etc/lilo.conf or /boot/boot.b was moved without re-running /sbin/lilo.

LILO = All of LILO loaded correctly.

Limitations

Must be installed on the 1st or 2nd IDE drive.

Limited by BIOS (uses BIOS to load kernel off of disk).

Must re-run /sbin/lilo every time you change your configuration.

Fixing a corrupt MBR

Use lilo to fix:

/sbin/lilo

Uninstalling LILO

When LILO overwrites an existing boot sector, it saves a copy of the original boot sector in /boot. The name of the original boot sector will be boot.MMmm where 'MM' is the major device number and 'mm' is the minor device number. So, the original boot sector from /dev/hda will be /boot/boot.0300.

To restore the original boot sector, use the dd command:

dd if=/boot/boot.0300 of=/dev/hda bs=446 count=1

The original boot sector is actually 512 bytes in length, but the remaining bytes after 446 are part of the partition table and we don't want to overwrite that in case it's changed.

Initial RAM Disk

Need: Allows necessary drivers to be loaded at boot time that aren't compiled directly into the kernel.

Creation: Use mkinitrd to create the initial RAM disk:

mkinitrd /boot/initrd-2.4.7-10 2.4.7-10

Setup: Specify in /etc/lilo.conf file as shown above.

4.3 Grub

Features

Command line interface available at boot prompt.

Can boot from multiple file systems including ext2/3, Reiserfs, FAT, minix, and FFS

Password protection using MD5

Changes to configuration file take effect immediately. Don't have to re-install MBR.

Configuration File

/boot/grub/grub.conf

Sample Configuration

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE: You have a /boot partition. This means that

# all kernel and initrd paths are relative to /boot/, eg.

# root (hd0,0)

# kernel /vmlinuz-version ro root=/dev/hdb5

# initrd /initrd-version.img

#boot=/dev/hdb

default=0 # Default to First definition for booting

timeout=10 # Time in seconds to wait for user interaction

splashimage=(hd1,0)/grub/splash.xpm.gz # Splash Screen

password --md5 $1$بàيآُXغt$Z.............. # Password protection

title Red Hat Linux (2.4.17) # First definition

root (hd1,0)

kernel /vmlinuz-2.4.17 ro root=/dev/hdb5

title Red Hat Linux (2.4.17pre2-pk) # Second definition

root (hd1,0)

kernel /vmlinuz-2.4.17pre2-pk ro root=/dev/hdb5

title Red Hat Linux (2.4.17pre2)

root (hd1,0)

kernel /vmlinuz-2.4.17pre2 ro root=/dev/hdb5

title Windows 98SE

rootnoverify (hd0,0)

makeactive

chainloader +1

Boot Time arguments

In order to pass arguments to the image being booted, you must enter menu editing mode, or enter the grub command line. If GRUB has been password protected, you'll need to enter 'p' followed by your password first.

To enter menu editing mode, select and entry and press 'e'. This will allow you to modify an existing boot setup and pass options to the kernel as well as init.

The GRUB command line allows you to create boot commands that don't exist in your grub.conf file. You can also run diagnostic tests and view the contents of files on your file systems.

Device Names according to Grub

(fd0) - First floppy drive detected by BIOS

(hd0) - First hard drive detected by BIOS (SCSI or IDE)

(hd1,3) - Fourth partition on the 2nd hard drive detected by the BIOS

Fixing a corrupt MBR

Use grub-install to fix:

/sbin/grub-install /dev/hda

Multi-disk scenario

In this situation, we have a nameless OS installed on /dev/hda and Linux installed on /dev/hdb. We need to setup grub to boot both OSes. This involves installing the first stage of grub on the MBR of /dev/hda and the second stage of grub on the /boot partition of /dev/hdb. We will use the grub configuration file listed above. This scenario assumes you either have a working system or are running in rescue mode chroot'd to /mnt/sysimage.

Launch a grub shell:

/sbin/grub

Note: The remaining steps will performed from within the "grub shell".

Set the root device:

root (hd1,0)

Specify where to install various boot stages:

install (hd1,0)/grub/stage1 d (hd0) (hd1,0)/grub/stage2 p (hd1,0)/grub/grub.conf

The above command line can be broken down as follows:

install <stage-1> d <install-disk> <stage-2> p <config file>

4.4 DOS Based

Loadlin - Capable of booting multiple OSes

Syslinux - Used by RH installation program

هذا الموضوع مغلق.

مواضيع مشابهة