grub的安装有两种方式:

1、在grub的命令行模式进行安装

[root@Wiker ~]# grub

Probing devices toguess BIOS drives. This may take a long time.



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


[ Minimal BASH-like line editing issupported.  For the first word, TAB

  lists possible command completions.  Anywhere else TAB lists the possible

  completions of a device/filename.]

grub> root (hd0,0)

root (hd0,0)

Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)

setup (hd0)

Checking if "/boot/grub/stage1"exists... no

Checking if "/grub/stage1" exists...yes

Checking if "/grub/stage2" exists...yes

Checking if "/grub/e2fs_stage1_5"exists... yes

Running "embed /grub/e2fs_stage1_5(hd0)"...  27 sectors are embedded.

succeeded

Running "install /grub/stage1 (hd0)(hd0)1+27 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded

Done.

这个方法是可以安装mbr里面的446个字节的内容,不会安装/boot/grub里面的内容,其他的直接复制就可以了,如果连/boot/grub里面的内容都搞丢了的话,可以去/usr/share/grub里面拷贝,里面除了grub.conf没有以为,其他的都有

2、第二种方法:命令行使用grub-install来安装,这种方式分两种情况

1):安装grub到系统所在的硬盘  

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

Installationfinished. No error reported.

This is the contentsof the device map /boot/grub/device.map.

Check if this iscorrect or not. If any of the lines is incorrect,

fix it and re-run thescript `grub-install'.


# this device map wasgenerated by anaconda

(hd0)     /dev/sda

2):安装在服务器上面的第二块硬盘上面,分为三个小步骤

1、给第二块硬盘进行分区

[root@Wiker boot]#fdisk -l /dev/sdb


Disk /dev/sdb: 5368MB, 5368709120 bytes

255 heads, 63sectors/track, 652 cylinders

Units = cylinders of16065 * 512 = 8225280 bytes

Sector size(logical/physical): 512 bytes / 512 bytes

I/O size(minimum/optimal): 512 bytes / 512 bytes

Disk identifier:0x00000000


Disk /dev/sdb doesn'tcontain a valid partition table

[root@Wiker boot]#fdisk /dev/sdb

Device containsneither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOSdisklabel with disk identifier 0x8130427e.

Changes will remainin memory only, until you decide to write them.

After that, ofcourse, the previous content won't be recoverable.


Warning: invalid flag0x0000 of partition table 4 will be corrected by w(rite)


WARNING:DOS-compatible mode is deprecated. It's strongly recommended to

        switch off the mode (command 'c') andchange display units to

        sectors (command 'u').


Command (m for help):n

Command action

  e  extended

  p  primary partition (1-4)

p

Partition number(1-4): 1

First cylinder(1-652, default 1):

Using default value 1

Last cylinder,+cylinders or +size{K,M,G} (1-652, default 652): +100M


Command (m for help):p


Disk /dev/sdb: 5368MB, 5368709120 bytes

255 heads, 63sectors/track, 652 cylinders

Units = cylinders of16065 * 512 = 8225280 bytes

Sector size(logical/physical): 512 bytes / 512 bytes

I/O size(minimum/optimal): 512 bytes / 512 bytes

Disk identifier:0x8130427e


  Device Boot      Start         End      Blocks  Id  System

/dev/sdb1               1          14      112423+ 83  Linux


Command (m for help):w

The partition tablehas been altered!


Calling ioctl() tore-read partition table.

Syncing disks.

[root@Wiker boot]#partprobe /dev/sdb

[root@Wiker boot]#cat /proc/partitions

major minor  #blocks name


  8       0  125829120 sda

  8       1     262144 sda1

  8       2   79872000 sda2

  8       3     524288 sda3

  8      16    5242880 sdb

8       17    112423 sdb1

253       0   59604992 dm-0

253       1     524288 dm-1

[root@Wiker boot]#mkfs.ext4 /dev/sdb1

mke2fs 1.41.12(17-May-2010)

Filesystem label=

OS type: Linux

Block size=1024(log=0)

Fragment size=1024(log=0)

Stride=0 blocks,Stripe width=0 blocks

28112 inodes, 112420blocks

5621 blocks (5.00%)reserved for the super user

First data block=1

Maximum filesystemblocks=67371008

14 block groups

8192 blocks pergroup, 8192 fragments per group

2008 inodes per group

Superblock backupsstored on blocks:

8193,24577, 40961, 57345, 73729


Writing inode tables:done                            

Creating journal(4096 blocks): done

Writing superblocksand filesystem accounting information: done


This filesystem willbe automatically checked every 33 mounts or

180 days, whichevercomes first.  Use tune2fs -c or -i tooverride.

2、创建目录,一定要叫boot,然后把刚才的分区挂载到boot上面

[root@Wiker boot]#mkdir /mnt/boot

[root@Wiker boot]#mount /dev/sdb1 /mnt/boot/

[root@Wiker boot]# cd/mnt/boot/

[root@Wiker boot]# ls

lost+found

3使用grub-install进行安装,需要制定root-directory目录

[root@Wiker boot]#grub-install --root-directory=/mnt/ /dev/sdb

Probing devices toguess BIOS drives. This may take a long time.

Installationfinished. No error reported.

This is the contentsof the device map /mnt//boot/grub/device.map.

Check if this iscorrect or not. If any of the lines is incorrect,

fix it and re-run thescript `grub-install'.


(fd0)        /dev/fd0

(hd0)        /dev/sda

(hd1)        /dev/sdb

[root@Wiker boot]#pwd

/mnt/boot

[root@Wiker boot]# ls

grub  lost+found

[root@Wiker boot]# ls grub/  

device.map     iso9660_stage1_5   stage1           xfs_stage1_5

e2fs_stage1_5  jfs_stage1_5       stage2

fat_stage1_5   minix_stage1_5     ufs2_stage1_5

ffs_stage1_5   reiserfs_stage1_5  vstafs_stage1_5