Linux mount命令是经常会使用到的命令,它用于挂载Linux系统外的文件系统。
Linux kernel是没法自动检测到文件系统的,当你使用mount命令要挂载一个文件系统,要加上文件系统类型的参数,或者指定auto,那kernel就会遍历其所支持的文件系统挨个尝试。而kernel所支持的文件系统列表,位于/proc/filesystems中。
比如ubuntu中的:
$ cat /proc/filesystems
nodev sysfs
nodev tmpfs
nodev bdev
nodev proc
nodev cgroup
nodev cgroup2
nodev cpuset
nodev devtmpfs
nodev configfs
nodev debugfs
nodev tracefs
nodev securityfs
nodev sockfs
nodev bpf
nodev pipefs
nodev ramfs
nodev hugetlbfs
nodev devpts
ext3
ext2
ext4
squashfs
vfat
nodev ecryptfs
fuseblk
nodev fuse
nodev fusectl
nodev mqueue
nodev pstore
nodev autofs
嵌入式Linux中:
# cat /proc/filesystems
nodev sysfs
nodev tmpfs
nodev bdev
nodev proc
nodev devtmpfs
nodev configfs
nodev debugfs
nodev sockfs
nodev pipefs
nodev ramfs
nodev devpts
squashfs
nodev jffs2
mount命令使用
显示帮助信息:
mount --help
Busybox里显示的帮助信息:
BusyBox v1.35.0 (2022-09-06 10:02:21 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.
举例:
将 /dev/hda1 用只读模式挂在 /mnt文件夹下:
# mount -o ro /dev/hda1 /mnt
比如我们要mount一个debugfs的话:
# mount -t debugfs none /sys/kernel/debug/
# ln -s /sys/kernel/debug /debug
如果直接执行mount命令,就会显示当前已经mount的文件系统,比如:
# mount
/dev/root on / type squashfs (ro,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=43548k,nr_inodes=10887,mode=755)
tmpfs on /dev type tmpfs (rw,relatime)
proc on /proc type proc (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=666)
tmpfs on /dev/shm type tmpfs (rw,relatime,mode=777)
tmpfs on /tmp type tmpfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755)
sysfs on /sys type sysfs (rw,relatime)
/dev/mtdblock_bbt_ro3 on /usr/data type jffs2 (rw,relatime)
none on /sys/kernel/config type configfs (rw,relatime)
none on /sys/kernel/debug type debugfs (rw,relatime)
什么是debugfs?
debugfs is a special file system available in the Linux kernel since version 2.6. 10-rc3. It was written by Greg Kroah-Hartman. debugfs is a simple-to-use RAM-based file system specially designed for debugging purposes. It exists as a simple way for kernel developers to make information available to user space.
debugfs是一个特殊的文件系统,从2.6.10-rc3版本开始在Linux内核中使用。debugfs是一个简单易用的基于RAM的文件系统,专门为调试目的设计。它的存在是为内核开发者提供一种简单的方法,在用户空间中获取内核的相关信息。
参考: