fstab -- static information about the filesyatem
设置文件系统挂载信息的文件,实现开机自动挂载磁盘信息。
# /etc/fstab # Created by anaconda on Wed Jul 20 19:58:06 2016 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=d3824e72-d534-4574-b097-400c794c0650 / ext4 defaults 1 1 UUID=e4fdfa26-62ea-4ccf-bcc9-75372563100a /boot ext4 defaults 1 2 UUID=6c627cf1-55ac-47d2-a4d0-4f8c8ad555b4 swap swap defaults 0 0 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 #/opt/sdb1 /mnt ext4 loop,noatime,noexec 0 0
第一列:挂载的设备,可以是设备名或者UUID或者是磁盘标签。
第二列:挂载点。
第三列:FS类型。
第四列:参数。
第五列:备份。
第六列:检查。fsck -A 检查磁盘,卸载的状态检查。(不要用它来检查好磁盘)
模拟一个文件系统来挂载试试:
模拟一个文件系统:
[root@apple pythonex]# dd if=/dev/zero of=/opt/sdb2 bs=4096 count=100 100+0 records in 100+0 records out 409600 bytes (410 kB) copied, 0.00281153 s, 146 MB/s
格式化:
[root@apple pythonex]# mkfs.ext4 /opt/sdb2 mke2fs 1.41.12 (17-May-2010) /opt/sdb2 is not a block special device. Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 56 inodes, 400 blocks 20 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=524288 1 block group 8192 blocks per group, 8192 fragments per group 56 inodes per group Writing inode tables: done Filesystem too small for a journal Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 39 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
查看:
[root@apple pythonex]# ll -l /opt/sdb2 -rw-r--r--. 1 root root 409600 Aug 17 07:08 /opt/sdb2
手动挂载:
[root@apple pythonex]# mount -t ext4 -o loop,noatime,noexec /opt/sdb2 /mnt [root@apple pythonex]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 20G 1.6G 17G 9% / tmpfs 250M 0 250M 0% /dev/shm /dev/sda1 194M 28M 157M 15% /boot /opt/sdb1 388K 15K 353K 5% /mnt /opt/sdb2 388K 15K 353K 5% /mnt
开机自动挂载:
[root@apple pythonex]# umount /opt/sdb2 [root@apple pythonex]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 20G 1.6G 17G 9% / tmpfs 250M 0 250M 0% /dev/shm /dev/sda1 194M 28M 157M 15% /boot /opt/sdb1 388K 15K 353K 5% /mnt [root@apple pythonex]# vi /etc/fstab # # /etc/fstab # Created by anaconda on Wed Jul 20 19:58:06 2016 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=d3824e72-d534-4574-b097-400c794c0650 / ext4 defaults 1 1 UUID=e4fdfa26-62ea-4ccf-bcc9-75372563100a /boot ext4 defaults 1 2 UUID=6c627cf1-55ac-47d2-a4d0-4f8c8ad555b4 swap swap defaults 0 0 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 /opt/sdb1 /mnt ext4 loop,noatime,noexec 0 0 /opt/sdb2 /mnt ext4 loop,noatime,noexec 0 0 ~ ~ "/etc/fstab" 17L, 969C written [root@apple pythonex]# mount -a [root@apple pythonex]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 20G 1.6G 17G 9% / tmpfs 250M 0 250M 0% /dev/shm /dev/sda1 194M 28M 157M 15% /boot /opt/sdb1 388K 15K 353K 5% /mnt /opt/sdb2 388K 15K 353K 5% /mnt
重启,检查是否能开机自动挂载:
[root@apple pythonex]# reboot Broadcast message from root@apple (/dev/pts/0) at 7:18 ... The system is going down for reboot NOW! [root@apple ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 20G 1.6G 17G 9% / tmpfs 250M 0 250M 0% /dev/shm /dev/sda1 194M 28M 157M 15% /boot /opt/sdb1 388K 15K 353K 5% /mnt /opt/sdb2 388K 15K 353K 5% /mnt
解决/etc/fstab 配置错误或损坏,导致服务器无法开机。
这里人为改动UUID,模拟fstab损坏的情况:
[root@apple ~]# vi /etc/fstab
# /etc/fstab
# Created by anaconda on Wed Jul 20 19:58:06 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
**UUID=d3824e72-d534-4574-b097-400c794c0650 / ext4 defaults 1 1
UUID=e4fdfa26-62ea-4ccf-bcc9-75372563100a /boot ext4 defaults 1 2
UUID=6c627cf1-55ac-47d2-a4d0-4f8c8ad555b4 swap swap defaults 0 0
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
/opt/sdb1 /mnt ext4 loop,noatime,noexec 0 0
/opt/sdb2 /mnt ext4 loop,noatime,noexec 0 0
~
~
"/etc/fstab" 16L, 969C written
[root@apple ~]# reboot
Broadcast message from root@apple
(/dev/pts/0) at 7:24 ...
The system is going down for reboot NOW!
重启后截图如下:
输入密码,执行 mount -o remount,rw / 获取权限,修改fstab 后reboot重启ok。
[root@apple ~]# mount -o remount,rw / [root@apple ~]# vi /etc/fstab [root@apple ~]# reboot