文件系统挂载

栏目: 服务器 · Linux · 发布时间: 6年前

内容简介:文件系统挂载

文件系统挂载

文件系统管理:

将额外文件系统与根文件系统某现存的目录建立起关联关系,进而使得此目录做为其它文件访问入口的行为称之为挂载;

解除此关联关系的过程称之为卸载;

把设备关联挂载点:Mount Point

mount

卸载时:可使用设备,也可以使用挂载点

umount

注意:挂载点下原有文件在挂载完成后会被临时隐藏;

挂载方法: mount DEVICE MOUNT_POINT

mount :通过查看 /etc/mtab 文件显示当前系统已挂载的所有设备

mount [-fnrsvw] [-t vfstype] [-o options] device dir

device :指明要挂载的设备;

(1) 设备文件:例如 /dev/sda5

(2) 卷标: -L ‘LABEL’, 例如 -L ‘MYDATA’

(3) UUID, -U ‘UUID’ :例如 -U ‘0c50523c-43f1-45e7-85c0-a126711d406e’

(4) 伪文件系统名称: proc, sysfs, devtmpfs, configfs

dir :挂载点

事先存在;建议使用空目录;

进程正在使用中的设备无法被卸载;

常用命令选项:

-t vsftype :指定要挂载的设备上的文件系统类型;

-r: readonly ,只读挂载;

-w: read and write, 读写挂载;

-n: 不更新 /etc/mtab

-a :自动挂载所有支持自动挂载的设备; ( 定义在了 /etc/fstab 文件中,且挂载选项中有“自动挂载”功能 )

-L ‘LABEL’: 以卷标指定挂载设备;

-U ‘UUID’: UUID 指定要挂载的设备;

-B, –bind: 绑定目录到另一个目录上;

注意:查看内核追踪到的已挂载的所有设备:cat /proc/mounts

-o options:(挂载文件系统的选项)

async :异步模式;

sync :同步模式;

atime/noatime :包含目录和文件;

diratime/nodiratime :目录的访问时间戳

auto/noauto :是否支持自动挂载

exec/noexec :是否支持将文件系统上应用程序运行为进程

dev/nodev :是否支持在此文件系统上使用设备文件;

suid/nosuid

remount :重新挂载

ro

rw:

user/nouser :是否允许普通用户挂载此设备

acl :启用此文件系统上的 acl 功能

注意:上述选项可多个同时使用,彼此使用逗号分隔;

默认挂载选项: defaults

rw, suid, dev, exec, auto, nouser, and async

卸载命令:

# umount DEVICE

# umount MOUNT_POINT

查看正在访问指定文件系统的进程:

# fuser -v MOUNT_POINT

终止所有在正访问指定的文件系统的进程:

# fuser -km MOUNT_POINT

挂载交换分区:

启用: swapon

swapon [OPTION]… [DEVICE]

-a :激活所有的交换分区;

-p PRIORITY :指定优先级;

禁用: swapoff [OPTION]… [DEVICE]

内存空间使用状态:

free [OPTION]

-m: MB 为单位

-g: GB 为单位

文件系统空间占用等信息的查看工具:

df:

-h: human-readable

-i inodes instead of blocks

-P: Posix 兼容的格式输出 ;

查看某目录总体空间占用状态:

du

du [OPTION]… DIR

-h: human-readable

-s: summary

命令总结:mount, umount, free, df, du, swapon, swapoff, fuser

文件挂载的配置文件:/etc/fstab

每行定义一个要挂载的文件系统;

要挂载的设备或伪文件系统 挂载点 文件系统类型   挂载选项 转储频率   自检次序

要挂载的设备或伪文件系统:

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

挂载选项:

defaults

转储频率:

0 :不做备份

1 :每天转储

2 :每隔一天转储

自检次序:

0 :不自检

1 :首先自检;一般只有 rootfs 才用 1

  文件系统上的其它概念:

Inode: Index Node, 索引节点

地址指针:

直接指针:

间接指针:

三级指针:

inode bitmap:对位标识每个inode空闲与否的状态信息;

链接文件:

硬链接:

不能够对目录进行;

不能跨分区进行;

指向同一个 inode 的多个不同路径;创建文件的硬链接即为为 inode 创建新的引用路径,因此会增加其引用计数;

符号链接:

可以对目录进行;

可以跨分区;

指向的是另一个文件的路径;其大小为指向的路径字符串的长度;不增加或减少目标文件 inode 的引用计数;

ln [-sv] SRC DEST

-s symbolic link

-v: verbose

例一:给文件设置硬链接

[root@localhost ~]# ln fstab fstab.hl

例二:创建软链接

[root@localhost ~]# ln -s fstab fstab.sl
[root@localhost ~]# ll -i
总用量 20
100663405 -rw-r--r--. 1 root root    0 5月   5 12:05 123
100663409 -rw-r--r--. 1 root root    0 5月   5 12:10 123.txt
100663408 -rw-r--r--. 1 root root    0 5月   5 11:44 201911111111.11
100663407 drwxr-xr-x. 2 root root   17 5月   5 14:42 34
100663363 -rw-------. 1 root root 1261 5月   5 06:31 anaconda-ks.cfg
 33611768 drwxr-xr-x. 2 root root    6 5月   5 18:55 ddd
