简体   繁体   English

如何检查 /tmp 和 /proc 文件系统是否安装在 chroot 环境中?

[英]How to check if /tmp and /proc filesysystems are mounted in a chrooted environment?

I have already tried mounting the filesystems without checking like this:我已经尝试过不检查就挂载文件系统:

sudo -- mount -t proc /proc $chroot_dir/proc
sudo -- mount --bind /tmp $chroot_dir/tmp

However, this would corrupt the parent OS session if already mounted, and I would have to restart the OS.但是,如果已经安装,这会破坏父操作系统 session,我将不得不重新启动操作系统。 I want to check if they're mounted beforehand.我想检查它们是否事先安装。

You can see in /etc/mtab what's currently mounted:您可以在/etc/mtab中查看当前挂载的内容:

if grep $chroot_dir/proc /etc/mtab; then
  echo already mounted
fi;

And analogously for tmp .和类似的tmp

Or you can use the output of mount:或者你可以使用 output 挂载:

is_mounted() {
    local drives=`mount | grep "$1" | awk '{print $3}'`
    local arr=($drives)
    for d in $arr; do
        if [ "$d" == "$1" ]; then
            return 0
        fi
    done
    return 1
}

which returns 0 if the path $chroot_dir/proc is mounted.如果安装了路径 $chroot_dir/proc 则返回 0。 So after issuing:所以发出后:

sudo -- mount -t proc /proc $chroot_dir/proc

the above function will return 0:上面的 function 将返回 0:

is_mounted $chroot_dir/proc
echo $?

and 1 otherwise和 1 否则

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

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