List of articles


Hello everyone , I am Gao Shenghan , This article is about Linux Operation and maintenance - Step by step - The second part of the basic part 48 Original articles .


Let's talk today mount Use

1. mount Explanation of orders

mount

1) effect : The command to mount the file system
2) The basic format is :

Mount options -t File system type -o Options 1, Options 2…
Example :
mount -t ext4 -o acl /dev/sdb1 /mnt/
It doesn't matter if you can't understand it for the time being , We'll talk about it later .

3) Common file system types are :
  • ext4
  • NFS
  • CIFS
  • XFS
  • ext2
  • ext3
    wait

at present centos7 The system of is XFS

4) Check which operating systems are supported by the current system

About the above -t Parameters , We don't write a lot of time , however -t Parameter specifies the file system type, which is very important . We can check filesystems The configuration file , To see which file systems are supported by the current system

 Insert picture description here

The second parameter in the above example -o

5) Details of Mount options

-o The mount options are specified later , There are many mount options

Options meaning
rw Reading and writing
ro read-only
suid Support suid
dev Support device files
nodev Device files are not supported
noexec Binary execution is not allowed
exec Allow binary execution
auto mount -a Power on auto mount
noauto mount -a It doesn't mount automatically when the machine is turned on
async Asynchronous write
sync Synchronous in
noatime Do not update access time atime
usrquota Support user level disk quota function
grpquota Support group level disk quota function
acl Support acl function ( Access control list )
remount Remount online

So in this example mount -t ext4 -o acl /dev/sdb1 /mnt/, -o hinder acl It supports access control lists .

Come here , I believe you can understand this example command , But understanding is just the beginning , Next , Let's talk about it in detail mount The past and this life .

6) And mount Related documents
  • /etc/fstab ( Set up auto mount files )
  • /etc/mtab
  • /proc/mounts
7) And mount Related parameters
Parameters meaning
-r read-only
-w Reading and writing Default
-F This order usually goes with -a Use it together , It will be for each mount The action of generating a journey is responsible for the execution of
-v Show more information , Usually and -f Used to get rid of mistakes .
-L Put the hard disk partition with a specific label on it .
-U Divide the file into Our file system is down .-L and -U Must be in /proc/partition This kind of file is meaningful only when it exists .
-t Specifies the type of the file system , It is usually not necessary to specify .mount The correct type will be selected automatically .
-a take /etc/fstab All file systems defined in , This operation can realize the requirement of auto mount when starting up . When writing /etc/fstab After the document , The mount operation can also specify only the mount source or mount point

2. mount Use examples

1. Allow executable and non executable permissions

exec/noexec

[root@gaosh-1 ~]# ll /dev/sdb*    Now there's a piece of sdb1 Disk brw-rw----. 1 root disk 8, 16 6 month   25 17:01 /dev/sdb
brw-rw----. 1 root disk 8, 17 6 month   25 17:31 /dev/sdb1[root@gaosh-1 ~]#

Create two directories , A directory for mounting executable permissions , A directory for mounting non executable permissions
 Insert picture description here

Mount and test :

[root@gaosh-1 ~]# mount /dev/sdb1 /mnt/gexec      Mount to executable binary Directory gexec[root@gaosh-1 ~]#  cp -rf /bin/date /mnt/gexec   # Copy a binary to test [root@gaosh-1 ~]# /mnt/gexec/date                # Execute command discovery can be executed successfully 2020 year  06 month  25 Japan   Thursday  21:13:51 CST[root@gaosh-1 ~]#

The above example proves that , After mounting, you can execute binary Directory , But there's no proof that if you add parameters noexec, You can't execute binary , Let's try

[root@gaosh-1 ~]# df -h  Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        20G  3.8G   15G  21% /
tmpfs           1.8G  228K  1.8G   1% /dev/shm
/dev/sda1       190M   40M  141M  22% /boot
/dev/sdb1       4.9G   11M  4.6G   1% /mnt/gexec[root@gaosh-1 ~]# umount /mnt/gexec/    First unload it and mount it to another directory  nexec[root@gaosh-1 ~]#

Next, we use a mount method that does not support executable permissions ,noexec, And test the

[root@gaosh-1 ~]# mount -o noexec /dev/sdb1 /mnt/nexec/    # Use here -o noexec Parameters 

test :
 Insert picture description here
You can see , It's also copying past binaries , But when executing, it prompts that the permission is not enough .

2.sync && async Synchronous write and asynchronous write
[root@gaosh-1 ~]# mkdir /mnt/test1[root@gaosh-1 ~]# mount /dev/sdb1 /mnt/test1/[root@gaosh-1 ~]# mount/dev/sdb1 on /mnt/test1 type ext4 (rw)

Without parameters , The default is asynchronous write , You can see ,rw jurisdiction

[root@gaosh-1 test1]# time cp -rf /etc/ /mnt/test1    # Look at the write time real    0m0.112s
user    0m0.000s
sys     0m0.111s

If you add -o sync Let's take a look :

[root@gaosh-1 ~]# umount /mnt/test1/   # Unload test1[root@gaosh-1 ~]# mkdir /mnt/test2    #  establish test2 Catalog [root@gaosh-1 ~]# mount -o sync /dev/sdb1 /mnt/test2   Use sync Synchronous write mount /dev/sdb1 on /mnt/test2 type ext4 (rw,sync)   # You can see rw, There are more synchronous writes in the back 

[root@gaosh-1 ~]# time cp -rf /etc/ /mnt/test2   Look at the write time real    0m5.267s
user    0m0.004s
sys     0m1.322s

It's obvious that the synchronization time is longer : Because when you synchronize client It takes time to get the response . But not in all cases is asynchrony faster than synchronization .

So here Shenghan means : The speed of time is only valid in this experiment .

3.acl Use

Set up auto mount
vim /etc/fstab
 Insert picture description here
Check it out. , There is no mount at present :
 Insert picture description here

perform mount -a Automatically mount  Insert picture description here

[root@gaosh-1 ~]# mount/dev/sdb1 on /mnt/test1 type ext4 (rw,acl)

4. Use UUID Mount

see uuid

[root@gaosh-1 ~]# blkid /dev/sdb1/dev/sdb1: UUID="37c948a1-d0b9-49ff-923c-f3eac30eb0f3" TYPE="ext4"

vim /etc/fstab

 Insert picture description here
Save and exit : And then use mount -a

summary

although mount There are many parameters for , But not every parameter needs to be mastered , Learn how to use /etc/fstab, Set up auto mount .

I am Gao Shenghan , A person who never forgets his original intention in the teaching and training industry , Welcome to my collection , See you next time !