29.08.2014, 19:53 UhrDeutsch | English
Hallo Gast [ Registrierung | Anmelden ]

Kleines Script für Chroot


Hier ein Kleines Script um sich die einzelnen Schritte für Chroot zu ersparen.

Das Script erwartet den Scriptnamen und als Argument das Device in das 'gechrooted' werden soll, ohne ein führendes '/dev/'.
Zum Beispiel:

chroot.sh sda8

um ein Chroot in die Partition /dev/sda8 durchzuführen. Nachdem die Arbeiten in der Chroot-Umgebung erledigt sind, verlässt man sie wieder mit dem Befehl "exit". Das Script hängt danach die Mountpunkte wieder aus.

#!/bin/bash

CHROOTDIR=/mnt/chroot

# Make sure only root can run our script
if [ $EUID -ne 0 ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

# Make sure that $1 is not empty
if [ ! -n "$1" ]; then
echo -e "\033[1;33mYou must give an argument which device you want to chroot in (without leading '/dev/') "
echo -e "\033[1;33mExample '$0 sda8' will chroot the device /dev/sda8 into /mnt/chroot."
exit 1
fi

# Make sure that directory '/mnt/chroot' exists
if [ ! -d $CHROOTDIR ]; then
 echo Error: No directory $CHROOTDIR existing. Creating it... !! >&2
 mkdir -p $CHROOTDIR
fi
if [ -d $CHROOTDIR ]; then
  echo Created directory $CHROOTDIR successfully... >&2
  echo Now chrooting into /dev/$1 ... >&2
fi

if [ -d $CHROOTDIR ]; then
mount /dev/$1 $CHROOTDIR
mount -t proc proc $CHROOTDIR/proc
mount -o bind /dev $CHROOTDIR/dev
cp -L /etc/resolv.conf $CHROOTDIR/etc/resolv.conf
chroot $CHROOTDIR /bin/bash

fi

echo unmounting the devices from the chroot directory ... >&2

if [ -d $CHROOTDIR ]; then
umount $CHROOTDIR/proc
umount $CHROOTDIR/dev
umount $CHROOTDIR
fi

echo deleting chroot directory $CHROOTDIR ... >&2
rmdir $CHROOTDIR
if [ ! -d $CHROOTDIR ]; then
echo $CHROOTDIR deleted successfully. Good bye !! >&2
fi
XML Revisions of $tag
Seiten-History :: Letzter Editor : Brilliant :: Eigentümer : krishan1 ::
Powered by pnWikka 1.0
 
 
Deutsch | English
Logos and trademarks are the property of their respective owners, comments are property of their posters, the rest is © 2004 - 2006 by Jörg Schirottke (Kano).
Consult Impressum and Legal Terms for details. Kanotix is Free Software released under the GNU/GPL license.
This CMS is powered by PostNuke, all themes used at this site are released under the GNU/GPL license. designed and hosted by w3you. Our web server is running on Kanotix64-2006.