天天看點

grub指令來引導linux

由于對linux系統的好奇,想按在機器上玩玩。昨天忙活了一晚上,最終才把linux安裝好。但高興的有點太早了,我還以為進linux就像進 windows那麼簡單哪,沒有想到卻蹦出來一個引導指令(grub),讓我引導,我一看麻木了。一點也不會。沒有辦法我實在熬不住了,就關機睡了。今天 中午,上網查資料。把有關的指令給熟悉了一邊。不過看後挺費勁的。試了幾次還是不行。我就沒有弄了。本打算放棄的。沒有想到下午來靈感了。敲幾個指令就進 了。

這次安裝讓我學到了不少。下面來主要講一下在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]

grub> kernel (hd0,0)/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]

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

以上也就這麼多,還須自己多揣摩

繼續閱讀