0% found this document useful (0 votes)
14 views

HowTos GrubInstallation

This document explains how to install or re-install the Grub boot loader under CentOS 5 and 6. It describes creating the grub configuration file, installing grub files and boot loader using grub-install, and provides notes on using a separate /boot partition or with ext4 file systems.

Uploaded by

Fresh Juice
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

HowTos GrubInstallation

This document explains how to install or re-install the Grub boot loader under CentOS 5 and 6. It describes creating the grub configuration file, installing grub files and boot loader using grub-install, and provides notes on using a separate /boot partition or with ext4 file systems.

Uploaded by

Fresh Juice
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

HowTos/GrubInstallation

[FrontPage] [TitleIndex] [WordIndex]

This is a read-only archived version of


wiki.centos.org
Grub Installation for CentOS 5 and 6
This document explains how to install or re-install the Grub boot loader under CentOS 5 and 6. You may
have to re-install Grub if the boot loader was damaged or destroyed, for example by installing an
incompatible operating system.

Contents
1. Grub naming conventions
2. Create or edit the configuration file /boot/grub/grub.conf
3. Installing Grub using grub-install
4. Alternative: Installing boot loader only using grub
5. Notes and warnings
1. Using a separate partition for /boot
2. Grub and ext4fs
3. Using the Grub command line from the boot loader
4. Using Grub to boot a Windows partition
6. More information

Installing Grub consists of three steps:

1. Creating the configuration file /boot/grub/grub.conf.


2. Installing the Grub files in /boot/grub.
3. Installing the Grub boot loader.

The 2nd and 3rd steps can be done using a single command, grub-install. Alternatively, the 3rd step can
be done using the grub command.

1. Grub naming conventions


Grub designates disks and partitions as follows:

1. All disks are designated as hd, whether they are IDE (PATA), SATA or SCSI disks, and whether they
would usually be designated using hd or sd.
2. All disks and partitions are numbered starting with 0 rather than 1.
3. Extended partitions are counted from 4, regardless of the actual number of primary partitions on the
hard disk.
4. The first number indicates the disk; the second number (if present) indicates the partition.

Examples:

Grub designation Meaning Usual designation


(hd0) First hard disk /dev/sda (or /dev/hda)
(hd1) Second hard disk /dev/sdb (or /dev/hdb)
(hd0,0) First hard disk, first partition /dev/sda1 (or /dev/hda1)
(hd1,0) Second hard drive, first partition /dev/sdb1 (or /dev/hdb1)
(hd1,1) Second hard drive, second partition /dev/sdb2 (or /dev/hdb2)

2. Create or edit the configuration file /boot/grub/grub.conf


First, you should create or edit the configuration file, /boot/grub/grub.conf. If the Grub boot loader
hasn't been installed on your hard disk, you should create the configuration file before installing the boot
loader.

In some distributions, the configuration file is /boot/grub/menu.lst. In CentOS,


/boot/grub/menu.lst is a link to /boot/grub/grub.conf, which is the real configuration file.

This file contains the following information:

1. The default boot partition.


2. How long to wait before automatically booting the default partition.
3. Optionally, a nice splash image to show while waiting for the user's input.
4. The various boot partitions which the user can choose.

Example:

(The numbers before each line should not be written. They refer to the explanations after the sample file.)

1 default=0
2 timeout=10
3 splashimage=(hd0,5)/boot/grub/splash.xpm.gz

4 title CentOS 5.6 i686


5 root (hd0,5)
6 kernel /boot/vmlinuz-2.6.18-238.19.1.el5.centos.plusPAE ro root=/dev/sda6 rhgb
noquiet
7 initrd /boot/initrd-2.6.18-238.19.1.el5.centos.plusPAE.img

8 title Linux Mint 11


9 root (hd0,9)
10 kernel /boot/vmlinuz-2.6.32-26-generic-pae ro root=/dev/sda10
11 initrd /boot/initrd.img-2.6.32-26-generic-pae

If you have a separate partition for /boot, see the note below.

Explanations:
1. By default, boot the 1st partition listed below. Remember that Grub starts counting with 0, not 1.

2. Wait 10 seconds for user input before booting default.

3. Show splash image while waiting for user input (optional).

4. Name of 1st possible boot partition. In this case, it's the default boot partition (see line 1).

5. Indicate root partition, using Grub naming conventions.

6. This line consists of 5 parts, as follows:

kernel /boot/vmlinuz-2.6.18-238.19.1.el5.centos.plusPAE

Location of kernel (vmlinuz), using conventional naming system.

ro

Mount partition "ro" (read-only) at first, to run fsck if necessary.

root=/dev/sda6

Location of root partition, using conventional naming system. The root partition can also be identified using
the file system's UUID (universally unique identifier) as follows: root=UUID=134d2a24-2699-4b0c-
823b-1e13633f3b07. CentOS now uses UUIDs by default. You can find a file system's UUID with the
following command: tune2fs -l /dev/sda6.

rhgb

Use graphical boot (Red Hat Graphical Boot). Omit if you want text-only boot.

noquiet

Be more verbose. Omit for less verbose booting.

7. Location of initial ramdisk (initrd or initramfs), using conventional naming system.

