Debian Linux on Flash Card

From wiki.linuxonlinehelp.eu
Jump to navigation Jump to search

Debian on compact flash (copy from web)

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).


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