logo       

Re: [uml-user] /dev/udb/0 mounting problem: msg#00236

Subject: Re: [uml-user] /dev/udb/0 mounting problem
Luke,

you might try building your own file system, that's what I eventually ended up doing.

I used a script from the LFS UML HowTo, and modified it heavily to get it to work with my UML version.

I have included it down below. Since I started with Mandrake, and built for a 2.6.0-test kernel you may expect to do several iterations of editing the script, and building before you get the script right for your distribution.

Galea, Luke wrote:

Hi all,

I've racked my brain all day on this. I'm running debian 3.0 with a custom
built 2.4.18 kernel.

I didn't build with devfs.. Nor tunnelling or ethertap :(

So I have a few probs: I have tried 4 different rootfs and they all freak
out saying they can't mount /dev/udb/0.. Editing fsb gets me by but then I
hit the whole 'process spawning too quickly' problem..

What am I doing wrong? Why are all the filesystems I download bad? And
because I forgot to include tunneling in the kernel am I screwed? Or can I
build just that one module now?

Thx!!

Script follows

--------------------------------- snip from following line -------------------------------------
#!/bin/bash -e
# note the "-e" above - it means exit script on any error.
# @(#) $Id: uml.txt,v 1.12 2002/05/01 13:54:08 ian Exp $
echo
echo "brfs - root filesystem build script - PW"
echo

PATH=/sbin:/bin:/usr/sbin:/usr/bin
# build_rootfs - create a basic root filesystem for user mode linux
# uses BSD style init scripts.  (nice and simple).

command=${0##.*/}

# root has to run build_rootfs to execute losetup environment.
if    [[ $UID != 0 ]]
then    echo "root has to run $command for losetup" >&2
   exit 1
fi

# $uml is where root_fs will be temporarily mounted while
# it is built.  $uml_root will get blown away by this script.
uml_root=/mnt/uml

# loopback block device - $loop will be mounted on $uml_root
loop=/dev/loop0

# cleanup if build_rootfs bombed in a previous run.
if    mount|grep $uml_root >/dev/null
then    umount $uml_root
   losetup -d $loop
fi

# uml_dest is the directory the uml root filesystem will be built in.
uml_dest=/usr/src/uml


# root_fs is the default name, if you change it, you'll have to
# pass an option to uml with the rootfs name.
root_fs=root_fs
# if user is set, the script will su to $user and boot uml at the end
# of build_rootfs
export user=

# size of filesystem in megs
megs=200

# hostname for uml
uml_hostname=uml
# uml_tun_ip is the address you want the uml machine to have.
uml_tun_ip="192.168.0.250"
# interface address of tap0 (interface to uml) - becomes uml defaultroute.
# this should not be the same as eth0 or ppp0.
host_tun_ip="192.168.0.230"

# hostfs lets you mount host filesystem under uml
host=$(hostname)

# set hostfs to true to mount host / on /mnt/$host and
# host /usr/src under /mnt/$host/usr/src
hostfs=true

# set devel=true if you want compilers and header files.
devel=true

# command to create filesystem --format 3.6 needed for
# reiserfsprogs 3.x.0k-pre14 on linux-2.5.x host, to get
# the --format option for mkreiserfs.
mkfs="mkreiserfs --format 3.6"
#mkfs="mkreiserfs"

# set network_server=true if you want uml network server commands
network_server=true

function usage {
echo "usage: $command [ -d /path/to/uml/dest ] [ -f ] [ -g ] [ -h uml_hostname ]" echo " [ -i uml_ipaddress ] [ -m megs ] [ -n ] [ -s ] [ -r /path/to/uml_root ]"
   echo "    [ -u /path/to/uml/patch.bz2 ] [ -v ]" >&2
   echo
   echo "example: $command -d/usr/src/uml -f -h myuml -i 192.168.0.222 \\"
   echo "    -m 500 -r/mnt/uml2 >&2"
   echo
   echo "options                    defaults" >&2
   echo " d    destination for uml tree    $uml_dest" >&2
   echo " f    use hostfs            $hostfs" >&2
   echo " g    add development files        $devel" >&2
   echo " h    uml hostname            $uml_hostname" >&2
   echo " i    uml ip address            $uml_tun_ip" >&2
   echo " m    rootfs size in MB        $megs" >&2
   echo " n    network server            $network_server" >&2
   echo " r    uml root for build        $uml_root" >&2
   echo " s    silent make            true" >&2
   echo "" >&2
   exit 1
}


# options
# d     destination for uml tree
# s     silent make
# t     tar uncompress option
# u     user-mode-linux patch
# v     verbose
while getopts :d:fgh:i:m:ns arg
do
       case $arg in
               d)      uml_dest=$OPTARG;;
               f)      hostfs=true;;
       g)    devel=false;;    # guru
               h)      uml_hostname=$OPTARG;;
               i)      uml_tun_ip=$OPTARG;;
       m)    megs=$OPTARG;;    # number
       n)    network_server=false;;
               r)      uml_root=$OPTARG;;
               s)      make_opt=-s;;
               \?)     echo "$command: Invalid switch $OPTARG" >&2
                       usage;;
               *)      usage;;
       esac
