[SM-Discuss] chroot playground

Vladimír Marek vlmarek at volny.cz
Fri May 14 14:21:53 EDT 2004


Hello,
I'm currently playing with perl modules dependencties, and I got to
state I need some testing, which could eventually be dangerous to life
of my system :) With great help from Belxjander and great idea from
misantrop I put together theese three files, which can create chroot
from your /var/cache/sorcery, and set everything so that sorcery works
in the chroot too.

Usage is simple:

1) edit jail_params

2) run jail_create (best as a regular user)

3) run as root what previous step tells you at the end :)

4) you are in chroot now, run /root/jail_setup_inside to prepare sorcery

all done

Happy hacking, comments welcomed

--
	Neuron
-------------- next part --------------
# Where the jail will be created
ROOT=/home/neuron/chroot

# Where _ALLREADY EXISTING_ precompiled binaries will be mounted
# If you put it into /var/cache/sorcery, sorcery will use them, but might also overwrite
CACHE=/var/cache/sorcery
#CACHE=/binaries

# Where _ALLREADY EXISTING_ sources will be mounted
# If you put it into /var/spool/sorcery, sorcery will use them, but might also overwrite
# CACHE=/var/cache/sorcery
SPOOL=/var/spool/sorcery
#SPOOL=/sources

# Packages needed to be able enter chroot
BASIC_PACKAGES='glibc glibc-kernel-headers bash ncurses gettext readline coreutils tar bzip2 gzip'

# Packages needed for sorcery to work
# net-tools only neccessary if you plan to download sources from net
OTHER_PACKAGES='tar bzip2 gzip findutils sed dialog grep gcc less util-linux wget gawk make file patch zlib binutils net-tools'
-------------- next part --------------
#!/bin/bash

. jail_params
. /etc/sorcery/config

function unpack_cached_spell () {
	for SPELL in "$@"; do
		run_details
		FILE="$INSTALL_CACHE/$SPELL-$VERSION-$BUILD.tar$EXTENSION"
		[ ! -e "$FILE" ] && echo "Can't locate $FILE" && exit 1
		echo
		echo echo $SPELL ...
		tar xjf $FILE
	done
}

[ -d $ROOT ] && echo "$ROOT allready exists" && exit
mkdir $ROOT
cd $ROOT

unpack_cached_spell $BASIC_PACKAGES

cp /etc/ld.so.conf etc/
cp /etc/passwd etc/
cp /etc/group etc/
cp /etc/resolv.conf etc/

mkdir -p dev
mkdir -p tpm
mkdir -p root
mkdir -p proc
mkdir -p $ROOT/$CACHE
mkdir -p $ROOT/$SPOOL

function ls_cached_spell {
	for SPELL in "$@"; do
		run_details
		FILE="$INSTALL_CACHE/$SPELL-$VERSION-$BUILD.tar$EXTENSION"
		[ ! -e "$FILE" ] && echo "Can't locate $FILE" && exit 1
		echo echo $SPELL ...
		echo "tar xjf \$CACHE/$SPELL-$VERSION-$BUILD.tar$EXTENSION -P"
	done
}

function prepare_setup {
	echo CACHE=$CACHE
	echo SPOOL=$SPOOL
	echo
	ls_cached_spell $BASIC_PACKAGES
	echo
	ls_cached_spell $OTHER_PACKAGES
	echo
	echo ldconfig
	echo
	echo cd /root
	echo tar xjf \$SPOOL/sorcery-devel.tar.bz2
	echo cd sorcery
	echo ./install
}

prepare_setup > root/jail_setup_inside

echo; echo; echo Run as root:; echo

echo mount --bind /var/cache/sorcery $ROOT$CACHE
echo mount --bind /var/spool/sorcery $ROOT$SPOOL
echo mount --bind /dev $ROOT/dev
echo mount --bind /proc $ROOT/proc
echo chroot $ROOT /sbin/ldconfig
echo 'PS1="CHROOT \$(pwd):"' chroot $ROOT /bin/bash

#vim
-------------- next part --------------
. jail_params

[ ! -d $ROOT ] && echo "$ROOT does not exist" && exit

umount $ROOT/$CACHE
umount $ROOT/$SPOOL
umount $ROOT/dev
umount $ROOT/proc

echo
echo Now do:
echo rm -rf $ROOT
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.ibiblio.org/pipermail/sm-discuss/attachments/20040514/2d3462f6/attachment.bin 


More information about the SM-Discuss mailing list