linux(ubuntu)开机自动挂载磁盘

  1. 1. 概述
  2. 2. fstab文件
    1. 2.1 挂载限制
    2. 2.2 file system
    3. 2.3 mount point
    4. 2.4 type
    5. 2.5 options
    6. 2.6 dump
    7. 2.7 pass

linux开机自动挂载磁盘

1. 概述

磁盘使用mount挂载时,每次开机都需要手动挂载。如果修改/etc/fstab文件,则开机会自动挂载磁盘,不需要手动进行挂载。

2. fstab文件

<file system> <mount point> <type> <options> <dump> <pass>
/dev/mapper/vgubuntu-root / ext4 errors=remount-ro 0 0
/dev/mapper/vgubuntu-swap_1 none swap sw 0 0
UUID=1BB8-DEC1 /boot/efi vfat defaults 0 1

2.1 挂载限制

    1. 根目录是必须挂载的,而且一定要先于其他mount point被挂载。因为mount是所有目录的跟目录,其他木有都是由根目录 /衍生出来的。
    1. 挂载点必须是已经存在的目录。
    1. 挂载点的指定可以任意,但必须遵守必要的系统目录架构原则
    1. 所有挂载点在同一时间只能被挂载一次
    1. 所有分区在同一时间只能挂在一次
    1. 若进行卸载,必须将工作目录退出挂载点(及其子目录),也就先umount之后才可以被卸载

2.2 file system

    1. 设备的文件
    1. 设备的Label
    1. 设备的UUID
sudo blkid

pic

2.3 mount point

设备的挂载点

2.4 type

磁盘文件系统的格式,包括ext2、ext3、reiserfs、nfs、vfat等

2.5 options

options 说明 description
async 设置是否为同步方式运行,默认为async All I/O to the filesystem should be done asynchronously. (See also the sync option.)
atime Do not use noatime feature, then the inode access time is controlled by kernel defaults. See also the description for strictatime and relatime mount options.
noatime Do not update inode access times on this filesystem (e.g, for faster access on the news spool to speed up news servers).
auto 当下载mount -a 的命令时,此文件系统是否被主动挂载。默认为auto Can be mounted with the -a option.
noauto 当下载mount -a 的命令时,此文件系统是否被主动挂载。默认为auto Can only be mounted explicitly (i.e., the -a option will not cause the filesystem to be mounted).
defaults 具有rw,suid,dev,exec,auto,nouser,async等默认参数的设置 Use default options: rw, suid, dev, exec, auto, nouser, async, and relatime.
dev Interpret character or block special devices on the filesystem.
nodev Do not interpret character or block special devices on the file system.
diratime Update directory inode access times on this filesystem. This is the default.
nodiratime Do not update directory inode access times on this filesystem.
dirsync All directory updates within the filesystem should be done synchronously. This affects the following system calls: creat, link, unlink, symlink, mkdir, rmdir, mknod and rename.
exec 限制此文件系统内是否能够进行”执行”的操作 Permit execution of binaries.
noexec 限制此文件系统内是否能够进行”执行”的操作 Do not allow direct execution of any binaries on the mounted filesystem. (Until recently it was possible to run binaries anyway using a command like /lib/ld*.so /mnt/binary. This trick fails since Linux 2.4.25 / 2.6.0.)
group Allow an ordinary (i.e., non-root) user to mount the filesystem if one of his groups matches the group of the device. This option implies the options nosuid and nodev (unless overridden by subsequent options, as in the option line group,dev,suid).
iversion Every time the inode is modified, the i_version field will be incremented.
noiversion Do not increment the i_version inode field.
mand Allow mandatory locks on this filesystem. See fcntl(2).
nomand Do not allow mandatory locks on this filesystem.
_netdev The filesystem resides on a device that requires network access (used to prevent the system from attempting to mount these filesystems until the network has been enabled on the system).
nofail Do not report errors for this device if it does not exist.
relatime Update inode access times relative to modify or change time. Access time is only updated if the previous access time was earlier than the current modify or change time. (Similar to noatime, but doesn’t break mutt or other applications that need to know if a file has been read since the last time it was modified.)
norelatime Do not use relatime feature. See also the strictatime mount option.
strictatime Allows to explicitly requesting full atime updates. This makes it possible for kernel to defaults to relatime or noatime but still allow userspace to override it. For more details about the default system mount options see /proc/mounts.
nostrictatime Use the kernel’s default behaviour for inode access time updates.
suid 是否允许SUID的存在 Allow set-user-identifier or set-group-identifier bits to take effect.
nosuid 是否允许SUID的存在 Do not allow set-user-identifier or set-group-identifier bits to take effect. (This seems safe, but is in fact rather unsafe if you have suidperl(1) installed.)
owner Allow an ordinary (i.e., non-root) user to mount the filesystem if he is the owner of the device. This option implies the options nosuid and nodev (unless overridden by subsequent options, as in the option line owner,dev,suid).
ro 是否以以只读或者读写模式挂载 Mount the filesystem read-only.
_rnetdev Like _netdev, except “fsck -a” checks this filesystem during rc.sysinit.
rw 是否以以只读或者读写模式挂载 Mount the filesystem read-write.
sync 设置是否为同步方式运行,默认为async All I/O to the filesystem should be done synchronously. In case of media with limited number of write cycles (e.g. some flash drives) “sync” may cause life-cycle shortening.
user Allow an ordinary user to mount the filesystem. The name of the mounting user is written to mtab so that he can unmount the filesystem again. This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid).
nouser Forbid an ordinary (i.e., non-root) user to mount the filesystem. This is the default.
users Allow every user to mount and unmount the filesystem. This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line users,exec,dev,suid).

2.6 dump

能否被dump备份命令作用:dump是一个用来作为备份的命令。通常这个参数的值为0或者1

dump 说明
0 代表不要做dump备份
1 代表要每天进行dump的操作
2 代表不定日期的进行dump操作

2.7 pass

是否检验扇区:开机的过程中,系统默认会以fsck检验我们系统是否为完整(clean)。

pass 说明
0 不要检验
1 最早检验(一般根目录会选择)
2 1级别检验完成之后进行检验

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 wind.kaisa@gmail.com

文章标题:linux(ubuntu)开机自动挂载磁盘

本文作者:kaisawind

发布时间:2019-12-12, 16:31:00

最后更新:2020-11-18, 15:55:44

原始链接:https://kaisawind.gitee.io/2019/12/12/2019-12-13-linux/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

喜欢就点赞,疼爱就打赏