简体   繁体   中英

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. One check i would like to do is determine if / filesyste was mounted using external OS (like using live SO) in previous mount.

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. But last mount using tune2fs gets current mount, not previous, because system is mounted when ckecks it.

Any idea to solve it? Thanks!

dmesg 's output shows about the mounting of / (and other infos as well). If your current OS's dmesg 's output has that info, it was mounted by the current system.

You can use the output of dmesg in your script like :

#!/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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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