*

Welcome, Guest. Please login or register.

Get your own OLPC - Buy an XO laptop on eBay!
Pages: [1]
Print
Author Topic: Debian & Kernel From Scratch  (Read 5819 times)

Debian & Kernel From Scratch

anna
Master Contributor
***
Posts: 326


April 05, 2010, 07:43:38 PM

The following creates a base Debian Squeeze jffs2 image you can flash on an unlocked XO's internal nand.  And when I say base, I mean it's the bare minimum required to make the XO boot into a console with functional networking.  I haven't seen all these steps together in one place, so thought I'd write something up.  If you've been looking for a way to roll an install for a minimal headless XO server, this would certainly do it.

It might be possible to do all this on the XO itself, but I have not tried that.  In addition to needing an external drive, you'd have to install a lot of dependencies and it would probably take forever.  Anyway, I'm on a regular Ubuntu desktop and the only dependency not in the repos is crcimg, which you can install by doing this:

Code:
wget http://dev.laptop.org/~mstone/releases/SOURCES/crcimg-1.1.tar.bz2
tar xvf crcimg-1.1.tar.bz2
sudo make -f Makefile.build install

I'm not going to list all the dependencies, as I've lost track, but there are quite a few.  Note I'm using my real life home directory in the commands, so make sure to edit that for your machine.  With that in mind, create the Debian filesystem with a couple of other things.  

Code:
mkdir /home/anna/squeeze
sudo debootstrap --include=wireless-tools,initramfs-tools,locales squeeze /home/anna/squeeze http://http.us.debian.org/debian/

Get the kernel source and check out the latest branch.  You can go to http://dev.laptop.org/git/olpc-2.6/ to verify which one you need.

Code:
mkdir /home/anna/kernel
cd /home/anna/kernel
git clone git://dev.laptop.org/olpc-2.6
cd olpc-2.6
git checkout origin/olpc-2.6.31

Go ahead and create a place to put the new kernel files.

Code:
mkdir /home/anna/kernel-install

Kernel compiling!  This will take awhile.

Code:
make clean distclean
make xo_1_defconfig
make menuconfig # only if you need to make changes
make
make INSTALL_MOD_PATH=/home/anna/kernel-install modules_install
make INSTALL_PATH=/home/anna/kernel-install install

Now we need to copy our kernel files over to the Debian filesystem.

