Check if running chrooted

This script checks if we are running in a chroot environment

#!/bin/sh
# Name: checkroot.sh
# Author: kdguntu@gmail.com
# Function: check if the script is running within a chroot environment
# Parameter: none
# Copyright: 2011 kdguntu@gmail.com GNU GPL v3
# http://www.gnu.org/licenses/gpl.html
 
if [ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ];
  then echo "Don’t run this script within the chroot environment"
  exit 1
fi
This entry was posted in bash, chroot, linux, stat, ubuntu. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *