This is a simple shell script that gets perl to do the chroot and setuid in 'one' operation (its hard to do in the shell without copying in a load of stuff from the real root). It works for me, but YMMV !
#!/bin/bash

# configuration

USERID="rod";
GUESTIP=192.168.30.44
HOSTIP=192.168.30.41

# end of configuration

uid=`grep ^$USERID /etc/passwd | cut -f 3 -d:`
GID=`grep ^$USERID /etc/passwd | cut -f 4 -d:`

tun=`tunctl -u $UID -b`;
echo "Starting Network on tun=$tun"

# configure host side of tuntap networking

ifconfig $tun $HOSTIP netmask 255.255.255.255 up
echo 1 >/proc/sys/net/ipv4/ip_forward
route add -host $GUESTIP dev $tun
echo 1 >/proc/sys/net/ipv4/conf/$tun/proxy_arp
arp -Ds $GUESTIP eth0 pub

# todo - make sure the /tmp /proc /dev bits are created

echo "Starting UML."

# use perl to chroot & set userid, as this is an arse in shell

perl <<EOF
use POSIX;
chroot("/home/$USERID");
POSIX::setuid($uid);
POSIX::setgid($GID);

system("./linux", "ubd0=./$USERID-root", "ubd1=./$USERID-swap", "devfs=nomount","mem=200M", "con=null", "eth0=tuntap,$tun");
EOF

echo "UML Stopped, stopping network..."

# stop the network & release the tuntap thingy

arp -i eth0 -d $GUESTIP
route del -host $GUESTIP dev $tun
ifconfig $tun down
tunctl -d $tun

echo "Network stopped."


  Page Info My Prefs Log in
This page (revision-1) last changed on 09:40 03-Nov-2006 by Dave Pearson.
 

JSPWiki v2.4.71
[RSS]