Mounting is the process of linking the device file name with the established empty directory, which is called mounting.
1. Introduction to mount command
(1) mount command description
All storage devices in Linux system must be mounted to use, including hard disk.
- Command name: mount
- Command path: / bin/mount
- Execution Authority: all users
Use example of mount command:
# Query my device in the system, -l will display the volume label name [root@localhost ~]# mount [-l]
(2) mount command format
[root@localhost ~]# mount [-t file system] [- L volume label] [- o special options] device file name mount point # Note: in Linux system, the meaning of \ means line feed, which means that the upper two lines are one line of content. Options: -t File system: add a file system type to specify the type of mount. You can ext3,ext4,iso9660 And other file systems. It's okay not to write, Linux System default disc U All discs can be recognized automatically). -L Volume label name: mount the partition with the specified volume label instead of the file name of the installation device. (I can't use it now, so I don't pay attention.) -o Special options: you can specify additional options for mounting, such as read-write permission, synchronous asynchronous, etc. if not specified, the default value will take effect.
give an example:
[root@localhost ~]# mount -t iso9660 /dev/sr0 /mnt/cdrom/
2. mount command example
Directly enter the mount command to query the mounted devices that already exist in the system.
[root@localhost ~]# mount /dev/sda3 on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) # Only # /Dev / sda3 on / type ext4 (RW) - > / dev / sda3 is mounted to the root directory. The file system is ext4 and the permissions are read and write. # /dev/sda1 on /boot type ext4 (rw) is useful. Others are interference items # Also note that the swap partition does not require a mount point. It is a partition directly accessed by the system kernel, and cannot be viewed by the mount command.
3. mount -a command description
# Mount automatically according to the contents of the configuration file / etc/fstab [root@localhost ~]# mount -a
-A of a means auto.
The hard disk of Linux system is automatically mounted after startup. However, mobile storage devices such as optical discs and U SB flash disks are not recommended to be mounted automatically after startup.
If mobile storage devices such as optical discs and USB flash drives are set to automatically mount when starting up, once you forget to put the optical disc or USB flash drive, the system will unconditionally look for this partition. If you can't find it, the system will start up incorrectly. This error is not difficult to repair, but it must be operated on this machine.
The Linux system is automatically mounted according to the / etc/fstab file. This file is a very fragile file. Once the file is written incorrectly, the system will start to report an error.
Execute the command to view the / etc / fstab file:[ root@localhost ~]# vim /etc/fstab
As shown in the figure below:
The mount -a command can be regarded as scanning the / etc/fstab file to see if the contents are wrong. If it is wrong, an error will be reported.
In Linux systems after Red Hat 6, the fault tolerance of / etc/fstab file is significantly enhanced. Before Red Hat 5, it was impossible to spell a letter incorrectly. After Red Hat 6, except for the information of key positions, other errors will not be reported. Therefore, sometimes scanning with mount -a command does not necessarily lead to errors. Therefore, the results of mount -a command cannot be blindly trusted. Just remember this. (it will be said later how to repair the file if there are errors)
4. - o description of special options
Let's first look at the / etc/fstab file mentioned earlier, the automatic mount configuration file of Linux system.
The red box in the figure above shows the default permissions for partition mounting. The following describes the permissions for mounting in detail:
- Atime / noaatime: update access time or do not update access time. Whether to update the access time of the file when accessing the partition file. The default is update.
- async/sync: asynchronous / synchronous, asynchronous by default.
- auto/noauto: Auto / manual. Whether the contents of the / etc/fstab file will be mounted automatically when the mount -a command is executed. The default is automatic.
- exec/noexec: execute or not. Set whether executable files are allowed to execute in the file system. The default is exec.
- rw/ro: read-write / read-only. Whether the file system has read-write permission when mounted. The default is rw.
- suid/nosuid: with or without SUID permission. Set whether the file system has SUID and SGID permission. The default is SUID.
- user/nouser: allows or does not allow ordinary users to mount. Set whether the file system allows ordinary users to mount. It is not allowed by default. Only root can mount partitions.
- defaults: defines the default value, which is equivalent to the seven options rw, suid, dev, exec, auto, nouser and async.
- Remount: remount the mounted file system. It is generally used to specify special permissions for modification.
- usrquota: write represents that the file system supports user disk quota. It is not supported by default.
- grpquota: write represents the disk quota of the file system support group. It is not supported by default.
- The defaults permission represents the top 7 permissions, one of which is the default value. This default value generally does not need to be modified, and the default option is very good.
- For example, if you select the exec/noexec option, the files in the entire partition cannot be executed. If the root directory is defined as noexec, the entire system cannot be started, even if you want to modify it, because the mount command cannot be executed.
5. exec/noexec option description
See the following example:
# 1. Check the mounted file system in the system. Note that there is a virtual file system # The result of the command is that the: / dev/sda3 partition is mounted to the / directory, the file system is ext4, and the permissions are read and write [root@localhost] # mount /dev/sda3 on/type ext4(rw)proc on/proc type proc(rw) sysfs on/sys type sysfs(rw) devpts on/dev/pts type devpts(rw，gid=5，mode=620) tmpfs on/dev/shm type tmpfs(rw) /dev/sdal on/boot type ext4(rw) none on/proc/sys/fs/binfmt_misc type binfmt_misc(rw) sunrpe on/var/lib/nfs/rpe_pipefs type rpc_pipefs(rw) # 2. Modify special permissions #When we see that the / boot partition has been mounted and the defaults option is used, we remount the partition and use noexec [root@localhost ~]# mount -o remount, noexec /boot (Provisional) # Then use the mount command to query the partition. The boot partition has more noexec permissions # /dev/sdal on /boot type ext4 (rw,noexec) # Permission forbids the execution of the executable file. See what happens (be careful not to experiment with the root partition,#Otherwise, the system command cannot be executed). # Execute a shell script [root@localhost boot]# ./hello.sh -bash:./hello.sh: insufficient privilege # After modifying the permissions, you can execute it. [root@localhost ~]# mount -o remount，exec /boot
In this exercise, you should also remember the function and use of remount.