Home>Article>Operation and Maintenance> Is the command to mount a hard disk in Linux the mount command?

Is the command to mount a hard disk in Linux the mount command?

青灯夜游
青灯夜游 Original
2023-01-28 17:34:41 4109browse

The linux command to mount a hard disk is the mount command. Mount is a mounting command that can mount a partition under a folder to connect the partition and the directory. In the future, simply accessing this folder will be equivalent to accessing the partition. The syntax is "mount [-t system type] [- L volume name] [-o special option] [-n] device file name mount point".

Is the command to mount a hard disk in Linux the mount command?

#The operating environment of this tutorial: linux7.3 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".

If it is not mounted, the hardware device can be found through the graphical interface system in the Linux system, but it cannot be found through the command line.

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

To mount the file system to a Linux system, you need to use themountmount command.

Linux mount command: Mount files outside the Linux system

The mount command is to mount the partition to a folder. The partition is associated with the directory. In the future, as long as we access this folder, it will be equivalent to accessing the partition.

The common formats of the mount command are as follows:

# mount [-l]

Simply using the mount command will display the mounted device information in the system, use the-loption , the volume name will be additionally displayed (readers can run it by themselves to view the output); the

# mount -a

-aoption means to automatically check whether there are any omissions in the /etc/fstab file. If there is a device file to be loaded, the device file will be automatically mounted. 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.

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

The meanings of each option are:

  • -tSystem 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.

  • -LVolume label name: In addition to using the device file name (such as /dev/hdc6), you can also use the file system’s volume label name to mount load.

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

  • -oSpecial options: You can specify additional options for mounting, such as read and write permissions, synchronization/asynchronous, etc. If not specified, the defaults will be used. For specific special options, see Table 1;

Table 1 mount command options and functions
Options Function
rw/ro Whether 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/sync Whether this file system uses synchronous writing (sync) or asynchronous (async) memory mechanism, the default is asynchronous async.
dev/nodev Whether 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/noauto Whether to allow this file system to be automatically mounted using mount -a, the default is auto.
suid/nosuid Set whether the file system has SetUID and SetGID permissions. The default is yes.
exec/noexec Set whether to allow execution of executable files in the file system. The default is allowed.
user/nouser Set whether this file system allows ordinary users to use mount to perform mounting. The default is not allowed (nouser), only root can .
defaults Define the default value, which is equivalent to the seven options of rw, suid, dev, exec, auto, nouser, and async.
remount Remount 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)

【例 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 #记得改回来,否则会影响系统启动

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

【例 3】挂载分区。

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

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

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

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

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

推荐学习:Linux视频教程

The above is the detailed content of Is the command to mount a hard disk in Linux the mount command?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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