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

Monday, August 4, 2008

Alix Board Router

I was interested in building a small, embedded router/firewall that was completely silent, and very low power. Here is the solution:


















That's right, it is no bigger than a paperback novel. Slaughterhouse Five is a damn fine book. Interested in building one yourself? You came to the right place. The process for building and configuring and Alix-based computer can be summarized in the following steps.

1. Find a parts supplier.
2. Test the board.
3. Install the image.
4. Configure your new computer.


Step 1: Find a parts supplier.

The only place to shop for parts is a website called mini-box.com. The following parts are required:

Total: About $192.00

Shipping costs will vary, but it will not add too much to the overall cost of the project.

Step 2: Test the board.
Here's how to test the board. First, let's start by doing something radical and reading the fine manual. The manual specifies that the required settings on a terminal emulator are as follows: 38400 8N1, flow control = none or xon-xoff. When you connect the board to the serial port of your computer, make sure you use the null modem adapter or a null modem cable, and you will see something like the following when power is applied to the board.


PC Engines ALIX.2 v0.98j
640 KB Base Memory
261120 KB Extended Memory

01F0 Master 848A CF 128MB
Phys C/H/S 1002/8/32 Log C/H/S 1002/8/32


Step 3: Install the image.
Okay, now that we know the board is not DOA, it is time to to choose and install an image. Head over to embcop.org and choose one of the WRAP images that matches your card. Once the file is downloaded, decompress it and you will have a resulting .img file. Push the .img file onto your compact flash card using dd.

dd if=1gbflash.img of=/dev/sdb

where /dev/sdb is the CF card. Your card may show up differently so take care to determine the correct path to your card before you wipe out your hard drive. Also, in this instance I used the 1 Gb image, which you can use only if your CF capacity will support it. This step may take up to 45 minutes to complete, so just take the time to daydream about your pending success. When the image is finished writing, unmount the drive and transfer the CF card to the Alix board.

Step 4: Configure your new computer.
If all goes well, you should find yourself booting into a new operating system, IPcop for embedded systems, or embcop.

Here are some screenshots of the embcop system: