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