三种方法,让linux帮你查看磁盘挂载
最编程
2024-08-14 22:52:55
...
第一种方法:使用df命令,例如:
orientalson:/home # df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 15213032 8043668 7169364 53% / udev 514496 104 514392 1% /dev /dev/mapper/vg_test-lv_test 511980 32840 479140 7% /home/mt orientalson:/home #
上面显示的挂载点/home/mt和她挂载的卷不在同一行,使用shell脚本分析非常麻烦。
第二种方法:使用mount命令,mount -l,这种方法的缺陷在于没有卷的大小,但是挂载点和挂载的卷在同一行。例如:
orientalson:/home # mount -l /dev/sda2 on / type reiserfs (rw,acl,user_xattr) [] proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) debugfs on /sys/kernel/debug type debugfs (rw) udev on /dev type tmpfs (rw) devpts on /dev/pts type devpts (rw,mode=0620,gid=5) securityfs on /sys/kernel/security type securityfs (rw) /dev/mapper/vg_test-lv_test on /home/mt type reiserfs (rw) [] orientalson:/home #
第三种方法:查看文件/etc/mtab。原理是,每新挂载一个卷基本上都会更新这个文件的,那么自然可以通过这个文件来查看挂载点和挂职的卷。这种方法比mount -l稍微清晰了一点,但是,有时候是不可靠的。
orientalson:/home # cat /etc/mtab /dev/sda2 / reiserfs rw,acl,user_xattr 0 0 proc /proc proc rw 0 0 sysfs /sys sysfs rw 0 0 debugfs /sys/kernel/debug debugfs rw 0 0 udev /dev tmpfs rw 0 0 devpts /dev/pts devpts rw,mode=0620,gid=5 0 0 securityfs /sys/kernel/security securityfs rw 0 0 /dev/mapper/vg_test-lv_test /home/mt reiserfs rw 0 0 orientalson:/home #
上面已经说了基本上会更新这个文件,但是并不总是更新这个问题。如果挂载时使用了-n选项,那么/etc/mtab文件里面就不会新挂载卷的信息。
orientalson:/home # umount /home/mt orientalson:/home # mount -n /dev/vg_test/lv_test /home/mt orientalson:/home # cat /etc/mtab /dev/sda2 / reiserfs rw,acl,user_xattr 0 0 proc /proc proc rw 0 0 sysfs /sys sysfs rw 0 0 debugfs /sys/kernel/debug debugfs rw 0 0 udev /dev tmpfs rw 0 0 devpts /dev/pts devpts rw,mode=0620,gid=5 0 0 securityfs /sys/kernel/security securityfs rw 0 0 orientalson:/home #
推荐阅读
-
使用Linux查看磁盘和挂载的方法
-
三种方法,让linux帮你查看磁盘挂载
-
紧急模式问题处理 - 图 1 紧急模式 根本原因分析 应急模式提供了尽可能小的环境,即使无法进入应急模式,也可以在其中修复系统。在应急模式下,系统只安装根文件系统供读取,不尝试安装任何其他本地文件系统,不激活网络接口,只启动一些基本服务。 进入应急模式的原因通常是 /etc/fstab 文件中存在错误,导致文件系统挂载失败。 文件系统中存在错误,导致。 约束和限制 本节适用于 Linux 操作系统紧急模式。程序涉及修复文件系统。修复文件系统有丢失数据的风险,因此请先备份数据,然后再执行修复操作。 处理方法 输入根密码,然后进入修复模式。 在应急模式下,根分区以只读模式挂载。要修改根目录中的文件,需要执行以下命令以读写模式重新挂载根分区。# mount -o rw,remount / 请执行以下命令首先检查 fstab 文件是否有误,然后尝试挂载所有未挂载的文件系统。# mount -a 如果挂载点不存在,请创建一个挂载点。 如果不存在此类设备,请注释或删除挂载行。 如果指定了不正确的挂载选项,请将挂载参数更改为正确的参数。 如果没有发生错误,但出现 UNEXPECTED INCONSISTENCY;RUN fsck MANUALLY 消息(通常是由文件系统错误引起的),请跳至第 7 步。 执行以下命令打开 /etc/fstab 以修改相应的错误。# vi /etc/fstab /etc/fstab 文件包含以下字段,以空格分隔:[文件系统] [dir] [type] [options] [dump] [fsck] 表 1 /etc/fstab 参数 说明 参数 说明 [文件系统] 要挂载的分区或存储设备。 文件系统]列建议以 UUID 的形式写入。执行 blkid 命令可查询设备文件系统 UUID。 参考格式如下: # <device> <dir> <type> <options> <dump> <fsck>; UUID=b411dc99-f0a0-4c87-9e05-184977be8539 /home ext4 defaults 0 2 使用 UUID 的好处是,它们与磁盘顺序无关。如果你在 BIOS 中更改了存储设备的顺序,或重新插入了存储设备,或者因为某些 BIOS 可能会随机更改存储设备的顺序,那么使用 UUID 会更有效率。 [文件系统] 文件系统]的挂载位置。 类型 挂载设备或分区的文件系统类型,支持多种不同的文件系统:ext2、ext3、ext4、reiserfs、xfs、jfs、smbfs、iso9660、vfat、ntfs、swap 和 auto。 设置为自动类型后,挂载命令会猜测所使用的文件系统类型,这对 CDROM 和 DVD 等移动设备非常有用。 选项 挂载时要使用的参数,有些参数是特定文件系统特有的。例如,默认值参数使用文件系统的默认挂载参数,ext4 的默认参数为:rw、suid、dev、exec、auto、nouser、async。 有关更多参数,请执行以下命令查看 man 手册:# man mount