Dear UML people

Opensuse 10.3 plays quite nicely with UML. Here is a HOWTO for configuring a 
fairly standard opensuse 10.3 root filesystem from the YaST install option 
'install into a directory' which creates an unconfigured a root filesystem 
tree. The crib sheet below gives commands to configure that tree sufficiently 
to boot the UML kernel.

Send any feedback directly to me because I'm not on the list.

Cheers
Ian

# This tells how to set up a UML root filesystem on an opensuse 10.3
# host, and how to run it in a DMZ behind the host machine's firewall.
# It can be used for running web servers etc.

# Before you start you will need:
#
# A host machine running opensuse 10.3 with at least 10GB of free disk
# Access to the Internet
# Access to a repository of the OSS RPMs for opensuse 10.3 
# A *bourne* shell on your host machine.

# The process is configured with shell variables.

# You will almost certainly need to change these:

# BUILD  is a directory with about 4G of free space for filesystem images etc.
# UMLUSR/UMLGRP is the user/group who will be running the UML kernel process
# RPMSRC is a mounted OSS repository for $ARCH from which RPMs are available
# DNS[12] are the name servers on your network
# DOMAIN is your domain
# ROOTPWCRYPT is some blowfish crypt for a root password
# BASEURL is a pointer to a repository with oss, non-oss and update dirs
#         You only need this after you boot the UML kernel

BUILD=/tmp/UML
UMLUSR=yourlogin
UMLGRP=yourlogin
RPMSRC=/some/place/with/suse-10.3/oss/$ARCH/suse/$ARCH
DNS1=nnn.nnn.nnn.nnn
DNS2=nnn.nnn.nnn.nnn
DOMAIN=some.place.com
ROOTPWCRYPT='$2a$10$XK0FuFfLhYujzWPfQafGPeCAakptcLxCMxnGkcE8hHaDIGxpumYeu'
# This is blank password: just hit return. Change it to something better.

# You may want to change these:

# SUSEVER is the version of opensuse
# VAR is a tag for the type of root filesystem. You may want several, each with
#      different selections of packages for different sorts of tasks
# KVER is the UML kernel version, this should be the latest stock kernel
# ARCH is the machine architecture of the host system (the UML kernel must have
#      the same architecture.)
# FSSIZE is the size of the root filesystem in MB
# SWAPSIZE is the size of the swap space
# PRIVNET is the first three octets in the address of a private class C network
#         So make it 192.168.xxx where you get to choose xxx
# UMLGUESTIP is the IP address of the UML virtual machine on the private net
# UMLHOSTIP is the IP address of the host machine on the private net
# HOSTDEV is the network interface on the host

SUSEVER=10.3
VAR=www-net
KVER=2.6.24
ARCH=x86_64
FSSIZE=4096
SWAPSIZE=512

PRIVNET=192.168.125
UMLGUESTIP=$PRIVNET.16
UMLHOSTIP=$PRIVNET.1
HOSTDEV=eth0

# You shouldn't need to change these
ONEMB=$((1024 * 1024))
ROOTIMG=suse-$SUSEVER-$ARCH-rootfs-$VAR.img
SWAPIMG=swap.img
ROOTTREE=suse-$SUSEVER-$ARCH-$VAR
UMKERNEL=um-linux-$KVER-$(uname -m)

cd $BUILD

echo Done.

# Don't copy this next command. It just enables one to source this file to set
# the variables in a shell, but the other commands below must be manually
# copied and pasted because some require interaction (and all require
# attention.)
cat > /dev/null <<'EOF'

# Save this file as ~/UML 

# On your opensuse 10.3 machine open a wide xterm (at least 200 characters)
# and load this file into less or a text editor.

# In another terminal, start a bash shell, if you haven't already got one
# running, and type

    . ~/UML

# or if that's a bit scary just copy-and-paste the lines above into the
# command shell.

# Then  ...

