5. Installation to Compactflash

A compactflash (CF) system first starts by using an initrd to boot up and enable the CF and mount its system partition. Then "pivot_root" is executed to switch from the initrd root filesystem to the CF root filesystem. The trick is to have a suitable, minimal initrd system to get things started, a decent distribution installed on your compactflash card, and various scripts set up to orchestrate the transfer between the initrd and the compactflash systems. The installation is therefore similar to the previous section (Installation to Initrd), with the addition of a system on compactflash. That section is a prerequisite to this section.

The netBook will support microdrives (IBM, Hitachi, etc.), which behave identically to CF cards (or IDE devices, in general). Microdrives of size 4 GB or larger are supported; there does not seem to be a particular limit to disk size for either CF or microdrive.

Linux can now be booted using an "OS.IMG" file, roughly equivalent to the netBook's original "OS.IMG" file, and this is the preferred method of booting. The linux OS.IMG file contains and starts the kernel and a small initrd to transfer the system to a compactflash-based system disk. With a suitable OS.IMG file, the details of how the system is booted can be largely ignored by those wishing to get on to the linux system. The advantage of booting to linux from EPOC using Arlo, rather than a replacement OS.IMG file, is that Arlo gives you essentially a dual-boot system - you get the best of both EPOC and Linux. (But the OS.IMG approach starts Linux much faster.)

5.1. Getting the things you need

For a compactflash system that boots from EPOC you will need four things to complete an installation of linux on the netBook: (1) a kernel image, (2) a ram disk root filesystem (initrd.gz), (3) the EPOC application ArLo, and (4) a decent system installed onto an ext2 partition on the compactflash. N.B. You cannot install a linux root filesystem onto the FAT filesystem that EPOC uses. That filesystem does not support the linux device filenames.

(1) You can obtain kernel images from Psilinux Downloads - a kernel that supports compactflash has now been formally released. The linux kernel will support either the 32MB or 64MB version, depending on if you have the 32MB memory expansion card or not. Separate kernels are no longer required for the various memory configurations. You might find a legacy 16MB kernel there as well. Put the appropriate kernel on your netBook as, e.g., D:\linux.image. For kernels that support compactflash, also check out openpsion for "testing" kernels [well...everything is "testing" at this stage!] for the netBook. Also try Leppä's Blog, the origin of the most cutting edge kernels at the moment.

(2) The ram disk root filesystem for a compactflash system is a small system tailored to mounting the compactflash drive and transferring the root filesystem to the compactflash ext2 partition. You can obtain a ram disk root filesystem for this purpose from the Psilinux Downloads page. Put this file on your netbook as, e.g., D:\initrd.gz. For now, Debian on netBook has the only initrd's developed specifically for the netBook and compactflash support.

(3) Next, get and install Arlo which is used to boot linux from a running EPOC system. (The original Arlo webpage is ArLo.) ArLo can now be installed as a *.zip installation. Unzip the zip file (preserving the folder structure) on either drive C: or D:. ArLo has a nice GUI frontend. Details on how to use ArLo can be found at that web site, or the manual.

(4) There are several root filesystems that you can now install onto the ext2 or ext3 filesystem of your compactflash card. An ipkg-based system can be found at www.netbook-linux.org. Debian linux based systems can be found at Debian linux on netbook (download from Psilinux Downloads) and possibly here. Install one of these systems on the second partition of your compactflash card.

5.2. Configure ArLo

The ArLo configuration is identical to that described in the previous section with one important difference; see the section on ArLo in this HOWTO Using ArLo - Booting Linux from EPOC for details. The entry for booting to the linux initrd in the arlo.cfg file needs to have another line giving the option "boot = init=/linuxrc". This line will cause linux to first run "/linuxrc" on the initrd, and this script takes care of mounting the compactflash disk and transferring the root filesystem to it.

5.3. Repartition your Compactflash Card

To use a compactflash-based system, you'll need to repartition your compactflash drive to have a small FAT16 partition and a larger ext2 or ext3 partition. For a 128 MB Compactflash drive, I have a 28 MB FAT16/DOS partition for EPOC and 100 MB ext2 (or ext3) for linux. The EPOC partition has Arlo installed on it. The netBook needs the 13 MB OS.img file to boot back to EPOC, so about 20 MB is probably the minimum size.

In one case, my CF disk would no longer boot up the OS.img file after repartitioning. This may have to do with nuances of the DOS filesystem. See the linux man pages for fdisk. I followed the advice from these man pages and zeroed the first 512 bytes of the new DOS filesystem with "dd if=/dev/zero of=/dev/sda1 bs=512 count=1", and then formatted the new 28 MB DOS partition using either linux or EPOC. The EPOC system would then boot the OS.img file again.

Interestingly, if you make two or more DOS partitions on your CF, EPOC will apparently recognize all of them. Some people claim to have better performance from their CF this way.

If you do not have a linux system handy to repartition and format the compactflash card as described above, you can always download any of the "Live" CD/DVD's that various systems have made available. These disks allow your computer to boot off the CD and operate entirely off the CD; your hard disks are untouched. And you have a complete, portable linux system at your disposal. I can recommend Ubuntu Linux, which is a spinoff of Debian linux (see the Downloads section - it is free, of course).