done

# list of daemons in /usr/sbin that you want if network_server=true
network_usr_sbin_daemons="inetd in.telnetd in.rlogind in.ftpd tcpd"

# commands to grab from /usr/bin on host machine
usr_bin="awk basename bc cal chroot cksum clear cmp col cut dc diff dirname ed egrep ex expr file find fmt fold free ftp fuser gawk getconf grep head id join last ldd nohup od passwd paste perl pkill procinfo reset setterm sleep sort split ssh ssh-keygen strace strings tail tee test time top tput tr tset tty uptime vi
vim vmstat xargs w wc who"

# these might help figuring out <ctrl c \>
key_cmds="dumpkeys  getkeycodes  setkeycodes  showkey"

usr_bin="$usr_bin $key_cmds"

# eliminate any files that haven't been installed
for f in $usr_bin
do    [ -f /usr/bin/$f ] && ub="$ub $f"
done
usr_bin="$ub"

# readprofile requires System.map
usr_sbin="klogd readprofile sshd syslogd tcpdump xinetd"
# eliminate any files that haven't been installed
for f in $usr_sbin
do    [ -f /usr/sbin/$f ] && us="$us $f"
done
usr_sbin="$us"

# /usr/bin commands included if $devel is true
usr_bin_dev="ar as as86 as86_encap autoconf autoexpect autoheader automake
autoreconf autoscan autoupdate bison c++ c++filt cc cpp cut find flex flex++ g++ gasp gcc gdb ld ld86 m4 make nm nm86 objcopy objdump objdump86 patch perl ranlib reset size
size86 strip vi "
# eliminate any files that haven't been installed
for f in $usr_bin_dev
do    [ -f /usr/bin/$f ] && ud="$ud $f"
done
usr_bin_dev="$ud"

# set v=v for verbose build
v=""

# argument to make ARCH=um install_modules quiet
silent_make="-s"

########### end of configuration setup ##############

# host system will need a tap interface
if    [[ ! -c /dev/tap0 ]]
then mknod /dev/tap0 c 36 16 fi

cd $uml_dest/linux

# use /dev/zero for building a file full of 00000000's
if    [[ ! -c /dev/zero ]]
then    mknod --mode 0644 /dev/zero c 1 5
fi

# create root_fs
rm -f $root_fs
dd if=/dev/zero of=$root_fs seek=$megs count=1 bs=1M

# loopback setup
losetup $loop $uml_dest/linux/$root_fs

# take the defaults creating reiserfs
yes | $mkfs $loop

mkdir -p $uml_root

# mount the loopback reiserfs file
mount -t reiserfs $loop $uml_root

# main user
export user=<your user name>

cd $uml_root
# create directory structure and copy /lib /sbin /dev into rootfs
mkdir -p bin dev etc/{rc.d,pam.d} lib/{security} mnt proc root sbin tmp usr/{bin,sbin,src} var/{log,run,tmp} home/$user
chmod 1777 tmp var/tmp
chown $user:$user home/$user
user_files=".bashrc .bash_profile .bash_history .bash_logout .viminfo"

# make a home directory for user
cd /home/$user
echo -en "/home/$user\t\t\t\t\t"
find $user_files -print|cpio -pdm $uml_root/home/$user

# duplicate the dev directory of the host system
cd /dev
echo -en "/dev\t\t\t\t\t"
find . -print|cpio -pdm $uml_root/dev
cd $uml_root/dev
# create ttyp (slave) and ptyp (master) for console if necessary.
i=0
while ((i <= 8))
do    [[ ! -c ptyp$i ]] && mknod --mode=644 ptyp$i c 2 $i
   [[ ! -c ttyp$i ]] && mknod --mode=644 ttyp$i c 3 $i
   ((i++))
