How-to: Create a Debian Filesystem Template for MLN
From SOFTICE
|
Developed by:
Synopsis
This page describes to to build an MLN filesystem template based on Debian's stable branch (etch). The filesystem built here is targeted for use in networking labs.
Dependencies
A computer running Linux with 300MB of available disk space. This page was written based on building the filesystem on a host computer running Debian's stable branch (sarge). The procedures may vary somewhat if the host computer is running another Linux variant.
Create and Mount a Filesystem Image
- Create an empty 300MB file. As of August 31, 2008, the finished filesystem takes up approximately 220MB of space, so this can be reduced if you wish.
dd if=/dev/zero of=debian.ext2 bs=1M count=300
- Make the file into an ext3 filesystem image.
mke2fs -F -j debian.ext2
- By default, the filesystem created above will have a fsck filesystem check run on it 180 days after creation. On COW filesystem, where the filesystem isn't actually written to, this would cause fsck to be run on every boot once the 180-day mark is reached. Run the following command to disable this behavior:
tune2fs -i 0 debian.ext2
- Create a directory to mount the filesystem to.
mkdir /mnt/debian
- Mount the filesystem image.
mount debian.ext2 /mnt/debian -o loop
Populate the Filesystem
- Install deboostrap.
apt-get install debootstrap
- Populate the filesystem image with a basic Debian installation.
debootstrap --arch i386 etch /mnt/debian http://ftp.us.debian.org/debian
Chroot
- If deboostrap was successful, you should now be able to set /mnt/debian as your root directory, and proceed with customizing the filesystem image:
chroot /mnt/debian
Make the Image Bootable
There are a few changes which must be made to insure that this filesystem image is bootable under MLN or User Mode Linux:
- Delete the /lib/tls directory:
rm -rf /lib/tls
- Populate the /etc/fstab file with filesystem information:
echo "# file system mount point type options dump pass" > /etc/fstab echo "/dev/ubd0 / ext2 noatime 0 0" >> /etc/fstab echo "proc /proc proc defaults 0 0" >> /etc/fstab
- Create ubd devices:
cd /dev for i in 0 1 2 3 4 5 6 7; do mknod ubd$i b 98 $[ $i * 16 ]; done
- Set the host name:
echo "uml" > /etc/hostname
- Add localhost to /etc/hosts:
echo "127.0.0.1 localhost" > /etc/hosts
- Configure lo - the loopback network interface:
echo "auto lo" > /etc/network/interfaces echo "iface lo inet loopback" >> /etc/network/interfaces
- Edit /etc/inittab. Find the section of the file that contains the following:
1:2345:respawn:/sbin/getty 38400 tty1 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
- Make the following changes (changes are shown in red):
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
- The above changes will insure that this copy of Linux only creates one terminal on startup.
- Now let's ensure that root will be able to login to the tty0 console that we specified above:
echo "tty0" >> /etc/securetty
Customize the Image
In this section, we will install some additional packages geared towards networking labs and improving thhe overall usability of the filesystem image. If all you want is a generic Debian filesystem image, you can skip this section.
- Create /etc/apt/sources.list so we can install new packages via apt-get:
echo "deb http://ftp.debian.org/debian/ stable main" > /etc/apt/sources.list echo "deb-src http://ftp.debian.org/debian/ stable main" >> /etc/apt/sources.list echo "deb http://security.debian.org/ stable/updates main" >> /etc/apt/sources.list
- Update apt-get's database:
apt-get update
- Set your locality:
apt-get install locales dpkg-reconfigure locales
- Select your desired language, country, and character encoding. If you're not sure which to select, "en_US.UTF-8 UTF-8" is a safe bet if you're based in the US, and will have primarily English speaking users. Once you've finished setting your locality, type su - to activate the changes:
su -
- Install utilities:
apt-get install make tcpdump lynx less nmap bzip2
- Install services. You will be prompted with some questions on how to configure these services. If you're uncertain about which selection to make, all the defaults are safe:
apt-get install quagga ssh thttpd dhcp
- Stop the services that were just installed. The filesystem image will not unmount until they are shut down:
cd /etc/init.d ./dhcp stop ./quagga stop ./ssh stop ./thttpd stop
- Disable most of these services from startup up at boot time. The idea here is in order to conserve RAM, only a minimal set of services should be started by default. They can be re-enabled later if needed:
update-rc.d -f dhcp remove update-rc.d -f exim4 remove update-rc.d -f hwclock.sh remove update-rc.d -f hwclockfirst.sh remove update-rc.d -f quagga remove update-rc.d -f thttpd remove
Enable routing by editing /etc/network/options, and setting ip_forward=yes. Here's an example /etc/network/options file:
ip_forward=yes spoofprotect=yes syncookies=no
Exit Chroot and Unmount Image
- Unmount the /sys and /proc filesystems - you won't be able to unmount /mnt/debian unless this is done:
umount /sys umount /proc
- We're now finished building our filesystem, so let's exit from the chroot that was entered earlier.
exit
- Now let's unmount the filesystem image.
umount /mnt/debian
- If you receive any error messages about not being able to unmount the filesystem, it's probably because you missed one of the steps above. All processes within the chrooted environment must be shutdown, and any mounts within the chrooted environment must be unmounted.
Testing
- You should now have a usable Debian Linux filesystem image. Go ahead and test it for errors. The path to the Linux kernel below may need to be changed depending on where you store your UML Linux kernel:
./linux ubd0=debian.ext2
Register the Template
- Run the following commands to register your new template with MLN
mln register_template -m "Description goes here" -t /path/to/debian.ext2

