Monday, July 6, 2009

Compact Flash Debian on Alix 2c3

CF DEBIAN on Alix 2C3

I am interested in building embedded computers. The boards I use are the Alix boards over at mini-box.com. That site is a good resource for researching and building very small form factor computers. Previously, I had built one of these computers as a home router running embcop, an embedded modification of the ipcop distribution. Instead of using the pre-build image, I wanted to roll my own using my favorite distribution: Debian.

I started the same way any good project does these days by googling for debian alix2c3 or something to that effect. I was introduced to this website which pretty much outlines the steps required to get it working. I had to make some small modifications to this process, but overall I followed this howto and was successful. Many thanks to Mates.

I keep notes on all of my projects so I won't forget the tricks I learned. My production box is a Ubuntu 8.04 desktop machine with only one hard drive. The main hard drive on the machine is /dev/sda and for the project I used a 1 GB compact flash card (~$10) which is henceforth referred to as /dev/sdb. The concept of the project is plain:
  1. Format
  2. Base install
  3. Kernel install
  4. Boot loader install
  5. ???
  6. Profit! (Profit valid for small values of profit)
I have a 1 GB compact flash card on which to install my operating system, 256 MB of system memory on my Alix board, 3 network interfaces, 2 USB, and 1 serial port.

My compact flash card showed up as /dev/sdb in my Ubuntu system, which I used to accomplish this project. Check your own device settings and be sure about which disk you are addressing, otherwise you may cause damage to your system disk.

First, set partitions on the CF card.

My CF configuration:

$ sudo fdisk -l

Disk /dev/sdb: 1024 MB, 1024450560 bytes
32 heads, 62 sectors/track, 1008 cylinders
Units = cylinders of 1984 * 512 = 1015808 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 24 23777 83 Linux
/dev/sdb2 25 1008 976128 83 Linux

Accomplish this how you wish, using the fdisk utility.

## Format the partitions to ext2.
$ mkfs.ext2 /dev/sdb1
$ mkfs.ext2 /dev/sdb2
## Install the necessary utilities
$ aptitude install debootstrap binutils
## Mount up and install
$ mount /dev/sdb2 /mnt
$ mkdir /mnt/boot
$ mount /dev/sdb1 /mnt/boot
## If you haven't used debootstrap before (I hadn't) you are in for a treat.
## This little program is magic. This step will take some time depending on
## the interwebs.
$ debootstrap --verbose --arch i386 etch /mnt http://ftp.us.debian.org/debian
## chroot into the new system and install a kernel
$ chroot /mnt /bin/bash
# aptitude update
# aptitude install linux-image-2.6-486 openssh-server grub
# mkdir /boot/grub
# cp /usr/lib/grub/i386-pc/* /boot/grub
## Configure the menu.lst file in /boot/grub. What you use here for console
## settings may be dependent on the terminal software used.
serial --speed=38400
terminal serial
timeout 1
default 0
title Debian router
root (hd0,0)
kernel /vmlinuz-2.6.18-6-486 root=/dev/hda2 console=ttyS0,38400n8
initrd /initrd.img-2.6.18-6-486
## Configure /etc/inittab to use the serial line.
## Comment out any lines that look like this:

*:*:respawn:/sbin/getty 38400 tty*

## There should be six or so of them.

## Uncomment this line and modify to suit your setup.

T0:23:respawn:/sbin/getty -L ttyS0 38400

## Edit /etc/fstab. I used hda and not sda for my CF card.

proc /proc proc defaults 0 0
/dev/hda2 / ext2 noatime,errors=remount-ro 0 1
/dev/hda1 /boot ext2 defaults 0 1
## Exit the chrooted environment and install grub to the CF card.
# exit
$ aptitude install grub
$ touch /mnt/boot/grub/device.map
$ echo '(hd0) /dev/sdb' > /mnt/boot/grub/device.map
$ grub-install --root-directory=/mnt /dev/sdb
## Unmount everything and install the card into your Alix board.
$ umount /mnt/boot
$ umount /mnt
## When your board is up and working, modify /etc/network/interfaces
## Here is an example:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto eth1
iface eth1 inet static
address 192.168.10.1
network 192.168.10.0
netmask 255.255.255.0