8. Name of 2nd possible boot partition.

9. Indicate root partition, using Grub naming conventions.

10. This line consists of 3 parts, as follows:

kernel /boot/vmlinuz-2.6.32-26-generic-pae

Location of kernel (vmlinuz), using conventional naming system.

ro

Mount partition "ro" (read-only) at first, to run fsck if necessary.

root=/dev/sda10
Location of root partition, using conventional naming system. See also the comment about UUIDs in line 6.

11. Location of initial ramdisk (initrd or initramfs), using conventional naming system.

3. Installing Grub using grub-install


The easiest way to install Grub, if possible, is using the command grub-install.

This command will:

1. Install the necessary files in /boot/grub of the current partition.


2. Install the boot loader in the location indicated, using the traditional naming system.

Examples:

Command Meaning
Install Grub files in directory /boot/grub of current partition. Install boot
grub-
loader in master boot record of first hard disk. This is the recommended
install /dev/sda
way to install Grub.
grub- Install Grub files in directory /boot/grub of current partition. Install boot
install /dev/sda1 loader in first partition of first hard disk.
grub- Install Grub files in directory /boot/grub of current partition. Install boot
install /dev/sda2 loader in second partition of first hard disk.

[root@localhost ~]# grub-install /dev/sda


Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.

# this device map was generated by anaconda


(hd0) /dev/sda
[root@localhost ~]#

4. Alternative: Installing boot loader only using grub


It is also possible to use the grub command to install the boot loader, but not the Grub files in /boot/grub.
This can be useful to repair a Grub installation if the boot loader was overwritten or damaged.

1. Do grub.
2. Optionally, do find /boot/grub/stage1 to find which partitions have the required Grub files in
/boot/grub. If you have a separate partition for /boot, do find /grub/stage1 instead.
3. Do root [partition using Grub convention] to indicate the partition which has the Grub
files in /boot/grub and the /boot/grub/grub.conf configuration file.
4. Install the boot loader using setup [location of boot loader using Grub convention].
5. Do quit to leave the Grub programme.

Example:
[root@localhost ~]# grub
Probing devices to guess BIOS drives. This may take a long time.

GNU GRUB version 0.97 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]

grub> find /boot/grub/stage1


(hd0,5)
(hd0,9)

grub> root (hd0,5)


Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)


Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 15 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd0) (hd0)1+15 p
(hd0,5)/boot/grub/stage2
/boot/grub/grub.conf"... succeeded
Done.

grub> quit

5. Notes and warnings


5.1. Using a separate partition for /boot

If you have a separate partition for /boot, the lines starting with root, kernel and initrd in
/boot/grub/grub.conf must be modified as follows:

The line starting with root must indicate the partition for /boot, not the partition for /.
The line starting with kernel must assume that the kernel (vmlinuz) is in /, not in /boot. However,
the command root in that line must indicate the partition for /, not the partition for /boot.
The line starting with initrd must assume that the initial ramdisk (initrd or initramfs) is in /,
not in /boot.

Example:

The /boot partition is /dev/sda1, or hd(0,0). The / partition is /dev/sda2, or hd(0,1). The file
/boot/grub/grub.conf must indicate the following:

title CentOS 5.6 i686


root (hd0,0)
kernel /vmlinuz-2.6.18-238.19.1.el5.centos.plusPAE ro root=/dev/sda2
initrd /initrd-2.6.18-238.19.1.el5.centos.plusPAE.img

5.2. Grub and ext4fs


Grub from CentOS 5 doesn't work with ext4fs. More precisely, it can't read the 256-byte inodes that ext4fs
uses by default.

There are two possible solutions:

Use Grub from CentOS 6, which works properly with ext4fs.


Create an ext4 file system with 128-byte inodes, by using the command mkfs.ext4 -I 128. This
will mean that some capabilities of ext4fs won't be available.

5.3. Using the Grub command line from the boot loader

Commands can be given to Grub from the boot loader itself. Type c at the boot menu, and then give Grub the
same commands that would be in the /boot/grub/grub.conf configuration file.

This can be useful if there are mistakes in the configuration file.

Example:

grub> find /boot/grub/stage1


(hd0,5)

grub> root (hd0,5)

grub> kernel /boot/vmlinuz-2.6.18-238.19.1.el5.centos.plusPAE ro root=/dev/sda6

grub> initrd /boot/initrd-2.6.18-238.19.1.el5.centos.plusPAE.img

grub> boot

You can also edit a line in /boot/grub/grub.conf from the Grub boot loader with the e command. For
example, to boot Linux in single-user mode (runlevel 1), edit the line with the kernel command by adding 1
at the end. Then type b to boot.

5.4. Using Grub to boot a Windows partition

To boot a Windows partition using Grub, add a "stanza" similar to this one in /boot/grub/grub.conf:

Example:

title Windows
rootnoverify (hd0,0)
makeactive
chainloader +1

6. More information
For complete information on Grub, do info grub.
How to re-install bootstrap code (GRUB)
Troubleshooting GRUB Issues
Information on Grub from RHEL's Installation Guide
Created by YvesBellefeuille

2023-09-11 07:22

You might also like