# Build uml_utilities
wget http://user-mode-linux.sourceforge.net/uml_utilities_20070815.tar.bz2
tar xjf uml_utilities_20070815.tar.bz2
cd tools-20070815
patch -p1 <<EOT
--- tools-20070815/umlfs/uml_mount.c.orig       2008-04-04 13:26:14.000000000 
+0100
+++ tools-20070815/umlfs/uml_mount.c    2008-04-04 13:26:33.000000000 +0100
@@ -1,3 +1,4 @@
+#define FUSE_USE_VERSION 25
 #include <fuse/fuse_lowlevel.h>
 #include <stdio.h>
 #include <stdlib.h>
EOT
patch -p1 <<'EOT'
--- tools-20070815/Makefile.orig        2008-04-04 13:30:34.000000000 +0100
+++ tools-20070815/Makefile     2008-04-04 13:31:19.000000000 +0100
@@ -4,12 +4,12 @@
        uml_net uml_switch watchdog umlfs
 UMLVER = $(shell date +%Y%m%d)
 TARBALL = uml_utilities_$(UMLVER).tar.bz2
-BIN_DIR = /usr/bin
+BIN_DIR = /usr/local/bin
 
 ifeq ($(shell uname -m),x86_64)
-LIB_DIR = /usr/lib64/uml
+LIB_DIR = /usr/local/lib64/uml
 else
-LIB_DIR = /usr/lib/uml
+LIB_DIR = /usr/local/lib/uml
 endif
 
 CFLAGS = -g -Wall
EOT
make
sudo make install
sudo ln -s /usr/local/lib64/uml/port-helper /usr/local/bin/

# Build a UML kernel

cd $BUILD
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-$KVER.tar.bz2
test -d linux-$KVER && rm -rf linux-$KVER
tar xjf linux-$KVER.tar.bz2
cd linux-$KVER
unset CDPATH
make defconfig ARCH=um
# Enable host filesystem support under UML options
make menuconfig ARCH=um
make ARCH=um
cd $BUILD
cp $BUILD/linux-$KVER/linux ./$UMKERNEL

# If you need to go back and rebuild the kernel with different config, run
#    make mrproper
#    make mrproper ARCH=um
# then start again at 'unset CDPATH'

# Now run yast2 on your host and do a 'install into directory'
# install into $ROOTTREE
echo Now do a directory install into $ROOTTREE
read junk

# Create a swap file (not sparse)
dd if=/dev/zero of=$SWAPIMG bs=$ONEMB count=$SWAPSIZE
mkswap $SWAPIMG

# Make a root filesystem in an image
dd if=/dev/zero of=$ROOTIMG bs=$ONEMB count=0 seek=$FSSIZE
mke2fs -j -F $ROOTIMG
mkdir -p $BUILD/mnt
sudo mount -o loop,rw $ROOTIMG $BUILD/mnt
sudo cp -a $ROOTTREE/* $BUILD/mnt

# Now configure it:

sudo sh -c "cat > $BUILD/mnt/etc/fstab" <<EOT
/dev/ubd/0      /                  ext3     defaults 1 1
proc            /proc              proc     defaults 0 0
sysfs           /sys               sysfs    noauto                0 0
debugfs         /sys/kernel/debug  debugfs  noauto                0 0
usbfs           /proc/bus/usb      usbfs    noauto                0 0
devpts          /dev/pts           devpts   mode=0622             0 0
/dev/ubdb       swap               swap     defaults              0 0
EOT

BOOTCONF=$BUILD/mnt/etc/sysconfig/boot
sudo cp $BOOTCONF $BOOTCONF.orig
sudo sh -c "sed -e '/^RUN_PARALLEL/ s/yes/no/' $BOOTCONF.orig > $BOOTCONF"

# Create modules.dep
sudo mkdir -p $BUILD/mnt/lib/modules/$KVER
sudo touch $BUILD/mnt/lib/modules/$KVER/modules.dep

# Fix root password
SHADOW=$BUILD/mnt/etc/shadow
sudo mv  $SHADOW  $SHADOW.old
sudo sh -c "cat > $SHADOW" <<EOT
root:$ROOTPWCRYPT:13976::::::
EOT
sudo sh -c "grep -v '^root' $SHADOW.old >> $SHADOW"
sudo chown root.shadow $SHADOW
sudo chmod 640 $SHADOW
sudo rm $SHADOW.old

# We don't update the hardware clock
sudo rm $BUILD/mnt/sbin/hwclock
sudo ln -s /bin/true $BUILD/mnt/sbin/hwclock

# Turn off auditd: it doesn't start (FIXME)
sudo rm $BUILD/mnt/etc/init.d/rc3.d/*auditd

# Install some useful RPMs and remove some others
sudo rpm --root $BUILD/mnt -ivh $RPMSRC/iputils-ss021109-233.$ARCH.rpm 
sudo rpm --root $BUILD/mnt -ivh $RPMSRC/psmisc-22.5-30.$ARCH.rpm

# The 'install into directory' option seems a bit erratic in its choice of
# packages, you probably don't have these, but I do, so I remove them:
sudo rpm --root $BUILD/mnt -e x11-video-fglrxG01-8.45.5-1.1.$ARCH \
                              ati-fglrxG01-kmp-default

# Remove the kernel if you like (you get a few grumbles though)
sudo rpm --root $BUILD/mnt -e kernel-default

# Configure the network
sudo sh -c "cat > $BUILD/mnt/etc/resolv.conf" <<EOT
nameserver $DNS1
nameserver $DNS2
search $DOMAIN
EOT

sudo sh -c "cat > $BUILD/mnt/etc/sysconfig/network/ifcfg-eth0" <<EOT
DEVICE=eth0
STARTMODE=onboot
IPADDR=$PRIVNET.16
BROADCAST=$PRIVNET.255
GATEWAY=$PRIVNET.1
NETMASK=255.255.255.0
NETWORK=$PRIVNET.0
USERCONTROL=no
FIREWALL=no
EOT

sudo sh -c "cat >> $BUILD/mnt/etc/hosts" << EOT
$PRIVNET.16 linux.localnet linux
EOT

sudo sh -c "cat >> $BUILD/mnt/etc/sysconfig/network/routes" << EOT
default $PRIVNET.1 - - 
EOT

# Unmount it
sudo umount $BUILD/mnt

# On HOST, Add UMLUSR to trusted group
sudo groupmod -A $UMLUSR trusted

sudo -v
sudo modprobe tun
TAP=$(sudo tunctl -u $UMLUSR -b)
sudo ifconfig $TAP $UMLHOSTIP up
sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
sudo route add -host $UMLGUESTIP dev $TAP
sudo bash -c "echo 1 > /proc/sys/net/ipv4/conf/$TAP/proxy_arp"
sudo arp -Ds $UMLGUESTIP $HOSTDEV pub
sudo chgrp trusted /dev/net/tun
sudo chmod 664 /dev/net/tun

# Then add $TAP to the DMZ in the yast2 firewall settings on the host,
# also enable masquerading. Allow HTTP to DMZ. Redirect host port 80
# to $UMLGUESTIP port 80 

# As user, start the UML process

./$UMKERNEL eth0=tuntap,${TAP:-tap0} ubda=$ROOTIMG ubdb=$SWAPIMG \
  mem=256M con0=fd:0,fd:1 con=pts ssl=null

# To access your terminals use GNU screen, e.g.
screen -t 'UML Host VC 0' /dev/pts/6

# Or you can ssh into your UML kernel
ssh [EMAIL PROTECTED]

# Log in as root

# First use 'zypper sl' and 'zypper sd' to remove all repositories.

# Then add these:
# BASEURL is a pointer to a repository with oss, non-oss and update dirs
BASEURL=http://www.mirrorservice.org/sites/ftp.opensuse.org/pub/opensuse/distribution/
zypper sa $BASEURL/10.3/repo/oss uxsup-10.3-oss
zypper sa $BASEURL/10.3/repo/non-oss uxsup-10.3-non-oss
zypper sa $BASEURL/update/10.3 uxsup-10.3-update

# Do an online-update:
zypper up

# Turn on apache2
chkconfig --add apache2

# Create a web page in /srv/www/html/index.html
cat > /srv/www/htdocs/index.html << EOHTML
<html>
<head><title>Test Page</title></head>
<body>
<h1>Test Page</h1>
<p>It works.
</body>
</html>
EOHTML

# Start apache
/usr/sbin/rcapache2 start


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
User-mode-linux-user mailing list
User-mode-linux-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-user

Reply via email to