#!/bin/sh # # Toralf Förster # Hamburg # Germany # set -x while getopts r: opt do case $opt in r) UMLROOTFS=$OPTARG ;; *) echo "Usage : $(basename $0) -r " exit 1 ;; esac done ############################################################################# # if [[ ! -f $UMLROOTFS || ! -r $UMLROOTFS || ! -w $UMLROOTFS ]]; then echo "no r/w able root-fs $UMLROOTFS" exit 1 fi # we assume different file names for the images # NAME=$(basename $UMLROOTFS) if [[ "$(whoami)" != "root" ]]; then echo " You must be root !" exit 2 fi # load module if neccessary and sleep a sec # to give it time for initialization # if [[ -z "$(lsmod | grep "^loop ")" ]]; then modprobe loop && sleep 2 || exit 3 fi MNTPNT=/mnt/ramdisk/$NAME if [[ ! -d $MNTPNT ]]; then mkdir $MNTPNT || exit 1 fi # is this UML image already in use ? # mountpoint -q $MNTPNT if [[ $? -eq 0 ]]; then echo "$MNTPNT is already mounted" exit 5 fi # temp dir for emerging packages, the UML image itself doesn't have too much free disk space # TMPPORTAGE=/mnt/ramdisk/uml_portage_$NAME if [[ ! -d $TMPPORTAGE ]]; then mkdir $TMPPORTAGE sudo chown portage:portage $TMPPORTAGE fi ############################################################################# # mount -o loop $UMLROOTFS $MNTPNT mount -t proc none $MNTPNT/proc mount -o bind /dev $MNTPNT/dev mount -o bind /dev/pts $MNTPNT/dev/pts mount -o bind /sys $MNTPNT/sys mount -o bind /usr/portage $MNTPNT/usr/portage mount -o bind /usr/local/portage $MNTPNT/usr/local/portage mount -o bind $TMPPORTAGE $MNTPNT/var/tmp/portage chroot $MNTPNT /bin/bash -c "su -" RC=$? umount $MNTPNT/var/tmp/portage umount $MNTPNT/usr/local/portage umount $MNTPNT/usr/portage umount $MNTPNT/sys umount $MNTPNT/dev/pts umount $MNTPNT/dev umount $MNTPNT/proc umount $MNTPNT rmdir $TMPPORTAGE/._unmerge_/ 2>/dev/null rmdir $TMPPORTAGE rmdir $MNTPNT exit $RC