Briefly, boot loader is the first software program that runs when acomputer starts. It is responsible for loading and transferring controlto the operating system kernel software (such as the Hurd or theLinux). The kernel, in turn, initializes the rest of the operatingsystem (e.g. GNU).
GNU GRUB is a Multiboot boot loader. It was derived from GRUB, GRandUnified Bootloader, which was originally designed and implemented byErich Stefan Boleyn.
root@localhost ~]#tar zxvf grub*.tar.gz
[root@localhost ~]#cd grub-xxx
[root@localhost ~]#./configure;make;make install确认您是否成功安装了GRUB,您可以测试是否有如下两个命令;
[root@localhost ~]# grub
[root@localhost ~]# grub-install如果您不能找到这两个命令,可能您的可执行程序的路径没有设置;
[root@localhost ~]# /usr/sbin/grub
[root@localhost ~]# /usr/sbin/grub-install
[root@localhost ~]# updatedb 注:这个要花很长时间;是索引slocate 的库,然后再通过locate来查找;
[root@localhost ~]# locate grub
[root@localhost ~]# locate grub
/sbin/grub-md5-crypt
/sbin/grub
/sbin/grub-install
/sbin/grub-terminfo
[beinan@localhost ~]$ su - 注:切换到root用户,并且切换到其家目录;
Password:
[root@localhost ~]#/sbin/grub 注:用绝对路径来运行grub命令;
[root@localhost ~]# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 970 7791493+ 7 HPFS/NTFS
/dev/hda2 971 9729 70356667+ 5 Extended
/dev/hda5 971 2915 15623181 b W95 FAT32
/dev/hda6 2916 4131 9767488+ 83 Linux
/dev/hda7 4132 5590 11719386 83 Linux
/dev/hda8 5591 6806 9767488+ 83 Linux
/dev/hda9 6807 9657 22900626 83 Linux
/dev/hda10 9658 9729 578308+ 82 Linux swap / Solaris如果通过fdisk -l 出现有/dev/hda字样的,我们就要用下面的命令来安装;
[root@localhost ~]# grub-install /dev/hda
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'.
(fd0) /dev/fd0
(hd0) /dev/hda如果是您fdisk -l 出现的有/dev/hdb呢,那就如下运行;
[root@localhost ~]# grub-install /dev/hdb如果既有/dev/hda和/dev/hdb 就安装到/dev/hda中;
[root@localhost ~]# grub-install /dev/hda值得注意的是如果您有一个/boot分区,应该用如下的办法来安装;
[root@localhost ~]#grub-install --root-directory=/boot /dev/hda
[root@localhost ~]#grub-install --root-directory=/boot /dev/hdb
[root@localhost ~]# grub
grub> find /boot/grub/stage1
(hd0,6)
(fd0) 注:这个是软驱;现在很少用软驱了,如果您有这方面的需要,自己看GRUB的DOC吧;注解:
(hd0,6) 这是/boot所在的分区;不要误解为是Linux 的/所在的分区,这是值得注意的;
(fd0) 注:这个是软驱;现在很少用软驱了,如果您有这方面的需要,自己看GRUB的DOC吧;
grub>root (hd0,6) 注:这是/boot所在的分区;
grub>setup (hd0) 注:把GRUB写到MBR上;
[root@localhost ~]# cd /boot/grub
[root@localhost ~]# ln -s menu.lst grub.conf
default=0
timeout=5
#splashimage=(hd0,6)/boot/grub/splash.xpm.gz
hiddenmenu
title Fedora Core (2.6.11-1.1369_FC4)
root (hd0,6)
kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/
initrd /boot/initrd-2.6.11-1.1369_FC4.img
title WinXp
rootnoverify (hd0,0)
chainloader +1
kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/
[root@localhost ~]# df -lh
[root@localhost ~]# ls /boot/vmlinuz*
/boot/vmlinuz-2.6.11-1.1369_FC4 注:看到内核vmlinuz所处的目录; 于是我们就可以这样kernel 这行了;
kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7
[root@localhost ~]# ls /boot/initrd*
/boot/initrd-2.6.11-1.1369_FC4.img如果是通过df -lh 得知或查看/etc/fstab 也行, 得知/boot是独立的分区;这时initrd 应该写成;
initrd /initrd-2.6.11-1.1369_FC4.img如果是 /boot不是独处一个分区,而是在/同一处一个分区, 则要写成;
initrd /boot/initrd-2.6.11-1.1369_FC4.img
[root@localhost ~]# df -lh
Filesystem 容量 已用 可用 已用% 挂载点
/dev/hda7 11G 9.2G 1.2G 90% /
/dev/shm 236M 0 236M 0% /dev/shm然后我们/etc/fstab 中,查看/分所在的分区或分区标签是什么;
[root@localhost ~]# more /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/ / ext3 defaults 1 1
/dev/devpts /dev/pts devpts gid=5,mode=620 0 0
/dev/shm /dev/shm tmpfs defaults 0 0
/dev/proc /proc proc defaults 0 0
/dev/sys /sys sysfs defaults 0 0
LABEL=SWAP-hda1 swap swap defaults 0 0
/dev/hdc /media/cdrecorder auto pamconsole,exec,noauto,managed 0 0
[root@localhost ~]# ls -lh /boot/vmlinuz*
-rw-r--r-- 1 root root 1.6M 2005-06-03 /boot/vmlinuz-2.6.11-1.1369_FC4
[root@localhost ~]# ls -lh /boot/initrd*
-rw-r--r-- 1 root root 1.1M 11月 26 22:30 /boot/initrd-2.6.11-1.1369_FC4.img
default=0
timeout=5
title FC4
root (hd0,6)
kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/
initrd /boot/initrd-2.6.11-1.1369_FC4.img也可以写成;
default=0
timeout=5
title FC4
root (hd0,6)
kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7
initrd /boot/initrd-2.6.11-1.1369_FC4.img
default=0
timeout=5
title FC4x
kernel (hd0,6)/boot/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7
initrd (hd0,6)/boot/initrd-2.6.11-1.1369_FC4.img
[root@localhost ~]# df -lh
Filesystem 容量 已用 可用 已用% 挂载点
/dev/hda6 200M 120M 80M 60% /boot
/dev/hda7 11G 9.2G 1.2G 90% /我们再进一行查看/etc/fstab 得知;
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2所以我们应该写成如下的;
title FC4x
kernel (hd0,5)/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/
initrd (hd0,5)/initrd-2.6.11-1.1369_FC4.img因为Linux的根分区是/dev/hda7,通过/etc/fstab和df -h的内容得知标签为 LABEL=/的分区就是/dev/hda7 ,所以有;
title FC4x
kernel (hd0,5)/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7
initrd (hd0,5)/initrd-2.6.11-1.1369_FC4.img
grub>
grub> help
blocklist FILE boot
cat FILE chainloader [--force] FILE
clear color NORMAL [HIGHLIGHT]
configfile FILE device DRIVE DEVICE
displayapm displaymem
find FILENAME geometry DRIVE [CYLINDER HEAD SECTOR [
halt [--no-apm] help [--all] [PATTERN ...]
hide PARTITION initrd FILE [ARG ...]
kernel [--no-mem-option] [--type=TYPE] makeactive
map TO_DRIVE FROM_DRIVE md5crypt
module FILE [ARG ...] modulenounzip FILE [ARG ...]
pager [FLAG] partnew PART TYPE START LEN
parttype PART TYPE quit
reboot root [DEVICE [HDBIAS]]
rootnoverify [DEVICE [HDBIAS]] serial [--unit=UNIT] [--port=PORT] [--
setkey [TO_KEY FROM_KEY] setup [--prefix=DIR] [--stage2=STAGE2_
terminal [--dumb] [--no-echo] [--no-ed terminfo [--name=NAME --cursor-address
testvbe MODE unhide PARTITION
uppermem KBYTES vbeprobe [MODE]如果需要得到某个指令的帮助,就在 help 后面空一格,然后输入指令,比如;
grub>help kernel
grub> cat ( 按tab 键会出来hd0或hd1之类的;
grub> cat (hd0, 注:输入hd0,然后再按tab键;会出来分区之类的;
grub> cat (hd0,6)
Possible partitions are:
Partition num: 0, Filesystem type unknown, partition type 0x7
Partition num: 4, Filesystem type is fat, partition type 0xb
Partition num: 5, Filesystem type is reiserfs, partition type 0x83
Partition num: 6, Filesystem type is ext2fs, partition type 0x83
Partition num: 7, Filesystem type unknown, partition type 0x83
Partition num: 8, Filesystem type is reiserfs, partition type 0x83
Partition num: 9, Filesystem type unknown, partition type 0x82
grub> cat (hd0,6)/etc/fstab 注:比如我想查看一下 (hd0,6)/etc/fstab的内容就这样输入;
LABEL=/ / ext3 defaults 1 1
/dev/devpts /dev/pts devpts gid=5,mode=620 0 0
/dev/shm /dev/shm tmpfs defaults 0 0
/dev/proc /proc proc defaults 0 0
/dev/sys /sys sysfs defaults 0 0
LABEL=SWAP-hda1 swap swap defaults 0 0
/dev/hdc /media/cdrecorder auto pamconsole,exec,noauto, managed 0 0
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
grub> kernel /boot/
Possible files are: grub initrd-2.6.11-1.1369_FC4.img System.map-2.6.11-1.1369_FC4 config-2.6.11-1.1369_FC4 vmlinuz-2.6.11-1.1369_FC4 grubBAK memtest86+-1.55
.1 xen-syms xen.gz
grub> kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/
[Linux-bzImage, setup=0x1e00, size=0x18e473]
kernel (hd[0-n],y)/boot/vmlinuz ro root=/dev/hd[a-z]X
grub>kernel
kernel (hd[0-n],y)/vmlinuz ro root=/dev/hd[a-z]X grub> kernel (hd0,6)/boot/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7
[Linux-bzImage, setup=0x1e00, size=0x18e473]
grub> kernel (hd0,6)/boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/
[Linux-bzImage, setup=0x1e00, size=0x18e473]
grub> initrd /boot/initrd在这里tab 来补齐;
grub> initrd /boot/initrd-2.6.11-1.1369_FC4.img
[Linux-initrd @ 0x2e1000, 0x10e685 bytes]
grub> initrd /initrd 在这里tab 来补齐;
grub> initrd /initrd-2.6.11-1.1369_FC4.img
[Linux-initrd @ 0x2e1000, 0x10e685 bytes]
grub> cat (hd0,6)/etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/ / ext3 defaults 1 1
/dev/devpts /dev/pts devpts gid=5,mode=620 0 0
/dev/shm /dev/shm tmpfs defaults 0 0
/dev/proc /proc proc defaults 0 0
/dev/sys /sys sysfs defaults 0 0
LABEL=SWAP-hda1 swap swap defaults 0 0
/dev/hdc /media/cdrecorder auto pamconsole,exec,noauto,managed 0 0
grub> root (hd0,6)
Filesystem type is ext2fs, partition type 0x83
grub> kernel /boot/在这里按tab补齐,全列出/boot所有的文件;
Possible files are: grub initrd-2.6.11-1.1369_FC4.imgSystem.map-2.6.11-1.1369_FC4 config-2.6.11-1.1369_FC4vmlinuz-2.6.11-1.1369_FC4
memtest86+-1.55.1 xen-syms xen.gz
grub> kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7 注:输入
[Linux-bzImage, setup=0x1e00, size=0x18e473]
grub> initrd /boot/在这里按tab补齐
Possible files are: grub initrd-2.6.11-1.1369_FC4.imgSystem.map-2.6.11-1.1369_FC4 config-2.6.11-1.1369_FC4vmlinuz-2.6.11-1.1369_FC4
memtest86+-1.55.1 xen-syms xen.gz
grub> initrd /boot/initrd-2.6.11-1.1369_FC4.img 注;输入intrd文件名的全名;
[Linux-initrd @ 0x2e1000, 0x10e685 bytes]
grub> boot
grub> cat (hd0,6)/etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/ / ext3 defaults 1 1
/dev/devpts /dev/pts devpts gid=5,mode=620 0 0
/dev/shm /dev/shm tmpfs defaults 0 0
/dev/proc /proc proc defaults 0 0
/dev/sys /sys sysfs defaults 0 0
LABEL=SWAP-hda1 swap swap defaults 0 0
/dev/hdc /media/cdrecorder auto pamconsole,exec,noauto,managed 0 0
grub> root (hd0,6)
Filesystem type is ext2fs, partition type 0x83
grub> kernel /boot/在这里按tab补齐,全列出/boot所有的文件;
Possible files are: grub initrd-2.6.11-1.1369_FC4.imgSystem.map-2.6.11-1.1369_FC4 config-2.6.11-1.1369_FC4vmlinuz-2.6.11-1.1369_FC4
memtest86+-1.55.1 xen-syms xen.gz
grub> kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/
[Linux-bzImage, setup=0x1e00, size=0x18e473]
grub> initrd /boot/在这里按tab补齐
Possible files are: grub initrd-2.6.11-1.1369_FC4.imgSystem.map-2.6.11-1.1369_FC4 config-2.6.11-1.1369_FC4vmlinuz-2.6.11-1.1369_FC4 grubBAK
memtest86+-1.55.1 xen-syms xen.gz
grub> initrd /boot/initrd-2.6.11-1.1369_FC4.img 注;输入intrd文件名的全名;
[Linux-initrd @ 0x2e1000, 0x10e685 bytes]
grub> boot
grub>kernel (hd0,6)/boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/
grub>initrd (hd0,6)/boot/initrd-2.6.11-1.1369_FC4.img
grub>boot 或
grub>kernel (hd0,6)/boot/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7
grub>initrd (hd0,6)/boot/initrd-2.6.11-1.1369_FC4.img
grub>boot 如果/boot位于 /dev/hda6,也就是(hd0,5),Linux的根/位于分区/dev/hda7,并且我们cat 出来的/etc/fstab 中/分区的标签为 LABEL=/。下面的两种方法都可以引导;
grub>kernel (hd0,5)/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/
grub>initrd (hd0,5)/initrd-2.6.11-1.1369_FC4.img
grub>boot 或
grub>kernel (hd0,5)/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7
grub>initrd (hd0,5)/initrd-2.6.11-1.1369_FC4.img
grub>boot
title WinXp
rootnoverify (hd0,0)
chainloader +1
title WinXp
map (hd0) (hd1)
map (hd1) (hd0)
rootnoverify (hd0,0)
chainloader +1
makeactive
title WinXp
rootnoverify (hd0,2)
chainloader +1
makeactive如果Windows的在第二个硬盘的某个分区,比如说是位于(hd1,2),则要用到map指令;
title WinXp
map (hd0) (hd1)
map (hd1) (hd0)
rootnoverify (hd1,2)
chainloader +1
title Win98
unhide (hd0,0)
hide (hd0,1)
rootnoverify (hd0,0)
chainloader +1
makeactive
title WinXP
unhide (hd0,1)
hide (hd0,0)
rootnoverify (hd0,1)
chainloader +1
makeactive
grub> rootnoverify (hd0,0)
grub> chainloader +1
grub> boot
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |