Linux - mount命令和debugfs

本文介绍了Linux系统中的mount命令,详细解释了如何使用该命令来挂载不同类型的文件系统,并提供了具体的例子。此外,还介绍了debugfs文件系统及其用途。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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的文件系统,专门为调试目的设计。它的存在是为内核开发者提供一种简单的方法,在用户空间中获取内核的相关信息。

参考:

debugfs mount point [LWN.net]

c - autodetect filesystem on mount() - Stack Overflow

https://en.wikipedia.org/wiki/Debugfs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜流冰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值