5.4. Swap Space Comments

There has been an on-going dialog concerning the use of swap space on a netBook. Generally, swap space is a good idea - this is an area of the disk, the compactflash card in this case, that is defined as a memory extension. When the system needs more memory than is available, memory can be made available from the disk; linux will "swap" the less used applications to the disk on swap space, freeing up system memory for more important needs. Given the netBook's limited 64 MB (max), swap space can enable compilation of programs or larger applications that would otherwise not be feasible. One person commented on the mail list that with swap space, the netBook seemed to be a bit happier; the exact effect of swap space on a system that does not have an obvious need for such space is unclear, however. Note that swap space is VERY slow; your application may finish, but it will likely take a while.

Sluggish performance is something that is commonly associated with low memory because desktop systems start swapping when memory is low. A swapless system won't exhibit this sluggish behaviour. When a memory limit is reached, an application will, if you're lucky, give you an error, or it may just crash. It shouldn't crash the entire system; the kernel should intelligent enough to make a user-space application crash, rather than refusing to allocate memory to a kernel process. What a particular application does when it hits the RAM limit depends on application, however. Some exit nicely, some crash in nasty ways. (This author is not altogether convinced that the netBook's kernel is completely intelligent in this matter...)

The main problem is that compactflash cards have only a limited number of writes. If swapspace is formally defined on the compactflash card, it will be used extensively by the linux kernel and may well cause that area of the compactflash card to fail at the hardware level. Formally defining a partition on the compactflash card to be swap space is not recommended for this reason. Note that the number of writes is ca. 100,000, and the disk controller is smart enough to keep rotating where the writes occur, so that it usually takes a long, long time for the card to "wear out". Microdrives are not subject to this issue.

There are, however, various strategies for enabling swap space. One approach is to make a file of size desired for swap space and then format it for swap. This file can then be mounted and used from time-to-time as necessary. The procedures to do this are:

  1. Create a contiguous file of zeros by: "dd if=/dev/zero of=/somewhere/swapfilename bs=512 count=16800" which makes a ca. 8 MB file of zeros (adjust the size as needed; the real required size is defined by the most memory you'll need for the applications you want to run. The size of your RAM + Swap should be slightly more than this.)

  2. Format the swap file to be used: "mkswap /somewhere/swapfilename"

  3. Mount the new swap space: "swapon /somewhere/swapfilename"; your system now has 8 MB of swapspace available to it. Do a "free" to verify the system is accessing the swap space.

  4. And after you are done using the swap space, turn it off: "swapoff /somewhere/swapfilename"

Another suggestion is to format an old, smaller compactflash card for swap, and use it in the pcmcia slot as needed. We all have various old cards lying around! This is a sacraficial use of an old, small card that would otherwise not be used.

Similarly, and perhaps optimally, an external laptop hard drive can be plugged into the pcmcia slot, and swap space, or even a swap partition on it, can then be used on it. In this case there is effectively all the swap space you want and no danger of wearing out the external disk.

5.5. Install the new system on the Compactflash Card

The Debian linux system is just a tar ball that should be unpacked onto the ext2 or ext3 filesystem of the second partition. First mount the compactflash partition on the desktop. Then unpack the system tar ball to it, "tar xfz system.tgz -C /mnt/disk2", if the CF ext2 partition is mounted to /mnt/disk2. That should be all that is required, although you can then customize whatever aspects you'd like on the CF system from the desktop, before booting it on the netBook.

5.6. Alternate Installation: An OS.IMG for linux

It is now possible to install a custom OS.IMG file that will boot the netbook directly to linux. For this system, you just need the OS.img file copied to the first fat16 partition of your compactflash card, and the linux system installed on the second ext2 partition of the compactflash card. For now, you can obtain an OS.IMG file from Psilinux Downloads (originally from Debian linux on netbook). Repartition the CF and install the linux filesystem as described above. Then remove the power and batteries from your netBook for a moment. When you power up again, the new OS.IMG should boot, mount your linux filesystem, and start linux...no fuss, no muss! The kernel, initrd and Arlo can be dispensed with using this approach.

5.7. Appendix: The /linuxrc script

I have used the following minimal script (on the initrd filesytem) to mount the CF partition, transfer root to it, and then start /sbin/init from the new root:

#!/bin/sh
#
# /linuxrc - run once at boot time

echo "Set the path" > /dev/console
# Set the path
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

# mount proc filesystem
mount -t proc /proc /proc

depmod -a

# the -o option causes cardmgr to run in the foreground
# and then exit when it is done configuring the disk.
cardmgr -o

echo "Mounting /dev/hda2 to /mnt/disk" > /dev/console
mount /dev/hda2 /mnt/disk

/bin/mount -o remount,ro /mnt/disk

echo "Executing pivot_root" > /dev/console
cd /mnt/disk
/sbin/pivot_root . old

exec /usr/sbin/chroot . /sbin/init <dev/console >dev/console

# The new system is now mounted as "/", with the old root system mounted
# to /old.  To free up the initrd memory, the startup has to umount /old/proc, 
# and then umount /old.