search
HomeOperation and MaintenanceLinux Operation and MaintenanceIs the command to mount a hard disk in Linux the mount command?

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:

# mount [-l]

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

# mount -a

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

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

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
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
What is Maintenance Mode in Linux? ExplainedWhat is Maintenance Mode in Linux? ExplainedApr 22, 2025 am 12:06 AM

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

Linux: A Deep Dive into Its Fundamental PartsLinux: A Deep Dive into Its Fundamental PartsApr 21, 2025 am 12:03 AM

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

Linux Architecture: Unveiling the 5 Basic ComponentsLinux Architecture: Unveiling the 5 Basic ComponentsApr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Linux Operations: Utilizing the Maintenance ModeLinux Operations: Utilizing the Maintenance ModeApr 19, 2025 am 12:08 AM

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

Linux: How to Enter Recovery Mode (and Maintenance)Linux: How to Enter Recovery Mode (and Maintenance)Apr 18, 2025 am 12:05 AM

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

Linux's Essential Components: Explained for BeginnersLinux's Essential Components: Explained for BeginnersApr 17, 2025 am 12:08 AM

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

Linux: A Look at Its Fundamental StructureLinux: A Look at Its Fundamental StructureApr 16, 2025 am 12:01 AM

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

Linux Operations: System Administration and MaintenanceLinux Operations: System Administration and MaintenanceApr 15, 2025 am 12:10 AM

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

See all articles

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools