fstab損壞修復過程總結

1. 創建錯誤環境

1.1 操作系統說明

操作系統:CentOS 5.8

硬盤分區情況:

  1. [root@hooper ~]# fdisk /dev/sda 
  2.  
  3. The number of cylinders for this disk is set to 1305. 
  4. There is nothing wrong with that, but this is larger than 1024, 
  5. and could in certain setups cause problems with: 
  6. 1) software that runs at boot time (e.g., old versions of LILO) 
  7. 2) booting and partitioning software from other OSs 
  8.    (e.g., DOS FDISK, OS/2 FDISK) 
  9.  
  10. Command (m for help): p   #顯示分區表 
  11.  
  12. Disk /dev/sda: 10.7 GB, 10737418240 bytes 
  13. 255 heads, 63 sectors/track, 1305 cylinders 
  14. Units = cylinders of 16065 * 512 = 8225280 bytes 
  15.  
  16.    Device Boot      Start         End      Blocks   Id  System 
  17. /dev/sda1   *           1          19      152586   83  Linux 
  18. /dev/sda2              20          52      265072+  82  Linux swap / Solaris 
  19. /dev/sda3              53        1305    10064722+  83  Linux 
  20.  
  21. Command (m for help): v 
  22. 6757 unallocated sectors 

fstab文件:

  1. [root@hooper ~]# cat /etc/fstab 
  2. LABEL=/                 /                       ext3    defaults        1 1 
  3. LABEL=/boot             /boot                   ext3    defaults        1 2 
  4. tmpfs                   /dev/shm                tmpfs   defaults        0 0 
  5. devpts                  /dev/pts                devpts  gid=5,mode=620  0 0 
  6. sysfs                   /sys                    sysfs   defaults        0 0 
  7. proc                    /proc                   proc    defaults        0 0 
  8. LABEL=SWAP-sda2         swap                    swap    defaults        0 0 

1.2 創建一個錯誤的分區

添加新硬盤,創建新的分區,並配置fstab文件
添加一塊新的硬盤,並創建分區:在/dev/sdb上創建新的主分區sdb1

  1. [root@hooper ~]# fdisk /dev/sdb 
  2.  
  3. Command (m for help): p 
  4.  
  5. Disk /dev/sdb: 536 MB, 536870912 bytes 
  6. 64 heads, 32 sectors/track, 512 cylinders 
  7. Units = cylinders of 2048 * 512 = 1048576 bytes 
  8.  
  9.    Device Boot      Start         End      Blocks   Id  System 
  10.  
  11. Command (m for help): n #創建分區 
  12. Command action 
  13.    e   extended 
  14.    p   primary partition (1-4) 
  15. Partition number (1-4): 1 
  16. First cylinder (1-512, default 1):  
  17. Using default value 1 
  18. Last cylinder or +size or +sizeM or +sizeK (1-512, default 512):  
  19. Using default value 512 
  20.  
  21. Command (m for help): p 
  22.  
  23. Disk /dev/sdb: 536 MB, 536870912 bytes 
  24. 64 heads, 32 sectors/track, 512 cylinders 
  25. Units = cylinders of 2048 * 512 = 1048576 bytes 
  26.  
  27.    Device Boot      Start         End      Blocks   Id  System 
  28. /dev/sdb1               1         512      524272   83  Linux 
  29.  
  30. Command (m for help): w 
  31. The partition table has been altered! 
  32.  
  33. Calling ioctl() to re-read partition table. 
  34. Syncing disks. 

創建文件系統

  1. [root@hooper ~]# mke2fs -j -L other /dev/sdb1 
  2. mke2fs 1.39 (29-May-2006) 
  3. Filesystem label=other 
  4. OS type: Linux 
  5. Block size=1024 (log=0
  6. Fragment size=1024 (log=0
  7. 131072 inodes, 524272 blocks 
  8. 26213 blocks (5.00%) reserved for the super user 
  9. First data block=1 
  10. Maximum filesystem blocks=67633152 
  11. 64 block groups 
  12. 8192 blocks per group, 8192 fragments per group 
  13. 2048 inodes per group 
  14. Superblock backups stored on blocks:  
  15.     8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409 
  16.  
  17. Writing inode tables: done                             
  18. Creating journal (8192 blocks): done 
  19. Writing superblocks and filesystem accounting information: done 
  20.  
  21. This filesystem will be automatically checked every 23 mounts or 
  22. 180 days, whichever comes first.  Use tune2fs -c or -i to override. 

將sdb1掛載到others目錄上

  1. [root@hooper ~]# mkdir /others 
  2. [root@hooper ~]# mount /dev/sdb1 /others 
  3. [root@hooper ~]# mount 
  4. /dev/sda3 on / type ext3 (rw) 
  5. proc on /proc type proc (rw) 
  6. sysfs on /sys type sysfs (rw) 
  7. devpts on /dev/pts type devpts (rw,gid=5,mode=620
  8. /dev/sda1 on /boot type ext3 (rw) 
  9. tmpfs on /dev/shm type tmpfs (rw) 
  10. none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) 
  11. sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) 
  12. nfsd on /proc/fs/nfsd type nfsd (rw) 
  13. /dev/sdb1 on /others type ext3 (rw) 
  14. [root@hooper ~]# cd /others 
  15. [root@hooper others]# ll 
  16. total 12 
  17. drwx------ 2 root root 12288 Dec  7 15:38 lost+found 

修改fstab文件

  1. [root@hooper others]# vi /etc/fstab 
  2. LABEL=/                 /                       ext3    defaults        1 1 
  3. LABEL=/boot             /boot                   ext3    defaults        1 2 
  4. tmpfs                   /dev/shm                tmpfs   defaults        0 0 
  5. devpts                  /dev/pts                devpts  gid=5,mode=620  0 0 
  6. sysfs                   /sys                    sysfs   defaults        0 0 
  7. proc                    /proc                   proc    defaults        0 0 
  8. LABEL=SWAP-sda2         swap                    swap    defaults        0 0 
  9. LABEL=/other            /others                 ext3    defaults        1 2 

    這裏用到的是LABE而不是設備名(/dev/sdb1),但是這個把卷標寫錯,應該是other,前面沒有 /,並且沒有運行mount -a 命令來驗證配置是否正確

重啓系統

  1. [root@hooper others]# init 6 

2. 修復fstab文件

重啓後遇到問題,如下圖:

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

2.1 故障解決過程

2.1.1 進入運行級別1

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

試圖修改/etc/fstab文件,發現此文件爲只讀

重新掛載(mount),並修改文件

再次修改/etc/fstab文件,並保存

修復完成,重啓系統

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

3. 問題總結

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

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