文章目录
-
- [1. 背景](#1. 背景)
- [2. 命令选项](#2. 命令选项)
- [3. 举例](#3. 举例)
1. 背景
在日常嵌入式开发中,经常需要对一些外插设备和网络设备进行挂载,常用的挂载指令为
mount,现在对此指令进行记录总结。
2. 命令选项
- 命令参数
bash
# mount --help
BusyBox v1.37.0 (2025-12-05 18:01:56 CST) multi-call binary.
Usage: mount [OPTIONS] [-o OPT] DEVICE NODE
Mount a filesystem. Filesystem autodetection requires /proc.
-a Mount all filesystems in fstab
-r Read-only mount
-t FSTYPE[,...] Filesystem type(s)
-T FILE Read FILE instead of /etc/fstab
-O OPT Mount only filesystems with option OPT (-a only)
-o OPT:
loop Ignored (loop devices are autodetected)
[a]sync Writes are [a]synchronous
[no]atime Disable/enable updates to inode access times
[no]diratime Disable/enable atime updates to directories
[no]relatime Disable/enable atime updates relative to modification time
[no]dev (Dis)allow use of special device files
[no]exec (Dis)allow use of executable files
[no]suid (Dis)allow set-user-id-root programs
[r]shared Convert [recursively] to a shared subtree
[r]slave Convert [recursively] to a slave subtree
[r]private Convert [recursively] to a private subtree
[un]bindable Make mount point [un]able to be bind mounted
[r]bind Bind a file or directory [recursively] to another location
move Relocate an existing mount point
remount Remount a mounted filesystem, changing flags
ro Same as -r
There are filesystem-specific -o flags.
- 其中
mount [OPTIONS] [-o OPT] DEVICE NODE为使用方法,DEVICE就是我们设备里面dev目录下的设备节点,NODE就是我们要挂载到的目录。
其中最主要的是-t 挂载系统和 -o挂载选项。
- -t(type)用于显式声明要挂载的文件系统类型。如果不指定,mount 会自动探测(但有时会失败)。
常见文件系统类型:
| 类型 | 说明 |
|---|---|
ext4 |
Linux 标准日志文件系统 |
ext3 / ext2 |
旧版 Linux 文件系统 |
xfs |
高性能日志文件系统(常用于服务器) |
btrfs |
支持快照、压缩等高级功能 |
vfat / msdos |
FAT16/FAT32(U盘、SD卡常用) |
ntfs |
Windows NTFS(需 ntfs-3g 驱动) |
iso9660 |
光盘镜像(.iso 文件) |
tmpfs |
基于内存的临时文件系统 |
proc |
内核虚拟文件系统(/proc) |
sysfs |
设备与驱动信息(/sys) |
nfs |
网络文件系统 |
cifs / smbfs |
Windows 共享(SMB/CIFS) |
- -o 用于指定挂载时的行为参数,多个选项用逗号分隔(无空格)
| 选项 | 作用 |
|---|---|
ro |
只读挂载(read-only) |
rw |
读写挂载(默认) |
noexec |
禁止执行该分区上的程序 |
nosuid |
忽略 set-user-identifier / set-group-identifier 位 |
nodev |
忽略设备文件(安全加固常用) |
sync |
同步写入(数据立即刷盘,安全但慢) |
async |
异步写入(默认,性能好) |
3. 举例
- 重新挂载根分区为读写(救援模式常用)
bash
mount -o remount,rw /
- 创建内存临时目录
bash
sudo mount -t tmpfs -o size=100m tmpfs /tmp/mytmp
- 挂载 ext4 分区
bash
sudo mount -t ext4 /dev/sdb1 /mnt/data`
- 挂载 U 盘(FAT32)
bash
sudo mount -t vfat /dev/sdc1 /mnt/usb
- 挂载 ISO 镜像
bash
sudo mount -t iso9660 -o loop ubuntu.iso /mnt/iso
- 挂载 nfs
bash
sudo mount -t nfs -o nolock 192.168.100.100:/data/ /mnt/nfs