Debian on compact flash

Recently I bought myself a Thintune Micro-PC after my old download and backup server crashed (RIP rammelbak). I was searching for a low cost replacement which did not make as much noise as Rammelbak (that was the hostname of the old server) and was not as power hungry. All of a sudden there was an auction on samenkopen.net and I managed to get one for 50 EUR. This system is completely fanless, and boots from a CF (compact flash) card which is put in a CF-To-IDE converter.

It will boot Debian Etch (aka stable) from a read only CF card, while all downloads and backups are stored on an external SATA drive which I can switch on and off from the commandline (still work in progress though).

mini-pc.JPG thintunem_1.JPG thintunem_4.JPG

Hardware specs

  • VIA C3 533 MHz CPU
  • 64 MB 133 MHz SD-RAM (upgraded to 256 MB)
  • 1x PCI with riser
  • 1x IDE delivered with CF-To-IDE converter
  • 32 MB CF card (upgraded to 2 GB)
  • 1x 100 Mbit LAN1xLAN (bootable)
  • Onboard Trident VGA 8 MB, max 1600×1200
  • Onboard sound, speaker/mic
  • 2x PS/2
  • 2x USB 1.0 (bootable)
  • 2x COM
  • 1x LPT
  • Power consumption:15 Watt (!!)

Why use CF instead of a normal HD ?

I wanted the system to be as quiet as possible, and use as less power as possible. As we all know, HD’s get hot when they’re in use due to the fact that there are a lot of parts moving around in it. Because of this heat, a fan is needed to create a certain airflow in order to cool things down … and fans create noise (as do HD’s).

A CF is a kind of SSS (Solid State Storage), and thus has no moving parts in it. No moving parts means no heat and no noise. A downside of flash memory is that it has a lifetime of around 10 000 to 1 000 000 write cycles. However, I’ll be using this CF to create a read only disk, so technically this disk will ‘never’ die.

Notes

The commands issued on this page are all run on an already installed Debian workstation, and are executed by the root user. This information is given as a guideline for myself, and should be used as such. I am not responisble if anything goes wrong!

Although I constantly speak of a CF card, you can easily try this on any kind of media (USB sticks, HD’s, …) which need to boot a read only filesystem.

Creating the image

Because of the low count of write cycles of flash memory, we’ll first install the OS in a new directory (or partition if you like) and once finished copy it as a whole to the CF card.

In order to do so, we need to create a directory (or partition) and do a debootstrap to get a new Debian install.

mkdir /cf
apt-get install debootstrap
debootstrap --arch i386 etch /cf http://ftp.debian.org

Now we have a fresh Debian system located in /cf. All we have to do now is change root (chroot) to this fresh install.

mount -t proc proc /cf/proc/
mount -o bind /dev/ /cf/dev/
LC_ALL=C chroot /cf /bin/bash

In this new root environment you can install the applications to make it suit your needs. Don’t forget to install a kernel (I compiled mine from source, get the config here) and a bootloader (I used grub). I also installed an SSH server, because I’ll be using this system as a headless one.

apt-get install ssh linux-source-2.6.18 gcc make libncurses-dev grub udev

I won’t explain how to compile your own kernel, there are places enough on the Internet where you can find the necessary information.

After you’ve compiled your kernel, install it.

cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.18
make modules_install

Remove /etc/mtab and symlink it to /proc/mounts. This special file also describes the mounted filesystems, and can replace mtab without needing a write access on it.

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

An other file in /etc that needs to be writeable is resolv.conf. This file holds the data concerning nameservers and the like. We make it writeable by removing it, and creating a symlink to /var/log (which is writable, see below).

mv /etc/resolv.conf /var/log
ln -s /var/log/resolv.conf

Next step is to create/modify some config files. Open them up with your favorite editor (e.g. vim) and change them to the following:

  • /etc/fstab

    /dev/hda1 / ext2 defaults,noatime 0 0
    proc /proc proc defaults 0 0
    tmpfs /var/run tmpfs defaults 0 0
    tmpfs /var/lock tmpfs defaults 0 0
    tmpfs /var/log tmpfs defaults 0 0
    tmpfs /tmp tmpfs defaults 0 0
    tmpfs /var/lib/dhcp3/ tmpfs defaults 0 0

  • /sbin/dhclient-script
    Set new_resolv_conf to “/tmp/resolv.conf.dhclient-new”.
    Change “mv -f $new_resolv_conf /etc/resolv.conf” to “cat $new_resolv_conf > /etc/resolv.conf”
  • /etc/network/interfaces

    auto lo eth0
    allow-hotplug eth0
    iface eth0 inet dhcp
    iface lo inet loopback

  • /etc/hosts

    127.0.0.1 localhost.localdomain localhost your_hostname

  • /etc/syslog.conf
    Comment the lines where /dev/xconsole is mentioned
  • /etc/init.d/checkroot.sh
    Change ROOTMODE to ro
  • /etc/init.d/bootlcean.sh
    Add the following lines before the line stateing [ -f /tmp/.clean ] && … (located at the end of the file)

    touch /var/log/resolv.conf
    touch /var/log/dmesg

