14 Şubat 2013 Perşembe

316. Briefly: Automated chroot/sandbox creation

To contact us Click HERE
I've been using chroot to compile and test stuff so much lately that I figure it was time to automate the process.

Before creating your chroot you'll need a few packages:
sudo apt-get install debootstrap coreutils x11-xserver-utils


The scripts
makechroot.sh
mkdir $HOME/tmp/jail/$1 -psudo debootstrap --arch amd64 testing $HOME/tmp/jail/$1 http://ftp.au.debian.org/debian/sudo cp setupchroot.sh $HOME/tmp/jail/$1/

setupchroot.sh
rm /etc/apt/sources.listecho 'deb http://ftp.au.debian.org/debian/ wheezy main contrib non-free' >> /etc/apt/sources.listapt-get updateapt-get install locales sudo vimecho 'export LC_ALL="C"'>>/etc/bash.bashrcecho 'export LANG="C"'>>/etc/bash.bashrcecho 'export DISPLAY=:0.0' >> /etc/bash.bashrcecho '127.0.0.1 beryllium >> /etc/hosts'source /etc/bash.bashrcadduser sandboxusermod -g sudo sandboxecho 'Defaults !tty_tickets' >> /etc/sudoers

launchchroot.sh
xhost +sudo mount -o bind /proc $1/procsudo cp /etc/resolv.conf $1/etc/resolv.confsudo chroot $HOME/tmp/jail/$1

How to use
To set up the chroot:
sh makechroot.sh mynewchrootsudo chroot mynewchrootroot@beryllium:/# sh setupchroot.sh

To use the chroot:
sh launchchroot.sh mynewchroot

Once you're done with the chroot and logged out, do
sudo umount $HOME/tmp/jail/mynewchroot/proc

to unmount the /proc -- you can now delete, copy etc. the directory structure of you chroot.

Hiç yorum yok:

Yorum Gönder