追踪网络问题时,看到这么一段bash脚本,发现应该很有用.
# Don't shut the network down if root is on NFS or a network
# block device.
rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/mtab)
rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
if [[ "$rootfs" =~ ^nfs ]] || [[ "$rootopts" =~ "_netdev|_rnetdev" ]] ; then
exit 1
fi
关于/etc/mtab 的作用,可以看busybox关于mount命令是否支持/etc/mtab这个配置选项的描述:
config FEATURE_MTAB_SUPPORT
bool "Support for the old /etc/mtab file"
default n
depends on MOUNT || UMOUNT
select FEATURE_MOUNT_FAKE
help
Historically, Unix systems kept track of the currently mounted
partitions in the file "/etc/mtab". These days, the kernel exports
the list of currently mounted partitions in "/proc/mounts", rendering
the old mtab file obsolete. (In modern systems, /etc/mtab should be
a symlink to /proc/mounts.)
The only reason to have mount maintain an /etc/mtab file itself is if
your stripped-down embedded system does not have a /proc directory.
If you must use this, keep in mind it's inherently brittle (for
example a mount under chroot won't update it), can't handle modern
features like separate per-process filesystem namespaces, requires
that your /etc directory be writeable, tends to get easily confused
by --bind or --move mounts, won't update if you rename a directory
that contains a mount point, and so on. (In brief: avoid.)
About the only reason to use this is if you've removed /proc from
your kernel.
endmenu
# Don't shut the network down if root is on NFS or a network
# block device.
rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/mtab)
rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
if [[ "$rootfs" =~ ^nfs ]] || [[ "$rootopts" =~ "_netdev|_rnetdev" ]] ; then
exit 1
fi
关于/etc/mtab 的作用,可以看busybox关于mount命令是否支持/etc/mtab这个配置选项的描述:
config FEATURE_MTAB_SUPPORT
bool "Support for the old /etc/mtab file"
default n
depends on MOUNT || UMOUNT
select FEATURE_MOUNT_FAKE
help
Historically, Unix systems kept track of the currently mounted
partitions in the file "/etc/mtab". These days, the kernel exports
the list of currently mounted partitions in "/proc/mounts", rendering
the old mtab file obsolete. (In modern systems, /etc/mtab should be
a symlink to /proc/mounts.)
The only reason to have mount maintain an /etc/mtab file itself is if
your stripped-down embedded system does not have a /proc directory.
If you must use this, keep in mind it's inherently brittle (for
example a mount under chroot won't update it), can't handle modern
features like separate per-process filesystem namespaces, requires
that your /etc directory be writeable, tends to get easily confused
by --bind or --move mounts, won't update if you rename a directory
that contains a mount point, and so on. (In brief: avoid.)
About the only reason to use this is if you've removed /proc from
your kernel.
endmenu