fstab損壞修復過程總結

1. 建立錯誤環境node

1.1 操做系統說明ide

操做系統:CentOS 5.8oop

硬盤分區狀況:this

  
  
  
  
  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文件:spa

  
  
  
  
  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
orm

  
  
  
  
  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. 

建立文件系統xml

  
  
  
  
  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目錄上blog

  
  
  
  
  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文件ip

  
  
  
  
  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配置文件

相關文章
相關標籤/搜索