修復錯誤配置fstab文件導致系統無法正常啓動

修復錯誤配置fstab文件導致系統無法正常啓動

 

 1. 問題再現

 1.1. 操作環境說明

    操作系統:CentOS5.2

    硬盤分區情況:   

[root@localhost ~]# fdisk /dev/sda

 

The number of cylinders for this disk is set to 1305.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

 

Command (m for help): p

 

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1         522     4192933+  83  Linux

/dev/sda2             523         783     2096482+  83  Linux

/dev/sda3             784         914     1052257+  82  Linux swap / Solaris

 

Command (m for help): v

6288172 unallocated sectors

    fstab文件:

[root@localhost ~]# more /etc/fstab

LABEL=/                 /                       ext3    defaults        1 1

LABEL=/tmp              /tmp                    ext3    defaults        1 2

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

LABEL=SWAP-sda3         swap                    swap    defaults        0 0

   

 1.2. 創建新的分區,並配置fstab文件

 1.2.1. 創建分區

    /dev/sda上創建新的主分區sda4

[root@localhost ~]# fdisk /dev/sda

 

The number of cylinders for this disk is set to 1305.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

 

Command (m for help): p

 

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1         522     4192933+  83  Linux

/dev/sda2             523         783     2096482+  83  Linux

/dev/sda3             784         914     1052257+  82  Linux swap / Solaris

 

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Selected partition 4

First cylinder (915-1305, default 915):

Using default value 915

Last cylinder or +size or +sizeM or +sizeK (915-1305, default 1305):

Using default value 1305

 

Command (m for help): p

 

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1         522     4192933+  83  Linux

/dev/sda2             523         783     2096482+  83  Linux

/dev/sda3             784         914     1052257+  82  Linux swap / Solaris

/dev/sda4             915        1305     3140707+  83  Linux

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

    創建文件系統,將Label設置爲other

[root@localhost ~]# mke2fs -j -L other /dev/sda4

mke2fs 1.39 (29-May-2006)

Filesystem label=other

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

393216 inodes, 785176 blocks

39258 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=805306368

24 block groups

32768 blocks per group, 32768 fragments per group

16384 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912

 

Writing inode tables: done                           

Creating journal (16384 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 20 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

[root@localhost ~]# e2label /dev/sda4

other

    Mount /dev/sda4/others

[root@localhost /]# mkdir /others

[root@localhost /]# mount /dev/sda4 /others

[root@localhost /]# mount

/dev/sda1 on / type ext3 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

/dev/sda2 on /tmp type ext3 (rw)

tmpfs on /dev/shm type tmpfs (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

/dev/sda4 on /others type ext3 (rw)

[root@localhost /]# cd /others

[root@localhost others]# ls -l

total 16

drwx------ 2 root root 16384 Nov 21 19:35 lost+found

[root@localhost others]#

    修改fstab文件

[root@localhost /]# vi /etc/fstab

LABEL=/                 /                       ext3    defaults        1 1

LABEL=/tmp              /tmp                    ext3    defaults        1 2

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

LABEL=SWAP-sda3         swap                    swap    defaults        0 0

LABEL=/other            /others                 ext3    defaults        1 2

    請注意:這裏用到是LABEL而不是設備名(/dev/sda4),但是這裏把卷標寫錯,應該是other,前面沒有 /

    並且沒有運行mount -a命令來驗證配置是否正確。

    接着就直接重啓系統了(init 6)。

[root@localhost /]# init 6

   

 1.3. 問題的出現

 1.3.1. 在重啓時遇到問題

 


1.1

    系統發現fstab中的LABEL=/other卷標不存在。

 

 2. 故障的解決過程

 2.1. 進入運行級別1

    輸入root用戶密碼,進入運行級別1   


2.1

    此時試圖修改/etc/fstab文件


2.2

    此時發現文件系統是隻讀的

    重新mount /


2.3

    再次修改fstab文件   


2.4

    修改完成,重啓系統(init 6)。

    系統可以正常啓動,問題解決了。


2.5

 

 3. 問題總結

    以上問題的出現是由於錯誤配置了/etc/fstab文件,在系統重啓時,無法識別卷標(/other),從而導致無法正常啓動。如果在修改/etc/fstab文件後,運行mount -a命令驗證一下配置是否正確,則可以避免此類問題。

    問題的修復方法不僅適用於以上所描述的問題,同樣可以處理由於錯誤修改配置導致系統無法啓動的其他問題。

    問題的解決過程中,重新mount /是比較關鍵的一步(mount -n -o remount,rw /)。如果沒有此步操作,則文件系統處於只讀狀態,導致不能修改配置文件並保存,修復存在的問題。

    

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章