grub命令來引導linux

來源:互聯網
上載者:User

標籤:style   io   os   ar   strong   for   檔案   div   sp   

由於對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]

或下面的輸入,以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
  以上也就這麼多,還須自己多揣摩

grub命令來引導linux

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.