Linux 磁盘 开机自动挂载 -- 基于 fstab 文件

个人博客首页(点击查看详情) -- https://blog.51cto.com/11495268
个人公众号(点击链接 扫码关注哦)-- https://blog.51cto.com/11495268/2401194
    

1、简介

    开机 自动 挂载 很有用,特别是 很多 开启自启 服务 依赖于 某些 数据文件;本文 描述 编辑 /etc/fstab 实现 开机自启
    

2、/etc/fstab

# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda3 during installation
UUID=4dfee257-e6a1-41fb-b16a-1d93a7ebe0be /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=9008bfed-4aa5-44d9-9a2d-58d4ffd0fcaf /boot           ext4    defaults        0       2
# swap was on /dev/sda5 during installation
UUID=9255b841-8bde-4878-afe4-ad7e118f132b none            swap    sw              0       0

UUID=c87a3ad3-d319-4621-bf08-14013281bbe7 /mnt/learn_linux ext4 defaults 0 0

    

3、内容详解

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# 要挂载的设备或伪文件系统  挂载点  文件系统类型  挂载选项 转储频率 自检次序

    

3.1 设备或伪文件系统

    设备文件、LABEL(LABEL="")、UUID(UUID="")
    伪文件系统名称(proc, sysfs)
    

3.2 挂载点

    指定的文件夹

3.3 挂载选项

    defaults

3.4 转储频率

    使用dump命令自动备份分区数据的频率
        0:不做备份
        1:每天转储
        2:每隔一天转储
    

3.5 自检次序

    0:不自检
    1:首先自检
    

4、扩展(/etc/fstab和/etc/mtab的区别)

4.1 /etc/fstab文件的作用

    记录了计算机上硬盘分区的相关信息,启动 Linux 的时候,检查分区的 fsck 命令,和挂载分区的 mount 命令,都需要 fstab 中的信息,来正确的检查和挂载硬盘
    

4.2 /etc/mtab文件的作用

    每当 mount 挂载分区、umount 卸载分区,都会动态更新 mtab,mtab 总是保持着当前系统中已挂载的分区信息

猜你喜欢

转载自blog.51cto.com/11495268/2402305