Tuesday, August 18, 2009

Alix board debian installation

Well, I've got two brandnew Alix boards and casings here. I already installed one based on a nice instruction found on Blogspot, but it seems the instructions have gone. Does Blogspot remove inactive blogs or something? Anyway, I found the instructions via Google cache and copy them here so I can find them easier next time ;-)

Note: I've copied them verbatim. I'll keep my changes in seperate postings.

Prerequisites

  1. A host system running debian. Can also be a Knoppix live CD. I used Ubuntu 8.10.
  2. CF card connected to a card reader. 2 GB was used for this system.

For the remainder of the guides, following notations are used:

  • CF card mounted on the host system as /dev/sdf
  • Prompt of the host system = Host#, so all commands following this prompt must be executed on the host system


Preparing the file system

Create a partition, create the ext3 file system and tune file system parameters

With fdisk, create a partition and make it bootable, type should be 83:
Host# fdisk /dev/sdf

Next, create the filesystem:
Host# mkfs.ext3 /dev/sdf

and tune it to reduce file system checks:
Host# tune2fs -c 0 /dev/sdf1

Install minimal debian system

A minimal debian system will now be created on the CF card using debootstrap.
On the host system, install debootstrap:
Host# apt-get install debootstrap

Mount the CF card as /mnt/cf:
Host# mount /dev/sdf1 /mnt/cf

and execute debootstrap:
Host# debootstrap --arch i386 lenny /mnt/cf http://ftp.debian.org/debian

Make sure that the status returned by debootstrap is:
I: Base system installed successfully.

chroot in the newly created environment

First, mount /proc and /sys:
Host# mount --bind /proc /mnt/cf/proc
Host# mount --bind /sys /mnt/cf/sys

and then chroot:
Host# chroot /mnt/cf /bin/bash

Configure the base system

First, edit /etc/inittab
  • Remove all lines of the form /sbin/getty ... ttyN
  • Add the following line: T0:23:respawn:/sbin/getty -L ttyS0 38400

Check, create and/or adapt the following lines:

  • /etc/fstab
    proc /proc proc defaults 0 0
    /dev/sda1 / ext3 noatime,errors=remount-ro,commit=120 0 1
    tmpfs /tmp tmpfs defaults,noatime 0 0
    tmpfs /var/tmp tmpfs defaults,noatime 0 0
    tmpfs /var/run tmpfs defaults 0 0
    tmpfs /var/log tmpfs defaults 0 0
    tmpfs /var/lock tmpfs defaults 0 0
  • /etc/hostname
    1 line with the hostname of the system
  • /etc/hosts
    127.0.0.1 localhost
  • /etc/resolv.conf
    search *
    nameserver your.nameserver.com
  • /etc/network/interfaces
    auto lo
    iface lo inet loopback
    auto eth0
    iface eht0 inet dhcp

Install additional packages

First, update the source file for apt. Edit /etc/apt/sources.list:
deb http://ftp.be.debian.org/debian/ lenny main
deb-src http://ftp.be.debian.org/debian/ lenny main
deb http://www.voyage.hk/dists/experimental ./

The repository from voyage Linux is added since I will grab a kernel from that site.

Update the package repository with:
# aptitude update

You will probably get an error of the form:
: GPG error: http://www.voyage.hk ./ Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY FC05444194EFBFA6

Add the missing key:
# gpg --keyserver subkeys.pgp.net --recv-keys FC05444194EFBFA6
# gpg --export
--armor FC05444194EFBFA6 apt-key add -

and try again:
# aptitude update

To avoid warnings about locale:
# export LC_ALL=C

In case you want to install additional locales:
# aptitude install locales
# dpkg-reconfigure locales

Now is also a good time to install ssh:
# aptitude install ssh

Check if /etc/ssh/sshd_not_to_be_run is not present, if so, delete

Install a kernel

First, check the available kernel images in the packages repository:

# apt-cache search linux-image

For example, one from voyage is: linux-image-2.6.26-486-voyage

Before installing the kernel, create a configuration file /etc/kernel-img.conf with contents:
# Kernel image management overrides
# See kernel-img.conf(5) for details
do_symlinks = yes
relative_links = yes
do_bootloader = no
do_bootfloppy = no
do_initrd = yes
link_in_boot = no

Install the kernel image with:


# aptitude install linux-image-2.6.26-486-voyage

Create /etc/modules with content:
natsemi
hostap_pci
lm90
w83627hf
scx200_acb base=0x810,0x820
geodewdt


Install grub

Install grub

# aptitude install grub

Create the grub directory

# mkdir /boot/grub

Copy files needed for grub

# cp /usr/lib/grub/i386-pc/* /boot/grub

Create /boot/grub/device.map file with contents:
(hd0) /dev/sdf
Note that /dev/sdf is the device name of the CF mounted on the development machine
Exit chroot:

# exit