Code:
cd /home/anna/kernel-install
sudo cp config*  System.map*  vmlinuz* /home/anna/squeeze/boot
sudo cp -rav lib/modules/* /home/anna/squeeze/lib/modules

We've got our filesystem and kernel, but we still need to make things bootable and do a bit of other housekeeping.  This is what chroot is for.  If you've never used it before, think of it like logging into the squeeze image.

Code:
sudo chroot /home/anna/squeeze

Create the ramdisk for the kernel.

Code:
cd /boot
mkinitramfs -o initrd-2.6.31.6 2.6.31.6

Go ahead and make the required symlinks.

Code:
ln -sf /boot/vmlinuz-2.6.31.6 /boot/vmlinuz
ln -sf /boot/initrd-2.6.31.6 /boot/initrd.img

Also in /boot, create your olpc.fth.  This is the simplest one that'll get the image to boot, so if you have another one you'd rather use, feel free.

Code:
\ OLPC boot script
" ro root=mtd0 rootfstype=jffs2 console=tty0 fbcon=font:SUN12x22" to boot-file
" nand:\boot\vmlinuz" to boot-device
dcon-unfreeze
boot

Here's an /etc/fstab that works.

Code:
mtd0 / jffs2 defaults,noatime 1 1
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults,size=15% 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
none /ofw promfs defaults 0 0
tmpfs /var/cache/apt tmpfs defaults 0 0

Apt-get doesn't like to play nice with jffs2, so throw this in /etc/rc.local.  Ugly, but it seems to work.

Code:
mkdir -p /var/cache/apt/archives/partial

Get the wifi firmware.

Code:
wget -O /lib/firmware/usb8388.bin http://dev.laptop.org/pub/firmware/libertas/usb8388-5.110.22.p1.bin

Load the wifi kernel module at boot.

Code:
echo usb8xxx >> /etc/modules

Create the /etc/hosts file.  Change anna-xo to whatever you want.

Code:
127.0.0.1 localhost.localdomain localhost
127.0.0.1 anna-xo

Specify the hostname (again, change anna-xo).

Code:
echo anna-xo > /etc/hostname

Since this is a "personal" image, I'm going to put my wifi AP in /etc/network/interfaces so the XO will automagically connect on first boot.  Mine happens to be unprotected, so if you have WEP you need to put your key in there as well.  If you have WPA, you'll need jump through other hoops.

Code:
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
wireless-essid MYHOMEWIFI

If you don't do this, you'll constantly get a bunch of errors about the locale.

Code:
dpkg-reconfigure locales

Scroll with your up/down arrow keys and then use the spacebar to select "en_US.UTF-8 UTF-8"  Tab, then enter to select OK.  Hit the down arrow to select that locale, then tab and enter for OK.

Set your time zone.

Code:
dpkg-reconfigure tzdata

Edit your /etc/apt/sources.list

Code:
## Debian Security updates:
deb http://security.debian.org/ squeeze/updates main contrib non-free
deb-src http://security.debian.org/ squeeze/updates main contrib non-free

## Debian.org:
deb http://ftp.debian.org/debian/ squeeze main contrib non-free
deb-src http://ftp.debian.org/debian/ squeeze main contrib non-free

## Debian US mirror:
deb ftp://ftp.us.debian.org/debian/ squeeze main contrib non-free
deb-src ftp://ftp.us.debian.org/debian/ squeeze main contrib non-free

Optionally, you can

Code:
aptitude update
apt-get install stuff

Remember not to go overboard if you're putting this on the nand.  Also remember to aptitude clean.

Finish up:  Set the root password and add a user if you want (no, it does not need to be olpc).  Clear out the network devices so the XO's wifi comes up as eth0.

Code:
rm /etc/udev/rules.d/70-persistent-net.rules.

To get out of the chroot environment, simply type exit.  Now we can create the files to flash the XO.  Go to the directory you want to put them.

Code:
sudo mkfs.jffs2 -n -e128KiB -r /home/anna/squeeze -o squeeze.tmp
sudo sumtool -n -p -e 128KiB -i squeeze.tmp -o squeeze.img
sudo crcimg squeeze.img
sudo rm squeeze.tmp

That creates squeeze.img and squeeze.crc in your current working directory.  Copy both those files to a USB drive, then go to the unlocked XO.  At the ok prompt, type

Code:
copy-nand u:\squeeze.img

Either type boot or power off and power back on.  If all went well, you should be welcomed with a console login prompt.  If you're using this as a headless machine, you can turn off the backlight like this:

Code:
echo 0 > /sys/class/backlight/dcon-bl/brightness

Turn it back to max by replacing 0 with 15.

Hopefully the image generation and kernel compile process isn't so mysterious now, even if you're not planning on doing it yourself.
« Last Edit: April 06, 2010, 10:27:52 AM by anna » Logged

#1 Re: Debian & Kernel From Scratch

anna
Master Contributor
***
Posts: 326


April 06, 2010, 04:32:51 PM

I couldn't get /etc/hosts to be there on reboot until I installed dnsutils.  Gotta have localhost.

Anyone know a cleaner way to go about that than including dnsutils in debootstrap?
Logged

#2 Re: Debian & Kernel From Scratch

anna
Master Contributor
***
Posts: 326


May 30, 2010, 06:32:37 PM

The process above for a console only Debian Squeeze install mostly works for Ubuntu Lucid, but with some key differences.  Mainly due to plymouth, which Lucid uses during the boot process.  It's a highly controversial change and has attracted quite a bit of ire.  I won't get into that, but eventually I did successfully create a 166M Lucid jffs2 image, flashed it on the XO, and got to a login prompt.

Create the directory for the install

Code:
mkdir /home/anna/lucid

The usual debootstrap process might fail.  I tried it a couple of times and it errored out, probably because the repos or my network were being flaky.  If it does fail, see the next two commands or try a different mirror.

Code:
sudo debootstrap --arch=i386 --include=wireless-tools,dnsutils,nano,wget lucid /home/anna/lucid/ http://archive.ubuntulinux.org/ubuntu

Instead of the above command, I ran this a couple of times and it eventually pulled in all the packages.

Code:
sudo debootstrap --arch=i386 --include=wireless-tools,dnsutils,nano,wget --download-only --keep-debootstrap-dir lucid /home/anna/lucid http://archive.ubuntulinux.org/ubuntu

Backup the lucid dir if you like before you continue.  If you mess up something later, you can simply rename the backup folder to lucid and go from there without having to download everything again.

Code:
cp -rav /home/anna/lucid /home/anna/debootstrap-lucid-backup

Complete the installation.

Code:
sudo debootstrap --arch=i386 --include=wireless-tools,dnsutils,nano,wget lucid /home/anna/lucid http://archive.ubuntulinux.org/ubuntu

Follow the instructions for the Debian install, except for these three things:

This olpc.fth works:

Code:
\ OLPC boot script
" ro root=mtd0 rootfstype=jffs2 console=tty0 console=ttyS0,115200 fbcon=font:SUN12x22 video=fb:1200x900 loglevel=1" to boot-file
" nand:\boot\vmlinuz" to boot-device
dcon-unfreeze
boot

Configure the locale:

Code:
locale-gen en_US.UTF-8

Create /etc/init/plymouth-console.conf so you don't have to hit ctrl+alt+F1 to get to your prompt.  You do have to hit enter, though.

Code:
# plymouth-console - if gdm is not installed, run this to change VT at the
# end of the boot

description "server VT switch"

start on (started tty1 or starting rcS or starting mountall-shell)

task

pre-start script
# Prevent this job from running if the package is removed but
# not purged.  This list needs to be kept in sync with the one in
# plymouth.conf (plus gdm).
if [ -x /usr/sbin/gdm ] || [ -x /usr/bin/kdm ] || [ -x /usr/bin/xdm ]
then
stop
fi
end script

exec chvt 1

It boots rather slowly compared to Debian Squeeze and then it won't give you a login prompt off the bat.  Hit enter when the boot messages stop scrolling and you should get a prompt.

I'm not sure what I think of it yet, but at least it booted on the XO.
« Last Edit: May 31, 2010, 02:28:29 PM by anna » Logged

#3 Re: Debian & Kernel From Scratch

Eph Zero
Senior Contributor
**
Posts: 170



WWW
June 09, 2010, 12:25:24 PM

Thanks very much for putting this info together! Worked for me. Smiley
Logged
Pages: [1]
Print
Jump to:  

Members
Total Members: 2405
Latest: sembik
Stats
Total Posts: 31943
Total Topics: 3843
Online Today: 27
Online Ever: 238
(April 18, 2011, 09:48:50 PM)
Users Online
Users: 0
Guests: 13
Total: 13