简体   繁体   English

如何在bash中确定/ mountpoint是否从其他操作系统挂载?

[英]How to determine in bash if / mountpoint was mounted from other OS?

Im writing shell script to check if user may be doing some nasty things in Linux enviroment. 我正在编写shell脚本来检查用户是否在Linux环境中做一些令人讨厌的事情。 One check i would like to do is determine if / filesyste was mounted using external OS (like using live SO) in previous mount. 我想做的一项检查是确定/ filesyste是否在以前的安装中是使用外部OS(例如使用live SO)安装的。

First i think to exec script when boot to get the mount time in previous boot using journalctl and actual last mount using tune2fs, to compare it. 首先,我想在启动时执行exec脚本,以比较使用journalctl进行上一次引导的安装时间,并使用tune2fs进行实际的最后一次安装,以进行比较。 But last mount using tune2fs gets current mount, not previous, because system is mounted when ckecks it. 但是最后一次使用tune2fs的安装会获得当前的安装,而不是之前的安装,因为系统会在进行ckeck时安装。

Any idea to solve it? 有解决的办法吗? Thanks! 谢谢!

dmesg 's output shows about the mounting of / (and other infos as well). dmesg的输出显示有关/的安装(以及其他信息)。 If your current OS's dmesg 's output has that info, it was mounted by the current system. 如果您当前操作系统的dmesg的输出包含该信息,则该信息已由当前系统挂载。

You can use the output of dmesg in your script like : 您可以在脚本中使用dmesg的输出,例如:

#!/bin/bash
number=$(dmesg | grep -c "sdaN")
if [ $number == 0 ]; then
    echo "It was not mounted by the current system"
else
    echo "It was mounted by the current system"
fi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM