What does mount in linux mean?

青灯夜游
Release: 2022-04-12 17:50:34
Original
9041 people have browsed it

In Linux, mount means "mounting" and is used to associate the device file system and the Linux file system through the specified directory; the syntax is "mount [-t system type] [-L volume name] [-o special option] [-n] device file name mount point", "mount -a", etc.

What does mount in linux mean?

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

In the Linux system, "everything is a file", and all files are placed in a tree directory structure with the root directory as the root. From Linux's perspective, any hardware device is also a file, and each of them has its own file system (file directory structure).

The problem that arises is that when using these hardware devices in a Linux system, the hardware device can only be used by us if the file directory of Linux itself and the file directory of the hardware device are combined into one. The process of combining the two into one is called "mounting".

Mounting refers to connecting the top-level directory in the device file to a directory under the Linux root directory (preferably an empty directory). Accessing this directory is equivalent to accessing the device file.

Mounting refers to associating the file system of the hardware device with the file system in the Linux system by specifying the directory (as the mount point). To mount the file system on a Linux system, you need to use the mount command.

The common formats of the mount command are as follows:

mount [-l]
Copy after login

Simply using the mount command will display the device information that has been mounted in the system. Using the -l option will additionally display the volume. Tag name (readers can run it themselves and view the output results);

mount -a
Copy after login

-a option means to automatically check whether there are any omitted mounted device files in the /etc/fstab file. If If yes, the automatic mounting operation will be performed. Here is a brief introduction to the /etc/fstab file. This file is an automatically mounted file. When the system is powered on, it will actively read the contents of the /etc/fstab file. According to the configuration of the file, the system will automatically mount the specified device. The specific introduction to automatic mounting (modifying this file) will be explained in a subsequent article.

mount [-t 系统类型] [-L 卷标名] [-o 特殊选项] [-n] 设备文件名 挂载点
Copy after login

The meanings of each option are:

  • -t System type: Specify the file system type to be mounted. Commonly supported types in Linux include EXT2, EXT3, EXT4, iso9660 (disc format), vfat, reiserfs, etc. If you do not specify a specific type, Linux will automatically detect it when mounting.

  • -L Volume label name: In addition to using the device file name (such as /dev/hdc6), you can also use the volume label name of the file system for mounting.

  • -n: By default, the system will write the actual mounting situation into the /etc/mtab file in real time, but in some scenarios (such as single-player maintenance mode ), in order to avoid problems, it will be deliberately not written. In this case, you need to use this option;

  • -o Special options: You can specify additional options for mounting, such as read and write permissions , synchronous/asynchronous, etc., if not specified, the defaults are used. For specific special options, see Table 1;

Table 1 mount command options and functions
OptionsFunction
rw/roWhether you have read and write permissions on the mounted file system, rw is the default value, which means you have read and write permissions; ro means read-only permissions.
async/syncWhether this file system uses synchronous writing (sync) or asynchronous (async) memory mechanism, the default is asynchronous async.
dev/nodevWhether it is allowed to extract data from the block file of this file system. In order to ensure data installation, the default is nodev.
auto/noautoWhether to allow this file system to be automatically mounted using mount -a, the default is auto.
suid/nosuidSet whether the file system has SetUID and SetGID permissions. The default is yes.
exec/noexecSet whether to allow execution of executable files in the file system. The default is allowed.
user/nouserSet whether this file system allows ordinary users to use mount to perform mounting. The default is not allowed (nouser), only root can .
defaultsDefine the default value, which is equivalent to the seven options of rw, suid, dev, exec, auto, nouser, and async.
remountRemount the mounted file system, generally used to specify and modify special permissions.

【例 1】

[root@localhost ~]# mount
#查看系统中已经挂载的文件系统,注意有虚拟文件系统
/dev/sda3 on / type ext4 (rw)  <--含义是,将 /dev/sda3 分区挂载到了 / 目录上,文件系统是 ext4,具有读写权限
proc on /proc type proc (rw)
sysfe on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw, gid=5, mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fe/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfe/rpc_pipefs type rpc_pipefs (rw)
Copy after login

【例 2】

修改特殊权限。通过例 1 我们查看到,/boot 分区已经被挂载了,而且采用的是 defaults 选项。这里我们重新挂载分区,并采用 noexec 权限禁止执行文件执行,看看会出现什么情况(注意不要用 / 分区做实验,否则系统命令也就不能执行了。

[root@localhost ~]# mount -o remount noexec /boot
#重新挂载 /boot 分区,并使用 noexec 权限
[root@localhost sh]# cd /boot
#写一个 shell 脚本,看是否会运行
[root@localhost boot]#vi hello.sh
#!/bin/bash
echo "hello!!"
[root@localhost boot]# chmod 755 hello.sh
[root@localhost boot]# ./hello.sh
-bash:./hello.sh:权限不够
#虽然赋予了hello.sh执行权限,但是仍然无法执行
[root@localhost boot]# mount -o remount exec /boot
#记得改回来,否则会影响系统启动
Copy after login

对于特殊选项的修改,除非特殊场景下需要,否则不建议大家随意修改,非常容易造成系统出现问题,而且还找不到问题的根源。

【例 3】挂载分区。

[root@localhost ~]# mkdir /mnt/disk1
#建立挂载点目录
[root@localhost ~]# mount /dev/sdb1 /mnt/disk1
#挂载分区
Copy after login

/dev/sdb1 分区还没有被划分。我们在这里只看看挂载分区的方式,非常简单,甚至不需要使用 "-ext4" 命令指定文件系统,因为系统可以自动检测。

可能会想,为什么使用 Linux 系统的硬盘分区这么麻烦,而不能像 Windows 系统那样,硬盘安装上就可以使用?

其实,硬盘分区(设备)挂载和卸载(使用 umount 命令)的概念源自 UNIX,UNIX 系统一般是作为服务器使用的,系统安全非常重要,特别是在网络上,最简单有效的方法就是“不使用的硬盘分区(设备)不挂载”,因为没有挂载的硬盘分区是无法访问的,这样系统也就更安全了。

另外,这样也可以减少挂载的硬盘分区数量,相应地,也就可以减少系统维护文件的规模,当然也就减少了系统的开销,即提高了系统的效率。

相关推荐:《Linux视频教程

The above is the detailed content of What does mount in linux mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template