done

# # put everything in /sbin /bin and /lib on uml root_fs
# copy everything in /sbin and /bin on uml root_fs
cd /sbin
echo -en "/sbin\t\t\t\t\t"
find . -print|cpio -pdm $uml_root/sbin
sleep 1
cd /bin
echo -en "/bin\t\t\t\t\t"
find . -print|cpio -pdm $uml_root/bin

# grab some goodies from /usr/bin and /usr/sbin
cd /usr/bin
echo -en "/usr/bin\t\t\t\t"
find $usr_bin|cpio -pdm $uml_root/usr/bin
cd /usr/sbin
echo -en "/usr/sbin\t\t\t\t"
find $usr_sbin|cpio -pdm $uml_root/usr/sbin

# grab PAM modules
cd /lib/security
echo -en "/lib/security\t\t\t\t"
find .|cpio -pdm $uml_root/lib/security
cd /etc/pam.d
echo -en "/etc/pam.d\t\t\t\t"
find .|cpio -pdm $uml_root/etc/pam.d

# maybe this will make <ctrl c> work for /dev/console (nope)
cd /usr
#echo -en "/usr/share/kbd\t\t\t\t"
#find share/kbd|cpio -pdm $uml_root/usr
echo -en "/usr/share/misc/magic\t\t\t"
find share/misc/magic*|cpio -pdm $uml_root/usr

# grab linux terminfo and keyboard files
mkdir -p $uml_root/usr/share/terminfo/l
[[ -f /usr/share/terminfo/l/linux ]] && cp -p /usr/share/terminfo/l/linux $uml_root/usr/share/terminfo/l

# development support files
if    [[ $devel == true ]]
then    echo "Including files for development"
   cd /usr/bin
   echo -en "Development commands\t\t\t"
   find $usr_bin_dev|cpio -pdmL $uml_root/usr/bin
   # gcc libs
   cd /usr/lib
   echo -en "/usr/lib/gcc-lib\t\t\t"
   find gcc-lib *crt*.o|cpio -pdm $uml_root/usr/lib
   # /usr/$MACHTYPE has some support files for binutils.
   # get header files too
   cd /usr
   echo -en "/usr/include\t\t\t\t"
   find include $MACHTYPE|cpio -pudm $uml_root/usr
fi

# networking
if    [[ $network_server == true ]]
then    cd /usr/sbin
   for f in $network_usr_sbin_daemons
   do    if    [[ -f $f ]]
       then    cp -${v}p $f ${uml_root}/usr/sbin/${f}
           chmod +x ${uml}${f}
       fi
   done
   cd -
fi

