Friday, July 23, 2010

how to create uml file system

this is the only way I found working on Ubuntu 10.04 32bit, the original link is:
http://web2.clarkson.edu/class/cs644/kernel/setup/uml/uml.html


Creating your filesystem

Debian is suprisingly simple to install inside of user mode linux. To begin you must initialize the files using dd. This example assumes that your image files are /opt/uml/debian-root.

Example 5. Creating your filesystem

 #dd if=/dev/zero of=/opt/uml/debian-root bs=1024K count=1000

Now we will initialize the filesystems inside of each of these files. We will be using ext3 as our root filesystem.

Example 6. Initializing the filesystems

 #mkfs.ext3 /opt/uml/debian-root

Now we will need to mount the root filesystem before we run debootstrap.

Example 7. Mounting root

 #mkdir /mnt/debian
#mount -o loop /opt/uml/debian-root /mnt/debian

Now we will install debootstrap and bootstrap a base Debian installation. This is a barebones installation that is less than 200 megs.

Example 8. Debian Installation

 #apt-get install debootstrap
#debootstrap --arch i386 sarge /mnt/debian http://ftp.us.debian.org/debian

or you may want to use the breezy installation.

#debootstrap --arch i386 breezy /mnt/debian http://archive.ubuntulinux.org/ubuntu

At this point your system is an unconfigured base system. You will need to edit the following files in order to have your system in a valid configuration.

  • /etc/fstab

  • /etc/hostname

  • /etc/hosts

  • /etc/network/interfaces

  • /etc/apt/sources.list

  • /etc/securetty

  • /etc/inittab

Example 9. FSTAB configuration

 /dev/ubd0 / ext3 defaults 0 1
proc /proc proc defaults 0 0

Example 10. Host configuration

You will need to make sure that /etc/hostname contains the following line or your nameing preference.

 uml-one

You will need to make sure that /etc/hosts contains the following line.

 127.0.0.1 localhost

At this point you will need to setup your network interface configuration. This is done by editing the file /etc/network/interfaces. This guest will have a loopback network device. More information on configuring network devices under Debian can be found in the Debian Reference.

Example 11. The loopback network interface

 auto lo
iface lo inet loopback

The above should be in the file /etc/network/interfaces. You'll also need to add a mirror or cdrom image to /etc/apt/sources.list

Example 12. /etc/securetty Configuration

 #echo "tty0" >> /etc/securetty
#echo "ttys/0" >> /etc/securetty

Example 13. /mnt/debian/dev

In the breezy debootstrap example no node was created for me to mount the file system too, you can check this by,

 #cd /mnt/debian/dev
#ls ubd*

If this does not return ubd0 then,

#mknod --mode=660 ubd0 b 98 0
#chown root:disk ubd0

Example 14. Edit /etc/inittab

This will allow you to login immediately after the boot messages

 Comment out the following lines:
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6

Now modify tty1 to say tty0, the result should look like this:
1:2345:respawn:/sbin/getty 38400 tty0
#2:23:respawn:/sbin/getty 38400 tty2
#3:23:respawn:/sbin/getty 38400 tty3
#4:23:respawn:/sbin/getty 38400 tty4
#5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6

Example 15. Add user to the file system

Before you can log into the file system you must add a user to be ablet logi in with.

 #chroot /mnt/debian
#adduser uml
Aswer the following questions about the new user or press enter followed by a yes at the end

Example 16. Run the kernel with UML

 #sudo umount /mnt/debian
#sudo ./linux ubd0=/opt/uml/debian-root

1 comment:

  1. why do we umount /mnt/debian before dong ./linux ubd0=/opt/uml/debian-root

    ReplyDelete