在grub下引導linux;
其步驟如下;
a 進入grub的命令模式。
b 先熟悉一下grub 的一些命令
grub>help
c 熟悉一下cat命令
d root指令來指定/boot所在的分區
e kernel指令來指定linux的內核,及所在的分區
f 用initrd命令來指定initrd文件
g boot引導系統
cat命令的用法
cat指令是用來查看文件內容的,有時我們不知道Linux的/boot分區,以及/根分區所在的位置,要查看/etc/fstab的內容來得知, 這時,我們就要用到cat (hd[0-n],y)/etc/fstab 來獲得這些內容;注意要學會用tab鍵命令補齊的功能;
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
主要查看/etc/fstab中的內容,主要是Linux的/分區及/boot是否是獨立的分區;如果沒有/boot類似的行,證明/boot和 Linux的/處於同一個硬盤分區;比如上面的例子中LABEL=/ 這行是極為重要的;說明Linux系統就安在標簽為LABEL=/的分區中;
如果您的Linux系統/boot和/沒有位於同一個分區,可能cat (hd[a-n],y) 查到的是類似下面的;
LABEL=/ / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 root (hd[0-n,y) 指令來指定/boot所在的分區;
其實這個root (hd[0,n],y)是可以省略的,如果省略了,我們要在kerenl 命令中指定;我們前面已經說過 (hd[0-n],y) 硬盤分區的表示方法的用途;主要是用來指定 /boot所在的分區;
eg:
grub> root (hd0,0)
kernel 指令,用來指定Linux的內核,及/所在的分區;
kernel 這個指令可能初學者有點怕,不知道內核在哪個分區,及內核文件名的全稱是什么。不要忘記tab鍵的命令補齊的應用;
如果我們已經通過root (hd[0-n],y) 指定了/boot所在的分區,語法有兩個:
如果/boot和Linux的/位於同一個分區,應該是下面的一種格式;
kernel /boot/vmlinuz在這里按tab鍵來補齊,就看到內核全稱了 ro root=/dev/hd[a-z]X
如果/boot有自己獨立的分區,應該是;
kernel /vmlinuz在這里按tab鍵來補齊,就看到內核全稱了 ro root=/dev/hd[a-z]X
在這里 root=/dev/hd[a-z]X 是Linux 的/根所位於的分區,如果不知道是哪個分區,就用tab出來的來計算,一個一個的嘗試;或用cat (hd[0-n],y)/etc/fstab 中得到Linux的/所在的分區或分區的標簽;
grub> kernel /boot/在這里按tab鍵;這樣就列出/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]
注解: root=LABEL=/ 是Linux的/所在的分區的文件系統的標簽;如果您知道Linux的/在哪個具體的分區,用root=/dev/hd[a-z]X來指定也行。比如下面的一行也是可以的;
grub> kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7
也可以把/boot所在的分區的指定 root (hd[0-n],y)這行省掉,直接在kernel 中指定/boot所在的分區;所以就在下面的語法;
如果是/boot和Linux的根同處一個分區;
kernel (hd[0-n],y)/boot/vmlinuz ro root=/dev/hd[a-z]X
比如:
grub>kernel
如果是/boot和Linux所在的根不在一個分區;則是;
kernel (hd[0-n],y)/vmlinuz ro root=/dev/hd[a-z]X grub> kernel (hd0,0)/boot/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7 [Linux-bzImage, setup=0x1e00, size=0x18e473]
或下面的輸入,以cat 出/etc/fstab內容為准;
grub> kernel (hd0,0)/boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/ [Linux-bzImage, setup=0x1e00, size=0x18e473]
initrd 命令行來指定initrd文件;
grub> initrd /boot/initrd在這里tab 來補齊; grub> initrd /boot/initrd-2.6.11-1.1369_FC4.img [Linux-initrd @ 0x2e1000, 0x10e685 bytes]
如果/boot是獨立的一個分區,應該是如下樣子的語法;比如下面的;
grub> initrd /initrd在這里tab 來補齊; grub> initrd /initrd-2.6.11-1.1369_FC4.img [Linux-initrd @ 0x2e1000, 0x10e685 bytes]
boot 引導系統;
grub>boot
下面是在我機器上的命令:
grub> cat (hd0,0)/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,0) Filesystem type is ext2fs, partition type 0x83 grub> kernel /boot/在這里按tab補齊,全列出/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 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.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> initrd /boot/initrd-2.6.11-1.1369_FC4.img 注;輸入intrd文件名的全名; [Linux-initrd @ 0x2e1000, 0x10e685 bytes] grub> boot