# Run ldd on everything to figure out what libs we need.
cd $uml_root
echo -en "Libraries\t\t\t\t"
libs=$(ldd sbin/* bin/* usr/sbin/* usr/bin/* 2>/dev/null|
awk '/=>/ {print $3}'|egrep -v '^/lib|perl5/'|sort -u|
sed -e 's:-.*:\*.so\*:' -e 's:\.*so.*:\*so\*:')
cd /
# grab all of /lib, other libs needed by commands, and /usr/lib/libc*
find lib/*so* $libs usr/lib/libc*|sed 's:^/::'|cpio -pudm $uml_root
if    [[ -f $uml_root/usr/bin/perl ]]
then    echo -en "Perl libs\t\t\t\t"
   find usr/lib/perl5|cpio -pdm $uml_root
fi
chmod +x $uml_root/*
# create an empty ld.so.conf for ldconfig
> $uml_root/etc/ld.so.conf
ldconfig -${v}r $uml_root
cd -

echo -en "/etc\t\t\t\t\t"
# some important things in /etc
[[ -f /etc/bashrc ]]        && cp -p /etc/bashrc $uml_root/etc
[[ -f /etc/hosts ]]        && cp -p /etc/hosts $uml_root/etc
[[ -f /etc/inetd.conf ]]    && cp -p /etc/inetd.conf $uml_root/etc
[[ -f /etc/inputrc ]]        && cp -p /etc/inputrc $uml_root/etc
[[ -f /etc/limits ]]        && cp -p /etc/limits $uml_root/etc
[[ -e /etc/localtime ]]        && cp -d /etc/localtime $uml_root/etc
[[ -f /etc/login.defs ]]    && cp -p /etc/login.defs $uml_root/etc
[[ -f /etc/nsswitch.conf ]]    && cp -p /etc/nsswitch.conf $uml_root/etc
[[ -f /etc/profile ]]        && cp -p /etc/profile $uml_root/etc
[[ -f /etc/protocols ]]        && cp -p /etc/protocols $uml_root/etc
[[ -f /etc/resolv.conf ]]    && cp -p /etc/resolv.conf $uml_root/etc
[[ -f /etc/securetty ]]        && cp -p /etc/securetty $uml_root/etc
[[ -f /etc/services ]]        && cp -p /etc/services $uml_root/etc
[[ -d /etc/ssh ]]        && cp -rp /etc/ssh $uml_root/etc
# UML host will need new host keys
rm -f $uml_root/etc/ssh/*key
[[ -f /etc/syslog.conf ]]    && cp -p /etc/syslog.conf $uml_root/etc

# instruct about login
echo "
Welcome to User-Mode-Linux
You can log into $uml_hostname with one of your normal accounts or root.
The passwords are the same as on $(hostname).
" > $uml_root/etc/issue

# Get passwd and shadow so we can login with the same accounts as the host
cp -p /etc/passwd /etc/shadow /etc/group $uml_root/etc


# basic fstab
cat<<!>$uml_root/etc/fstab
/dev/bd0    /        reiserfs    defaults    0 0
proc        /proc        proc        defaults    0 0
none        /dev/pts    devpts        defaults    0 0
!

# append hostfs to fstab if desired
if    [[ $hostfs == true ]]
then    cat<<-!>>$uml_root/etc/fstab
   none        /mnt/$host    hostfs        defaults    0 0
   none        /mnt/$host/usr/src    hostfs        /usr/src    0 0
   !
   mkdir -p $uml_root/mnt/$host/usr/src
fi

# inittab for uml
cat <<!>$uml_root/etc/inittab
# user-mode-linux inittab
id:3:initdefault:
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc.0
l1:S1:wait:/etc/rc.d/rc.1
l2:2:wait:/etc/rc.d/rc.2
l3:3:wait:/etc/rc.d/rc.3
l4:4:wait:/etc/rc.d/rc.4
l5:5:wait:/etc/rc.d/rc.5
l6:6:wait:/etc/rc.d/rc.6
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
su:S016:wait:/sbin/sulogin
c1:23:respawn:/sbin/agetty console 38400 linux
!

# startup/rc scripts
#mkdir $uml_root/etc/rc.d

# Create rc.sysinit for uml.
cat<<!>$uml_root/etc/rc.d/rc.sysinit
#!/bin/sh
# begin of /etc/rc.d/rc.sysinit

# Mount root device ro.
/bin/mount -n -o remount,ro /

# Mount swap partitions.
/sbin/swapon -a

# Remount root device rw.
/bin/mount -n -v -o remount,rw /

echo "" > /etc/mtab
/bin/mount -f -o remount,rw /

# Mount special filesystems
/bin/mount /proc
/bin/mount /dev/pts

# Initialize loopback network interface.
/sbin/ifconfig lo 127.0.0.1

# Set hostname.
/bin/hostname -v $uml_hostname

# Recreate the utmp file so w/who are correct.
rm -f /var/run/utmp
touch /var/run/utmp
chmod 0644 /var/run/utmp

# end of /etc/rc.d/rc.sysinit
!

# Create rc.0 for uml.
cat <<!>$uml_root/etc/rc.d/rc.0
#!/bin/sh
# /etc/rc.d/rc.0
# Sending TERM signal to all processes.
/sbin/killall5 -15

# Sending KILL signal to all processes.
/sbin/killall5 -9

# Unmounting swap partitions.
/sbin/swapoff -a

# put marker in messages
case "\$0" in
       *6)
         /sbin/reboot -w
         ;;
       *0)
         /sbin/halt -w
         ;;
esac

/bin/sync

# Remount root filesystem ro.
/bin/mount -n -o remount,ro /

# Unmount other filesystems
/bin/umount -a

case "\$0" in
       *6)
         /sbin/reboot -d -f -i
         ;;
       *0)
         /sbin/halt -d -f -p
         ;;
esac
# end of /etc/rc.d/rc.0
!
# end of here doc for /etc/rc.d/rc.0

# Create rc.1 for uml.
cat<<!>$uml_root/etc/rc.d/rc.1
#!/bin/sh
# /etc/rc.d/rc.1

# Send TERM signal to all processes.
/sbin/killall5 -15

# Send KILL signal to all processes.
/sbin/killall5 -9

# Disable eth0.
/sbin/ifconfig eth0 down

# end of /etc/rc.d/rc.1
!
# end of here document for /etc/rc.d/rc.1

# Create rc.2 for uml
cat<<!>$uml_root/etc/rc.d/rc.2
#!/bin/sh
# /etc/rc.d/rc.2

echo "Cleaning /tmp"
/bin/rm -rf /tmp
/bin/mkdir --mode=1777 /tmp

# don't put MARK in syslog every 20 minutes
/usr/sbin/syslogd -m0

# -c set console log level to 3 (warning?)
# -x Omits EIP translation and therefore doesn't read the System.map file.
#    Suggestion from Keith Owens on lkml on 10/31/2001.
#/usr/sbin/klogd -c3 -x -k /boot/System.map-`uname -r`
/usr/sbin/klogd -c3 -x

# load default keymap
#/bin/loadkeys -d

# Initialize uml eth0.
/sbin/ifconfig eth0 $uml_tun_ip up
/sbin/route add default gw $host_tun_ip

# Starting inetd server.
if    [[ -r /etc/inetd.conf ]] && [[ -x /usr/sbin/inetd ]]
then    /usr/sbin/inetd
fi

if    [[ -x /usr/sbin/sshd ]]
then    if    [ -d /etc/ssh ]
   then    if    [ -f /etc/ssh/ssh_host_key ]
       then    echo "/etc/ssh/ssh_host_key already exists, skipping."
       else    ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N ""
       fi
       if    [ -f /etc/ssh/ssh_host_dsa_key ]
       then    echo "/etc/ssh/ssh_host_dsa_key already exists, skipping."
       else    ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ""
       fi
       if    [ -f /etc/ssh/ssh_host_rsa_key ]
       then    echo "/etc/ssh/ssh_host_rsa_key already exists, skipping."
       else    ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ""
       fi
   fi
   /usr/sbin/sshd
fi

# Mount other filesystems
/bin/mount -a
# end of /etc/rc.d/rc.1
!

# links for rc scripts
cd $uml_root/etc/rc.d
ln -s rc.2 rc.3
ln -s rc.2 rc.4
ln -s rc.2 rc.5
ln -s rc.0 rc.6

# permissions for rc scripts
cd $uml_root/etc/rc.d
chmod 754 rc.[0-2]
chmod 754 rc.sysinit

# done with /etc
echo "done"

# install modules from uml kernel
echo -en "Installing kernel modules\t\t"
cd $uml_dest/linux
make $silent_make modules_install INSTALL_MOD_PATH=$uml_root ARCH=um
echo "done"

# basic .bash_profile for root.
cd $uml_root/root
cat<<EOF>.bash_profile
export PATH="\$PATH:/sbin:/usr/sbin"
set -o vi
alias l="ls -l"
EOF


cd /
sync
echo "umounting $uml_root"
umount $uml_root
echo "detaching $loop"
losetup -d $loop

if    ! grep -q $user /etc/passwd
then echo "change user=$user at the top of $0 to whatever your login name is"
else    chown $user:root $uml_dest/linux/$root_fs
fi

# load tun driver on host system - only necessar.
if [[ -f /lib/modules/`uname -r`/kernel/drivers/net/tun.o ]] && ! modprobe tun
then    insmod tun
fi

cd $uml_dest/linux
# boot uml if user was specified in script.
if    [[ $user != "" ]]
then    # boot up
   echo -e "\nBooting uml!\n"
su - $user -c "cd $uml_dest/linux&&./linux root=/dev/ubd/0 ubd0=$root_fs eth0=tuntap,,,$host_tun_ip umid=$uml_hostname"
else    echo "Your uml $root_fs is in $uml_dest"
   echo "boot uml as a non-root user with a command like:"
echo "cd $uml_dest/linux && ./linux rootfs=$root_fs eth0=tuntap,,,$host_tun_ip umid=$uml_hostname"
fi
# use the line below for no networking, and no init.  It may be useful
# for troubleshooting.
#su - $user -c "cd $uml_dest/linux&&./linux rootfs=$root_fs init=/bin/bash"
# end of build_root_fs

-------------------------- end of script -----------------------------------------------------------

--
Paul Wujek





-------------------------------------------------------
This SF.net email is sponsored by OSDN developer relations
Here's your chance to show off your extensive product knowledge
We want to know what you know. Tell us and you have a chance to win $100
http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54


<Prev in Thread] Current Thread [Next in Thread>