Compact Flash Linux - Part 2

Printer-friendly versionSend by emailPDF version

In the first part of the series, we have shown how to install Debian Linux on a compact flash in one of our system: the OpenBrick-E 600Mhz Celeron-M. In this second installment, we will show how to configure Linux to minimize the "wear-and-tear" of a compact flash. Similar strategy is used in Embedded Linux areas. The next part, the third of the series, describes the setup of a Java Application Server; specifically the OpenVPN-ALS, used to be called Adito, which provides the SSL VPN services.

Our strategy is rather simple. There are many places on the filesystem that will experience a lot of updates, specifically the /var/log and the /var/spool directories. We will move these into the tmpfs which is like a ramdisk.

So, the first thing we did after the first boot up is to create a /var/log_compressed directory to store the compressed log and spool files. You will probably recognize that we have "borrowed" this idea from the IPCop people.

#mkdir /var/log_compressed
#tar czf /var/log_compressed/log.tgz /var/log/*
#tar czf /var/log_compressed/spool.tgz /var/spool/*

Then, we create a start-up file. The purposes of the start-up file /etc/init.d/flash-up is to:

  1. During boot up, it copies the compressed log and spool files to the ramdisk.
  2. During shutdown, it makes copies of the current log and spool directories and stores them back on the flash drive.

#cat >/etc/init.d/flash.up <<EOF
#! /bin/sh
# /etc/init.d/flash.up
#

# Some things that run always
touch /var/lock/flash.up

# Carry out specific functions when asked to by the system
case "\$1" in
start)
echo "Starting script flash.up "
cd / ; /bin/tar xzf /var/log_compressed/log.tgz
cd / ; /bin/tar xzf /var/log_compressed/spool.tgz
echo "Completing untar the log and spool files to ram disk..."
;;
stop)
echo "Stopping script flash.up"
/bin/tar czf /var/log_compressed/log.tgz --exclude=/var/log/cache/* /var/log/*
/bin/tar czf /var/log_compressed/spool.tgz /var/spool/*
echo "tar the log and spool files from ram disk to /var/log_compressed..."
;;
*)
echo "Usage: /etc/init.d/flash.up {start|stop}"
exit 1
;;
esac

exit 0
EOF

And make it a start-up file the "Debian" way.

#chmod 7555 /etc/init.d/flash.up

#update-rc.d flash.up defaults 10

Since we also want to keep a record of the log and spool directories, a cron is configured to back them up once every hour onto the flash memory.

#cat >/etc/cron.hourly/logcompressed <<EOF
#!/bin/sh

test -x /bin/tar || exit 0

# Backup logs to flash
/bin/tar -czf /var/log_compressed/log.tgz --exclude=/var/log/cache/* /var/log/*
/bin/tar -czf /var/log_compressed/spool.tgz /var/spool/*
EOF

Remember to make the cron file executable or it does not work!

#chmod a+x /etc/cron.hourly/logcompressed

Following are the changes to the /etc/fs:

  1. Mount the following filesystem on tempfs:
    • /tmp
    • /var/log
    • /var/tmp
    • /var/run
    • /var/lock
    • /var/spool
  2. Add "noatime" to any writable filesystems

See screenshot!

 

The final step is optional. Logrotate is used to make a backup of the log and spool once a day.

#cat >/etc/logrotate.d/logcompressed <<EOF
/var/log_compressed/log.tgz
{
rotate 2
daily
missingok
postrotate
/bin/tar -czf /var/log_compressed/log.tgz --exclude=/var/log/cache/* /var/log/*
endscript
notifempty
nocompress
}

/var/log_compressed/spool.tgz
{
rotate 2
daily
missingok
postrotate
/bin/tar -czf /var/log_compressed/spool.tgz /var/spool/*
endscript
notifempty
nocompress

}
EOF

Make sure to reboot after all of the changes!

Downloadable Compact Flash Images

The Compact Flash Linux images can be downloaded from http://www.hacom.net/catalog/pub/debian. They are similar to what was outlined in these articles. Except, they were actually built using debootstrap.

Conclusions:

Using some of the simple changes, we have limited the writes onto the compact flash about once an hour. Even with the 100,000 lifetime re-write cycles, it should last more than 10 years. Our compact flash Linux is working in similar fashion as a "standard" flash-based embedded Linux system. The main difference is that we have more available flash memory. In most embedded systems, since flash memory is limited, they tend to use the wear-leveling technology in a filesystem like jffs2, to lengthen the live of flash memory.

For the compact flash Linux, further optimization would be to mount the root filesystem as read-only. Our experience has indicated that it is not neccessary.

Now, we can start to install packages to make the compact flash Linux into: firewalls/routers, database server, web server, or Java application server. The next part of the series does just that. It describes the setup of a Java Application Server; specifically the OpenVPN-ALS, used to be called Adito, which provides the SSL VPN services.

Knowledge Base: