InternetInABox Debian On Leon
From RAD Lab
Contents |
How to install Debian on Leon
Created by Zhangxi Tan (xtan@cs dot berkeley dot edu)
Dec 19, 2006
We have successfully installed Debian 3.1 (sarge) on Leon3 with Diligent XUP board (Virtex-II Pro). Leon boots with a RAM disk image, which later pivot_root to a NFS mount point. The rest of Debian package is on the NFS server. You can also replace NFS server with a generic local hard disk or flash drive. In this guide, we will demonstrate how to boot Leon with Debian Linux on NFS step by step.
Prerequisite
- Leon3 MMU with FPU (A lot Debian packages require FP operations)
- A NFS server
- Gaisler Research Linux 2.6 Kernel with glibc (p26 or above)
- Internet access to any Debian repository with Sparc port(Debian GNU/Linux 3.1 or above)
Create Debian rootfs on PC
All the command executed here are on your x86 host PC. Any Debian distributions including Ubuntu can be used as the host OS.
Execute debootstrap to have basic Debian 3.1 (sarge) packages. You can also choose the nearest mirror server. chroottarget is the directory of the Debian root, which should be placed on NFS for Leon.
pc$ debootstrap --foreign --arch sparc sarge chroottarget "http://ftp.debian.org/debian"
Build a basic Linux kernel for Leon that supports NFS mount (through BusyBox). Boot this preliminary version of Linux on Leon and run the second stage of debootstrap as follows:
leon$ mount -o nolock 192.168.1.129:/home/xtan/nfsroot /home/nfs leon$ cd /home/nfs leon$ chroot chroottarget /debootstrap/debootstrap --second-stage
192.168.1.129 is the IP of your NFS server.
Change root password for the target Debian:
leon$ chroot chroottarget leon$ passwd root
You can also modify files in /etc and device nodes under /dev to customize your Debian.
Add the following line to /etc/inittab. This is to put a getty on serial ttyS0, which is the default console output.
T0:2345:respawn:/sbin/getty -L ttyS0 38400 vt100
Create linuxrc file for initrd
A script file called /linuxrc should be placed in ramdisk. This script file brings up network and mounts NFS server. Finally, it calls pivot_root to Debian on NFS and runs /sbin/init. Since pivot_root only works with directories that is registered with mount, it requires mount --bind on Debian root directory (chroottarge) in case it is not the NFS mount point. However, mount in BusyBox does not support '--bind' options. Instead, we use mount from Debian distribution in addition with two shared libraries onto initrd. You can find all required programs and libraries through the Debian root filesystem created above. They are:
chroottarget/lib/libblkid.so.1 chroottarget/lib/libuuid.so.1 chroottarget/bin/mount
Modify the Makefile in vendor/gaisler/leon3mmu to install mount and /linuxrc scripts.
$(ROMFSINST) linuxrc /linuxrc $(ROMFSINST) mount /bin/mount $(ROMFSINST) libblkid.so.1 /lib/libblkid.so.1 $(ROMFSINST) libuuid.so.1 /lib/libuuid.so.1 chmod +x $(ROMFSDIR)/lib/libblkid.so.1 chmod +x $(ROMFSDIR)/lib/libuuid.so.1
change the line
genromfs -v -V "ROMdisk" -f $(ROMFSIMG) -d $(ROMFSDIR)
to
genext2fs -b 8192 -D dev.txt -d $(ROMFSDIR) $(ROMFSIMG)
A sample /linuxrc is given here, Leon has a IP of 192.168.1.80. If you use BusyBox, command line tools used in this script must be supported, e.g. chroot, pivot_root, umount, exec.
#!/bin/sh mount -t proc none /proc echo "Bringing up lo" /sbin/ifconfig lo up 127.0.0.1 netmask 255.0.0.0 echo "Bringing up eth0" /sbin/ifconfig eth0 up 192.168.1.80 echo "Setting routing table" route add 127.0.0.1 dev lo route add default dev eth0 route add default gw 192.168.1.1 echo "Mounting NFS" mount -o nolock 192.168.1.129:/home/xtan/nfsroot /home/nfs mount --bind /home/xtan/nfsroot/chroottarget /home/xtan/nfsroot/chroottarget # tell the kernel the root is on nfs echo 0x0100 > /proc/sys/kernel/real-root-dev echo "Umounting temporary proc" umount /proc echo "Change to new root on NFS" cd /home/nfs/debian-pkg pivot_root . initrd exec /usr/sbin/chroot . /sbin/init </dev/console >/dev/console 2>&1
Configure Linux kernel
When building the kernel, make sure your kernel command line contains 'init=/linuxrc' as follows:
console=ttyS0,38400 root=/dev/ram rw init=/linuxrc
Here we assume using an ext2 initrd instead of a romfs image (default in gaisler Linux distribution). romfs should also work.
Enable tmpfs file system support in kernel
File systems ---> Pseudo filesystems ---> [*] Virtual memory file system support (former shm fs)
Download the new image and reboot
If you put Debian rootfs on a NFS, there will be several warnings concerning fsck, empty fstab (if you didn't configure it) and clock setting at startup. These warnings can be safely ignored.
You can also modify the source list of apt-get to your favorite Debian mirrors. If you need more application packages, just do apt-get or dselect!
