挂载更新 /proc/mount 但不更新 /etc/mtab,导致分区不显示在 df、挂载列表中

挂载更新 /proc/mount 但不更新 /etc/mtab,导致分区不显示在 df、挂载列表中

我在 RHEL 6 上。我使用 parted 创建了一些分区,使用 mke2fs 格式化它们,并使用 mount 挂载它们。我还将它们添加到 /etc/fstab。但是,它们没有显示在 mount 或 df 列表中。

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/vda1              20G  1.9G   17G  10% /
tmpfs                  58G     0   58G   0% /dev/shm

$ mount
/dev/vda1 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

$ cat /etc/mtab
/dev/vda1 / ext4 rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0

但是,分区确实显示为已在 /proc/mounts 中挂载:

$ cat /proc/mounts
rootfs / rootfs rw 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
devtmpfs /dev devtmpfs rw,nosuid,relatime,size=60487100k,nr_inodes=15121775,mode=755 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
/dev/vda1 / ext4 rw,relatime,barrier=1,data=ordered 0 0
/proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0
/etc/auto.misc /misc autofs rw,relatime,fd=7,pgrp=2265,timeout=300,minproto=5,maxproto=5,indirect 0 0
-hosts /net autofs rw,relatime,fd=13,pgrp=2265,timeout=300,minproto=5,maxproto=5,indirect 0 0
/dev/vdb1 /mnt ext4 rw,relatime,barrier=1,data=ordered 0 0
/dev/vdc1 /disks/vdc1 ext4 rw,relatime,barrier=1,data=ordered 0 0
/dev/vdd1 /disks/vdd1 ext4 rw,relatime,barrier=1,data=ordered 0 0
/dev/vde1 /disks/vde1 ext4 rw,relatime,barrier=1,data=ordered 0 0
/dev/vdf1 /disks/vdf1 ext4 rw,relatime,barrier=1,data=ordered 0 0
/dev/vdg1 /disks/vdg1 ext4 rw,relatime,barrier=1,data=ordered 0 0
/dev/vdh1 /disks/vdh1 ext4 rw,relatime,barrier=1,data=ordered 0 0
/dev/vdi1 /disks/vdi1 ext4 rw,relatime,barrier=1,data=ordered 0 0
/dev/vdj1 /disks/vdj1 ext4 rw,relatime,barrier=1,data=ordered 0 0
/dev/vdk1 /disks/vdk1 ext4 rw,relatime,barrier=1,data=ordered 0 0

使用上述内容覆盖 /etc/mtab 可以使 df 工作:

# cat /proc/mounts > /etc/mtab

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
rootfs                 20G  1.9G   17G  10% /
devtmpfs               58G  232K   58G   1% /dev
tmpfs                  58G     0   58G   0% /dev/shm
/dev/vda1              20G  1.9G   17G  10% /
/dev/vdb1             2.7T  202M  2.6T   1% /mnt
/dev/vdc1             2.7T  201M  2.6T   1% /disks/vdc1
/dev/vdd1             2.7T  201M  2.6T   1% /disks/vdd1
/dev/vde1             2.7T  201M  2.6T   1% /disks/vde1
/dev/vdf1             2.7T  201M  2.6T   1% /disks/vdf1
/dev/vdg1             2.7T  201M  2.6T   1% /disks/vdg1
/dev/vdh1             2.7T  201M  2.6T   1% /disks/vdh1
/dev/vdi1             2.7T  201M  2.6T   1% /disks/vdi1
/dev/vdj1             2.7T  201M  2.6T   1% /disks/vdj1
/dev/vdk1             2.7T  201M  2.6T   1% /disks/vdk1

这让我摆脱了眼前的问题,但我仍然想了解为什么 mount 没有正确更新 /etc/mtab。有什么想法吗?

编辑:根据要求,fdisk -l 的输出:

$ sudo fdisk -l

Disk /dev/vda: 21.5 GB, 21474836480 bytes
43 heads, 16 sectors/track, 60963 cylinders
Units = cylinders of 688 * 512 = 352256 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00054b77

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1               3       60964    20970496   83  Linux

WARNING: GPT (GUID Partition Table) detected on '/dev/vdb'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/vdb: 3000.0 GB, 2999999004672 bytes
255 heads, 63 sectors/track, 364729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1      267350  2147483647+  ee  GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/vdc'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/vdc: 3000.0 GB, 2999999004672 bytes
255 heads, 63 sectors/track, 364729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vdc1               1      267350  2147483647+  ee  GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/vdd'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/vdd: 3000.0 GB, 2999999004672 bytes
255 heads, 63 sectors/track, 364729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vdd1               1      267350  2147483647+  ee  GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/vde'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/vde: 3000.0 GB, 2999999004672 bytes
255 heads, 63 sectors/track, 364729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vde1               1      267350  2147483647+  ee  GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/vdf'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/vdf: 3000.0 GB, 2999999004672 bytes
255 heads, 63 sectors/track, 364729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vdf1               1      267350  2147483647+  ee  GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/vdg'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/vdg: 3000.0 GB, 2999999004672 bytes
255 heads, 63 sectors/track, 364729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vdg1               1      267350  2147483647+  ee  GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/vdh'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/vdh: 3000.0 GB, 2999999004672 bytes
255 heads, 63 sectors/track, 364729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vdh1               1      267350  2147483647+  ee  GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/vdi'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/vdi: 3000.0 GB, 2999999004672 bytes
255 heads, 63 sectors/track, 364729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vdi1               1      267350  2147483647+  ee  GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/vdj'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/vdj: 3000.0 GB, 2999999004672 bytes
255 heads, 63 sectors/track, 364729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vdj1               1      267350  2147483647+  ee  GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/vdk'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/vdk: 3000.0 GB, 2999999004672 bytes
255 heads, 63 sectors/track, 364729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vdk1               1      267350  2147483647+  ee  GPT

答案1

在我犯了手动编辑的错误后,这种情况就发生在我身上/etc/mtab。这就是为什么现有的每本手册都说 - 不要这样做 :) 编辑本身是无害的 - 我重命名了已安装逻辑卷的 LVM 卷组,并且需要对其mtab条目进行简单的更新,以便mount -a停止报告虚假错误。问题是我的编辑器在 处留下了一个简单的备份文件/etc/mtab~

所有mount(8)调用都停止更新mtab,并开始花费约 30 秒的时间运行,这相当可疑。遗憾的是,它甚至没有打印警告,花了一段时间才strace弄清楚:

% sudo strace mount /something
[...]
link("/etc/mtab~.10889", "/etc/mtab~")  = -1 EEXIST (File exists)
open("/etc/mtab~", O_WRONLY)            = 3
[...]
unlink("/etc/mtab~.10889")              = 0
[...]

它循环执行了该组link()和调用,但最终放弃并执行了临时文件的操作。open()unlink()

解决方案很简单,就是手动删除该备份/etc/mtab~

相关内容