文件系统挂载

文件系统挂载

文件系统管理:

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

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

 把设备关联挂载点: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

-iinodes 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

-ssymbolic 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
 


原创文章,作者:kang,如若转载,请注明出处:http://www.178linux.com/75922

(0)
kangkang
上一篇 2015-12-15
下一篇 2015-12-16

相关推荐

  • 简单路由实验

    今天学习了路由相关的基础知识,为了加深印象,做了如下的一个实验。根据下面的网络拓扑图分别配置两台PC和路由,以实现PC1和PC2能够互相ping通。实验环境为VM虚拟机 在实验开始前,我们需要在路由添加两块网卡,PC机添加一块网卡,此实验网卡的链接方式是桥接,一共需要4台虚拟机,两台做PC机,两台做路由器 1、R2路由器的配置 [root@linuxpao&…

    Linux干货 2016-09-05
  • bash脚本循环语句用法练习

    bash脚本循环语句用法练习 1、使用循环语句写一个脚本,实现打印出来国际象棋的棋盘 #方法1:使用until循环语句实现 [root@liang7 bin]# cat chess-until.sh  #!/bin/bash #Author:liang #Version:1.0 #Description:Print&n…

    Linux干货 2016-08-24
  • Centos7下的systemd管理

    systemd简介 Systemd是由红帽公司的一名叫做Lennart Poettering的员工开发,systemd是Linux系统中最新的初始化系统(init),它主要的设计目的是克服Sys V 固有的缺点,提高系统的启动速度,systemd和upstart是竞争对手,ubantu上使用的是upstart的启动方式,centos7上使用systemd替换…

    Linux干货 2016-09-23
  • Linux系统结构 详解

    Linux系统一般有4个主要部分: 内核、shell、文件系统和应用程序。内核、shell和文件系统一起形成了基本的操作系统结构,它们使得用户可以运行程序、管理文件并使用系统。部分层次结构如图1-1所示。  1. linux内核         内核是操作系统的核心,具有很多最基本功能,它负责管理系…

    Linux干货 2015-04-13
  • KeepAlived的配置及使用!

    此篇博客主要是和大家共同了解一下keepalived的功能及基础配置,以便于牢固掌握,此篇博客共分为三个部分;                ⊙ 简述keepalived的主要功能及安装环境;           &nb…

    2017-05-13
  • Linux运维之路-Linux基础学习三

    先学会用户组和文件的属性,才知道怎么去管理

    Linux干货 2017-11-26