100699875 -rw-r--r--. 2 root root  617 5月  16 08:58 fstab
100699875 -rw-r--r--. 2 root root  617 5月  16 08:58 fstab.hl
100699893 lrwxrwxrwx. 1 root root    5 5月  16 09:05 fstab.sl -> fstab
100699876 -rw-r--r--. 1 root root   48 5月   6 13:01 grep.txt
100699877 -rw-r--r--. 1 root root  138 5月   6 16:57 ls.txt
      705 drwxr-xr-x. 2 root root    6 5月   5 12:10 rrr
[root@localhost ~]# rm fstab
rm:是否删除普通文件 "fstab"?y
[root@localhost ~]# ll
总用量 16
-rw-r--r--. 1 root root    0 5月   5 12:05 123
-rw-r--r--. 1 root root    0 5月   5 12:10 123.txt
-rw-r--r--. 1 root root    0 5月   5 11:44 201911111111.11
drwxr-xr-x. 2 root root   17 5月   5 14:42 34
-rw-------. 1 root root 1261 5月   5 06:31 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 5月   5 18:55 ddd
-rw-r--r--. 1 root root  617 5月  16 08:58 fstab.hl
lrwxrwxrwx. 1 root root    5 5月  16 09:05 fstab.sl -> fstab
-rw-r--r--. 1 root root   48 5月   6 13:01 grep.txt
-rw-r--r--. 1 root root  138 5月   6 16:57 ls.txt
drwxr-xr-x. 2 root root    6 5月   5 12:10 rrr

文件管理操作对文件的影响:

文件删除:rm

文件复制:cp

文件移动:mv

例一:挂载文件,创建新的目录

[root@localhost ~]# mkdir /mydata
[root@localhost ~]# mount /dev/sdb /mydata/
[root@localhost ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=488984k,nr_inodes=122246,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/cl-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=35,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/mapper/cl-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=99996k,mode=700)
/dev/sdb on /mydata type ext2 (rw,relatime,seclabel)

例二:指定要挂载的设备上的文件系统类型

[root@localhost ~]# mount -t ext2 /dev/sdb /mydata
[root@localhost ~]# mount

例三:卸载站点

[root@localhost ~]# umount /dev/sdb
[root@localhost ~]# mout
-bash: mout: 未找到命令
[root@localhost ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=488984k,nr_inodes=122246,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=sr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,necls)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/cl-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=35,pgrp=1,timeout=300,minproto=5axproto=5,direct)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/mapper/cl-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=99996k,mode=700)

文件挂载的配置文件: /etc/fstab

每行定义一个要挂载的文件系统;

要挂载的设备或伪文件系统 挂载点 文件系统类型   挂载选项 转储频率   自检次序

要挂载的设备或伪文件系统:

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

  挂载选项:

defaults

转储频率:

0 :不做备份

1 :每天转储

2 :每隔一天转储

自检次序:

0 :不自检

1 :首先自检;一般只有 rootfs 才用

例一:挂载文件,自启动 …

[root@localhost ~]# vim /etc/fstab
/dev/sdb               /mydata                 ext4    defaults        0 0
[root@localhost ~]# mount -a
[root@localhost ~]# mount
/dev/mapper/cl-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=26,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/mapper/cl-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=99996k,mode=700)
/dev/sdb on /mydata type ext4 (rw,relatime,secla

bash 脚本编程之用户交互:

read [option]… [name …]

-p ‘PROMPT’

-t TIMEOUT

bash -n /path/to/some_script

检测脚本中的语法错误

例一:检测命令语法

[root@localhost bin]# vim read.sh
[root@localhost bin]# bash -n read.sh

bash -x /path/to/some_script

调试执行

例一:命令执行过程

[root@localhost bin]# bash -x read.sh
+ read -p 'Enter a disk special file:' diskfile
Enter a disk special file: /dev/sda
+ '[' -z /dev/sda ']'
+ fdisk -l
+ grep '^Disk /dev/sda'
+ echo 'Wrong disk special file.'
Wrong disk special file.
+ exit 2

以上所述就是小编给大家介绍的《文件系统挂载》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

疯传:让你的产品、思想、行为像病毒一样入侵(全新修订版)

疯传:让你的产品、思想、行为像病毒一样入侵(全新修订版)

[美] 乔纳•伯杰(Jonah Berger) / 乔迪、王晋 / 电子工业出版社 / 2016-6 / 68.00

是什么让事物变得流行? 从买轿车、买衣服、吃三明治,到给孩子取名字,你是否知道为什么某些产品会大卖,某些故事被人们口口相传,某些电子邮件更易被转发,或者某些视频链接被疯狂地点击,某些谣言更具传播力,某些思想和行为像病毒一样入侵你的大脑……这本书将为你揭示这些口口相传和社会传播背后的科学秘密,并且告诉你如何将产品、思想、行为设计成具有感染力和传播力的内容。 无论你是大公司的管理者,还是努......一起来看看 《疯传:让你的产品、思想、行为像病毒一样入侵(全新修订版)》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具