Unmount /proc and /sys on the development machine

Host# umount /mnt/cf/proc
Host# umount /mnt/cf/sys

Now, on the development machine:

Host# grub-install --root-directory=/mnt/cf /dev/sdf

Create menu.lst for grub, edit /mnt/cf/boot/grub/menu.lst with contents:
serial --speed=38400
terminal serial
timeout 1

default 0
title debian-lenny

root (hd0,0)
kernel /vmlinuz root=LABEL=ROOT_FS console=ttyS0,38400n8
initrd /initrd.img
Unmount the CF on the development machine

Host# umount /mnt/cf

In case busy, check with lsof what process is blocking it, most probably sshd, in which case:

Host# killall sshd

and unmount again:

Host# umount /mnt/cf
Add a label to the partition with:

Host# e2label /dev/sdf1 ROOT_FS


Now insert the CF in alix and boot, check the progress on the serial terminal

Login

Login on the alix and watch the output from dmesg
# dmesg

In case you get errors such as:
eth0: ERROR while getting interface flags: No such device

and no network connectivity, you need to correct /etc/udev/rules.d/70-persistent-net.rules:
  • Comment the atl1 SUBSYSTEM line
  • Check and correct the names of eth0, eth1 and eth2. They should correspond to the MAC addresses of these interfaces

Also, avoid warnings in perl about locale. Edit /root/.profile and add:

export LC_ALL=C

export LANG="en_US.UTF-8"

Some settings to reduce CF wear. Link mtab to procs since mtab is written a lot:

# rm -f /etc/mtab

# ln -s /proc/mounts /etc/mtab

Configure the timezone with:

# dpkg-reconfigure tzdata

and make sure UTC=yes in /etc/default/rcS

Finally, set root password with passwd and create users with useradd


Install ntp

Alix has no battery backup for the hardware clock so each time at bootup the time is reset.
Additionally, the clock is not so accurate with a lot of drift (upto 4 hours / 6 days!).
For platforms with continuous network access, the best solution is to install ntp:
# aptitude install ntp

Adapt /etc/ntp.conf and specify a time server (in addition to the predefined ones)

Reload the ntp.conf file with:
# /etc/init.d/ntp restart

and check if peers are found with:
# ntpq -p

Compensate for clock drift

Ntp has a maximum operating range of 500 ppm. This corresponds to 43.2 seconds per day.
If the clock drift is bigger than 43.2 seconds per day, ntp can not compensate anymore.
A quick measurement on the Alix reveals that clock drift is more than 2000 seconds a day!

The solution is twofold:
  1. Install the adjtimex package to set the kernel time variables and compensate so that clock drift is less than 43.2 seconds per day
  2. Use ntp to synchronize to a time reference

First, disable ntp:

# /etc/init.d/ntp stop

Then, install adjtimex on the Alix:

# aptitude install adjtimex

As part of the installation, it will do a measurement of the clock skew and report values for tick and frequency. These quick measurements (70 seconds) resulted in good enough values to stay within 43.2 seconds drift/day.

Make sure these values are correctly placed in /etc/default/adjtimex

The installation will also add links to /etc/rcS.d so that adjtimex is run once at boottime.

Start adjtimex with:

# /etc/init.d/adjtimex start

and restart ntp:

# /etc/init.d/ntp start

In case the reported tick and frequency values during installation of adjtimex are not good enough, following workaround can be used:

Disable ntp:

# /etc/init.d/ntp stop

Set the values of tick and frequency to the default value in /etc/default/adjtimex:

  • tick = 10000
  • frequency = 0

and force reload these values:

# /etc/init.d/adjtimex restart

Synchronize the clock once with ntpdate:

# ntpdate your.timeserver.com

(in case ntpdate is not present, install it with: aptitude install ntpdate)

Let the system run for one day exactly (use a reference clock such as a DCF clock for instance) and check the date again with:

# date

Now you know the time difference you need to compensate for. Take as an example: system clock is 2000 seconds ahead.

With this number, you can calculate the value of tick:

  • 1 tick is 8.64 sec/day
  • 2000 / 8.64 = 231.5 ticks

If the clock is ahead, subtract from 10000: tick = 10000 - 231 = 9769

(if clock is behind, add to 10000)

This can be further finetuned with the frequency parameter since there is not enough granularity with tick alone.

  • 231 * 8.64 = 1995.84
  • 2000 - 1995.84 = 4.16 sec

This means that using the tick value, there will still be a 4.16 second deviation which need to be compensated for:

  • frequency = 2^16 * 4.16 / 0.0864 = 3155437

Put these values (tick=9769 and frequency=3155437) in /etc/default/adjtimex and apply them:

# /etc/init.d/adjtimex restart

Now you can monitor the clock again for a couple of hours.

In case clock drift is within 43.2 sec/day, enable ntp again:

# /etc/init.d/ntp start




No comments:

Post a Comment