In /etc/fstab we created a couple of tmpfs entries. These point to the directories where files are located that should be writeable at all times (/var/lock, /var/run). These directories are than mapped to memory, so when a program writes to a file in that particular directory, it actually writes to the memory. This way we prevent loads of error messages (about files being on a read only disk) flooding the terminal .

It’s also a good idea to create 2 alias definitions in /root/.bashrc for remounting the root directory ro/rw.

echo alias ro='/sbin/cleanup all;mount -o remount,ro /' >> /root/.bashrc
echo alias rw='mount -o remount,rw /' >> /root/.bashrc

The file cleanup is a bash-script which I’ve written to remove files which shouldn’t be written back to the cf card. You can download it here.

Transferring the image

Once you are finished modifying your image, exit the chroot (by typing exit) and copy all files in the image to your CF card. Be sure to first create a partition on the CF disk, and remember to format it using the ext2-filesystem (don’t use ext3, what would be the use of a journaling filesystem on a read only disk :-)). I presume your CF card is located at /dev/sda (mine is). To be sure, check the output of dmesg when you insert the card.

cfdisk /dev/sda
mkdir /mnt/cf
mount /dev/sda1 /mnt/cf
cp -aR /cf/* /mnt/cf

Now the files are copied to your CF card, but we still need to install the bootloader on it.

grub-install /mnt/cf --recheck /dev/sda

Now the bootloader is installed, we need to configure it. Enter the chroot environment on your cf card, and enter this command:

update-grub

Exit the chroot, unmount the image and now you have a working Debian install on a CF card. You can check the image with qemu before you put it in another computer.

umount /mnt/cf

To do

  • make the server control my lights using simple 433 MHz remotes
  • install a VPN server
  • make it interact with my mobile via bluetooth so I can program mythtv and control my lights using SMS


						
			
		

36 Comments

OkUApril 7th, 2008 at 10:00 pm

I have the same device.
Would it be possible to put the cf image online.

adminApril 8th, 2008 at 7:02 am

Well, I’ll have to check what the size of the image is.
You could also do these steps while you’re booted from a Knoppix CD, if you don’t have a working Linux install on your PC.

Otherwise you could mail me a location where you want the image, and I’ll send it to you (presumably on sunday …)

OkUApril 13th, 2008 at 2:38 pm

I have solved the problem. I was asking for the image because grub couldn’t boot, but i was working on debian testing when i tried you tutorial on etch i was working fine. Thx great tutorial.

GuidoApril 16th, 2008 at 10:33 pm

I used your “Debian on compact flash” to run my OpenVZ host system on.
Thanks to your explaination installing everyting on a CF card was realy easy.

Thanks ..!

rafaelMay 27th, 2008 at 1:07 am

hi, i have the sam device, and i installed an ipcop on this system. my problem is that the device will restart over time. i think its a heat problem. The cpu gets so hot that i cant hold my fingers over a long time on it. do you have a heatproblem too ?

adminMay 27th, 2008 at 7:19 am

Hey Rafael,

I don’t have an overheating problem. Have you checked your resources
using ‘top’? I don’t know how resource-hungry ipcop is when you have a lot off traffic passing by. Have you disabled SWAP (because there’s no DMA support on the onboard CF-IDE)

maxSeptember 1st, 2008 at 10:32 pm

Perfect and usefool but dont you think that
grub-install /mnt/cf –recheck /dev/sda
should be:
grub-install –root-directory /mnt/cf –recheck /dev/sda

adminSeptember 12th, 2008 at 10:26 am

Hey Max,

I think you’re right. I haven’t got the time to check it in the next weeks, but next month I’ll have a look at it !

Thanks for mentioning it !

[...] make it interact with my mobile via bluetooth so I can program mythtv and control my lights using SMS February 10th, 2008 in linux, thintune Refer: http://kristof.vanhertum.be/?p=3 [...]

Charles McKinnisOctober 6th, 2008 at 3:26 am

I used your documentation a while back to build myself a router with some build changes. It occurred to me when someone else linked to me that I should give you the opportunity to review the post with my notes.

Kristof Van HertumOctober 6th, 2008 at 6:55 am

@Charles
Thanks for linking back. I’ve used the LC_ALL=”C” part in the chroot command because some people seem to have not set this variable in their shells. This causes warnings to be printed (something like “WARNING: variable LC_ALL is not set…”)

Holger WirtzOctober 15th, 2008 at 1:11 pm

Kristof,

this descrition is really nice! I just have some problems to check my image with qemu. My CF card is at /dev/sdd and after apllying your commands I try “qemu -m 32 -localtime -hda /dev/sdd -append “root=/dev/hda1″ (as root, because I need the access to /dev/sdd). But booting ends every time in the grub shell. From there I tried to load the kernel with “linux /boot/vmlinuz root=/dev/hda1″ but this stops with a kernel panic.

Any hints?

Thanks, Holger

Kristof Van HertumOctober 15th, 2008 at 1:36 pm

Hey Holger,

It’s been a long time since I last tested my image with qemu …
Have you tried leaving out the ‘-append “root=/dev/hda1″’ ?

Does your system itself boot from the CF card ?

MJOctober 15th, 2008 at 4:47 pm

Hi

I have the same device, but can’t boot from usb. You wrote “2x USB 1.0 (bootable)”. Have you tried this ?

Another question: What kind of PCI riser card is this ? There are only pins on the mainboard for PCI. No socket.

Thanks

MJ

Kristof Van HertumOctober 15th, 2008 at 7:50 pm

Hi MJ,

I have tried booting it from USB, but it was really slow (USB 1…). In order to boot from USB, you’ll have to upgrade your bios.

You can see the riser card at the top of the page, the image at the middle. Mine has a socket, and the riser card was included.

Gr,
Kristof

Holger WirtzOctober 16th, 2008 at 8:34 am

Hi Kristof,

I really don’t know what I am doing wrong but the system won’t boot - not im qemu and not on the real hardware. It seems to be a problem with installing/configurating grub. Every time the system stops in the grub shell and loading the system “by hand” boots the kernel but don’t find the root partition… really strange. I think I have to read more about grub…

MJOctober 16th, 2008 at 11:26 am

Hi Kristof,

how can I upgrade the Bios ? In Bios mode the headline says only:

” Bootloader Version 4.00 Build 009 (Eden)”

-no “Phoenix” or “Award” …

Do I need the thintune management software for this ?

And the riser card… Sure, I can see it, but it seems to be non-standard with an 80 pin socket (like big IDE) for the mainboard. Perhaps i’ve to tinker something.

Any idea, if the internal power supply is strong enough for an internal 3,5 ” IDE HDD ?

thanks a lot
MJ

Kristof Van HertumOctober 16th, 2008 at 11:39 am

@Holger:
Have you tried what max said (grub-install –root-directory /mnt/cf –recheck /dev/sda) ?
What is the error you get from grub ? Is the device you are trying to boot a thintune (if not, the kernel config won’t work !)

@MJ:
No idea if the power supply is strong enough for a normal HD. I believe it is capable of powering a laptop HD. But where would you place it :-). The PCI riser card is a normal one (meaning you could fit a normal PCI card in it, although you couldn’t close the case anymore).
Once you boot the BIOS update CD, you have to give a command, but I don’t know by hand which one …

MJOctober 16th, 2008 at 1:07 pm

@ Kristof:

I have no BIOS update CD. Where do you get it. Perhaps you could offer the iso somewhere online so i can download it. ( or by email)

greets
MJ

MJOctober 16th, 2008 at 1:11 pm

@ Kristof:

when the Bios update CD is a normal one, it’s not the problem. But the BIOS to flash…

Holger WirtzOctober 16th, 2008 at 1:49 pm

Kristof,

sorry for misusing your comment as a kind of maillist, but I found what the problem is on my installation. It has not much to do with grub (or lilo I tried now). The problems are that ther kernel don’t knows anything about the drivers in /dev. I installed udev but I think I forgot to buzild a driver hard into the kernel for using udev. Until know I didn’t find the right one. I will giv a reply if I know how to fix this.

Regards, Holger

Kristof Van HertumOctober 16th, 2008 at 2:34 pm

@MJ:
I mailed you the update CD yesterday, to the address you used to post your reply.

@Holger
Using it as a mailing list, increases the comment counter and makes me look important ;-)
Make sure you compiled udev support into your kernel. If you have the thintune, you can use the kernel config which I’ve put online.

MJOctober 16th, 2008 at 2:41 pm

@Kristof:

thank you for mailing. I’ll try…

MJOctober 19th, 2008 at 12:41 pm

Hi Kristof,

my mainboard is a TK3350 V2.3 and i’am still looking for a compatible riser card. On the mainboard are only 80 pins (like big IDE) for the PCI interface. No PCI socket.
Perhaps you could send me some specs, description, identification or just some pics of your riser card ?

- Is the BIOS file included in the FLASHCD-Iso you send me.
Which file is it ? BACKUP.BIN, BACKUP.BOO, BACKUP.CMO, UNIFLASH.EXE, or UNIFLASH.LNG ?
Could you backup your “old” BIOS file with this utility ?

sorry, lots of questions…

thamks
MJ

Kristof Van HertumOctober 20th, 2008 at 6:18 pm

Hi MJ,

You have to run UNIFLASH.EXE. No idea whether you can create a backup with it.

For the riser card, you can view some pics at http://www.samenkopen.net/action_product/459722/567493.

Gr,
Kristof

In Defiance of TitlesNovember 7th, 2008 at 2:09 pm

[...] from the data. I don’t think I’ll make it completely read-only as some folks have suggested, but obviously I’ll need to be careful about how often it gets written to. Anyway, I thought [...]

TobiDecember 9th, 2008 at 9:33 am

Hello Kristof

This tutorial is really nice! :)

But, what about updates? How do you update your system once it is running (ro)?

Regards, Tobi

Kristof Van HertumDecember 9th, 2008 at 10:45 am

Hey Tobi,

I wouldn’t really update the image, because installing extra/new/updated packages would reduce the lifetime of your flash disk (if it dies, I have to remove the riser card in order to replace the CF card). You could however install the packages by mounting the / partition rw, and after installing remount it ro.

I however, copied the complete image to an external harddisk. If I want to install/upgrade a package, I just chroot to the image on the external disk and install it there. You can simply run programs from the external disk by chroot-ing to it.

Hope this helps,
Kristof

TobiDecember 9th, 2008 at 12:23 pm

Hey Kristof

Thank you very much for your quick answer—it helps! :)

Bye, Tobi

StevenDecember 12th, 2008 at 10:38 pm

Hi mate thanks for the details they’ve been very helpful. Quick question though, the tmpfs drives seem to be mounted ro is this normal?

Your alias scripts need a tweak, i had to add ‘ in the bashrc. Most folk would work it out but you never know if a noob stumbles across it (me).

Kristof Van HertumDecember 14th, 2008 at 10:26 am

Hi Steven,

Could you tell me where you added the `? I just had a quick view on it, but didn’t find a missing `.

It is not normal that you tmpfs mounts are readonly. Are you sure you added the ‘defaults’ tag to fstab ?

Kristof

StevenDecember 15th, 2008 at 12:28 am

Thanks for the response. I’ll just copy in the relevant part of the .bashrc.
alias ro=’/sbin/cleanup all;mount -o remount,ro /’
alias rw=’mount -o remount,rw /’
When i first ran the echo command it didn’t put the ‘ in.

Defaults added to the fstab, yeah. Is there something else that would cause this behaviour?

lsJanuary 24th, 2009 at 12:39 pm

Hi everybody!
I have the same thintune device now, bought a few days ago.
Would be nice if you could write me a mail Kristof.
Thank you!

DaveMarch 14th, 2009 at 5:33 pm

Hi Kristof,

Thanks for the post, It’ll certainly come in handy when i build myself a new fileserver in a few weeks time.

Anyone reading this might want to consider using CF Microdrives, they’re pretty cheap now and don’t have a write cycle limitation (though, they draw slightly more power).

Cheers,

Dave

johnnysavilleSeptember 27th, 2009 at 3:29 am

Hey Kristof,
I did the things it said in the article and it all worked really great! I’m just wondering, when I look at my mount tables I see these three extra entries:

rootfs on / type rootfs (rw)
none on /sys type sysfs (rw,nosuid,nodev,noexec)
none on /proc type proc (rw,nosuid,nodev,noexec)

Even though they say “RW”, are they readonly?

Kristof Van HertumSeptember 27th, 2009 at 9:12 am

Hey Johnny,

Those are ‘filesystems’ used by the kernel. They are created in memory, so they do not write to your disk/card.

Gr,
Kristof

Leave a comment

Your comment