http://jserv.sayya.org/kernel/uml/create-uml-rootfs

#!/bin/sh

BASE_DIR=`pwd`

# --- Modified as you need ---
TARGET_DIR=$BASE_DIR/ext2fs
ETC_SAMPLE=etc_sample.tar.bz2
ROOTFS_FILE=ubuntu-root

# Create rootfs (400Mb)
echo "Creating root file system..."
rm -f $ROOTFS_FILE
dd if=/dev/zero of=$ROOTFS_FILE bs=1024K count=400
if [ ! -f $ROOTFS_FILE ]; then
    echo "Error: creation of image file fails."
    exit
fi
yes y | mkfs.ext2 $ROOTFS_FILE
mkdir -p $TARGET_DIR
mount -o loop $ROOTFS_FILE $TARGET_DIR

# Make use of Debian's debootstrap tool to construct Ubuntu Dapper (6.10) base
echo "Invoking debootstrap..."
debootstrap --arch i386 dapper \
    $TARGET_DIR \
    http://archive.ubuntulinux.org/ubuntu

# Extract sample configure files
if [ -f $ETC_SAMPLE ]; then
    cd $TARGET_DIR
    tar jxvf $ETC_SAMPLE
    cd $BASE_DIR
fi

# mknod for ubd0 (specific to UML)
if [ -d $TARGET_DIR/dev ]; then
    cd $TARGET_DIR/dev
    mknod --mode=660 ubd0 b 98 0
    chown root:disk ubd0
    cd $BASE_DIR
else
    echo "Error: debootstrap fails."
    exit
fi

# Finish
sync
umount ext2fs
echo "Done"
echo "Please assign the rootfs: " $ROOTFS_FILE

Reply via email to