Linux

grub 總是會啟動到 grub 命令行

  • September 16, 2013

我有一個遠端 CentOS 6.4 伺服器(具有 KVM 訪問權限),當我收到它在單個磁碟 (sda) 上使用 LVM 執行的伺服器時

我設法刪除了 LVM 並在 sda 和 sdb 磁碟中安裝了 raid 1

鏡像工作正常,我現在唯一的問題是每次重新啟動伺服器時,我都會得到 grub 命令行,並且我已經使用命令手動啟動

grub> 配置文件 (hd1,0)/grub/grub.conf

或者

grub> 配置文件 (hd0,0)/grub/grub.conf

然後它將正常啟動而沒有任何錯誤。

知道如何讓它自動啟動嗎?

注意:每個磁碟(sda 和 sdb)都是 2TB 大小,這可能是問題嗎?

我的設置

Filesystem            Size  Used Avail Use% Mounted on
/dev/md2              1.8T  1.1G  1.7T   1% /
tmpfs                  16G     0   16G   0% /dev/shm
/dev/md0              1.9G   69M  1.8G   4% /boot


# cat /proc/mdstat 

Personalities : [raid1] 
md2 : active raid1 sda3[2] sdb3[0]
       1940882240 blocks super 1.2 [2/2] [UU]

md1 : active raid1 sdb2[0] sda2[2]
      10482176 blocks super 1.2 [2/2] [UU]

md0 : active raid1 sdb1[0] sda1[1]
      2008000 blocks [2/2] [UU]

 unused devices: <none>

# fdisk -l /dev/sda

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b0530

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         250     2008093+  83  Linux
/dev/sda2             251        1556    10490445   82  Linux swap / Solaris
/dev/sda3            1557      243201  1941013462+  fd  Linux raid autodetect


# fdisk -l /dev/sdb

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xadb3bd62

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         250     2008093+  fd  Linux raid autodetect
/dev/sdb2             251        1556    10490445   82  Linux swap / Solaris
/dev/sdb3            1557      243201  1941013462+  fd  Linux raid autodetect

# cat grub.conf 


# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/vg_srv6953-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd1,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-358.18.1.el6.x86_64)
   root (hd1,0)
   kernel /vmlinuz-2.6.32-358.18.1.el6.x86_64 ro root=/dev/md2 KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 crashkernel=auto rhgb quiet rd_retry=20
   initrd /initramfs-2.6.32-358.18.1.el6.x86_64.img
title CentOS (2.6.32-358.el6.x86_64)
   root (hd1,0)
   kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=/dev/md2  KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 crashkernel=auto rhgb quiet
   initrd /initramfs-2.6.32-358.el6.x86_64.img



# grub
Probing devices to guess BIOS drives. This may take a long time.


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

[ Minimal BASH-like line editing is supported.  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 0xfd
grub> setup (hd0)
setup (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  27 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd0) (hd0)1+27 p (hd0,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
Done.

好的

我做了以下事情:

  1. 從 raid 中刪除 sda(使用 mdadm)
  2. 執行 dd (dd if=/dev/zero of=/dev/sda bs=512 count=1000)
  3. 複製目前磁碟分區表(sfdisk -d /dev/sdb | sfdisk /dev/sda)
  4. 將磁碟添加到 RAID(使用 mdadm)
  5. 重新安裝 grub(使用 grub 命令)
  6. 執行 grub-install /dev/sda
  7. 重啟

現在它正在工作:)

除了第2步之外,我之前做了所有上述步驟,看來我需要用dd清除磁碟

您需要在伺服器硬碟設備上重新安裝 grub。要知道設備地址,請輸入終端

 sudo fdisk -l

這將在列表中列出磁碟及其卷。記下需要安裝 grub 的設備。你的設備的大小會給你一個提示。如果 /dev/sda 是需要安裝 grub 的設備,請轉到終端並鍵入

sudo grub-install /dev/sda

重新啟動伺服器並檢查問題是否已解決。

引用自:https://serverfault.com/questions/539068