Home Operation and Maintenance Linux 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?

Jan 28, 2023 pm 05:34 PM
linux mount

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 the mount mount 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:

1

# mount [-l]

Copy after login

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

1

# mount -a

Copy after login

-a option 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.

1

# 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 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;

  • -o Special 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
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】

1

2

3

4

5

6

7

8

9

10

[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 权限禁止执行文件执行,看看会出现什么情况(注意不要用 / 分区做实验,否则系统命令也就不能执行了。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

[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】挂载分区。

1

2

3

4

5

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

See all articles