Main Page | Index

Axis Software User Manual


Creating a Bootable Compact Flash Device

This section describes how to use the following programs to install a bootable Linux onto a Compact Flash card:

The following assumes the use of a USB Compact Flash reader/writer. The Compact Flash reader/writer is included in the Axis Development Kit and is mounted as a virtual SCSI drive, being allocated to the block device /dev/sda. The first partition on this device is identified by an additional 1, so /dev/sda1 is the first partition. If your system associates the Compact Flash with a different device all references to /dev/sda and /dev/sda1 will need changing to reflect this.

The procedure also involves changing drive partition tables, formatting drives and installing a boot loader. Any of these operations if applied to the wrong disk drive can render the development machine unbootable or erase all the data on one of its disks. It is important to check each stage carefully.

In most Linux systems with IDE drives, the drives are named:

You will need to be logged on to the local root account on the development machine to perform these operations.

Converting a Compact Flash Device to Linux

Most Compact Flash devices seem to be supplied pre-formatted with FAT 16. To change to a native Linux file system, two operations need to be performed. Firstly, the partition table needs modifying and then the disk needs formatting with a more Linux friendly file system (Linux can work with FAT formatted drives but prefers to start from a Linux/Unix file system).

To change the partition table, issue the command:

fdisk /dev/sda (assuming that your flash drive is mapped to this block device)

Typing m prints a command menu:

Command (m for help): m
Command
Action
a
toggle a bootable flag
b
edit bsd disklabel
c
toggle the dos compatibility flag
d
delete a partition
l
list known partition types
m
print this menu
n
add a new partition
o
create a new empty DOS partition table
p
print the partition table
q
quit without saving changes
s
create a new empty Sun disklabel
t
change a partition's system id
u
change display/entry units
v
verify the partition table
w
write table to disk and exit
x
extra functionality (experts only)

The p command will print out the existing partition table for a typical device. The ouput should look like:

Command (m for help): p

Disk /dev/sda: 256 MB, 256376832 bytes
16 heads, 32 sectors/track, 978 cylinders
Units = cylinders of 512 * 512 = 262144 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 977 250096 6 FAT16

Before proceeding, check that the drive size matches what you would expect for the chosen Compact Flash device. If it does not match the required size, quit and double check that you have the correct drive.

The partition type needs changing from type 6 to type 83:

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 83
Changed system type of partition 1 to 83 (Linux)

The P command can be used to verify that the partition has been changed:

Command (m for help): p

Disk /dev/sda: 256 MB, 256376832 bytes
16 heads, 32 sectors/track, 978 cylinders
Units = cylinders of 512 * 512 = 262144 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 977 250096 83 Linux

To make the changes permanent use the w command:

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.

Warning: If you have created or modified any DOS 6.x partitions, please see the
fdisk manual page for additional information.

Syncing Disks

The next stage is to format the flash disk with a native Linux file system. At this stage several possibilities exist. Ext2, Ext3, ReiserFS, JFS or XFS are all candidates.

Further the kernel chosen must have support for that file system compiled in. It makes sense to ensure that both the target platform and the development system kernels have support for the chosen file system included so both can read and write files in the Compact Flash device.

All the file systems should perform admirably. However, as the system is likely to encounter power failures, a journalling system is to be preferred (operation with a read only file system should be possible but Heber has not tried this). Ext3 should be used in preference to Ext2. After an unscheduled power down on an Ext2 fsck will need running and this may take sometime. The other four file systems perform metadata journalling and should be able to recover from a power failure in a few milliseconds.

Note: Journalling file systems protect there metadata against power down not your application data so software still needs to take precautions. Web searches will reveal many different opinions as to the best system and file system performance is related to file sizes and usage patterns.

Ext3 can be thought of as the same as Ext2 but with the addition of metadata journalling.

The command to create a file system varies on the chosen file system.

mkfs can be used as a front end and the system type specified with the -t parameter

To make a Reiser base use the mkreiserfs command.

This example shows converting a flash drive to reiserfs:

linux:# mkreiserfs /dev/sda1
mkreiserfs 3.6.4 (2002 www.namesys.com)
mkreiserfs: Guessing about desired format.
mkreiserfs: Kernel 2.4.20-4GB is running.
Format 3.6 with standard journal
Count of blocks on the device: 62524
Number of blocks consumed by mkreiserfs formatting process: 8213
Blocksize: 4096
Hash function used to sort names: "r5"
Journal Size 8193 blocks (first block 18)
Journal Max transaction length 1024
inode generation number: 0
UUID: 3a3c50a9-5162-4ae1-b991-75afdbc731ce
ATTENTION: YOU SHOULD REBOOT AFTER FDISK!
ALL DATA WILL BE LOST ON '/dev/sda1'!
Continue (y/n):y
Initializing journal - 0%....20%....40%....60%....80%....100%
Syncing..ok
Please visit www.namesys.com for information about ReiserFS sponsors

This should take no more than a couple of minutes for a 256 MB card. Before the card can be accessed it needs mounting in the Axis Development Kit. The chosen mount point is /media/sda1. If yours is different, you will need to adjust accordingly.

linux # mount -tauto /dev/sda1 /media/sda1
linux #

This command can take a few moments to execute.

Once the Compact Flash has been mounted then the base file system can be created. Mostly this is outside the scope of this document. However several entries are needed in the file system.

The current systems use Lilo as a boot manager, this needs to read a file called lilo.conf from the /etc directory on Compact Flash. Both of these need creating.

To make the /etc directory for the target Compact Flash, issue the command:

 mkdir 

to create the path to the Compact Flash. Then inside the new /etc directory create a new file called lilo.conf or target.lilo.conf

A basic lilo.conf might be as follows:

boot = /dev/sda
disk = /dev/sda
bios =0x80
image = /boot/bzImage
root =/dev/sda1
append =""
label = Linux
read-only

Lilo also needs to access several raw devices and it tries by going through the dev directory on the Compact Flash card.

The following commands should solve this:

mkdir $EMBEDDED_ROOT_DIR/dev
mknod -m660 $EMBEDDED_ROOT_DIR/dev/sda b 8 0
mknod -m660 $EMBEDDED_ROOT_DIR/dev/sda1 b 8 1

The desired kernel image should be copied to the boot directory along with its map file. This path must match the image parameter in lilo.conf.

Once the kernel image is in place, lilo.conf in place and the correct device files entered into the flash dev directory, Lilo can be called. It seems to work best if invoked with the root of the Compact Flash as the current directory.
So:

cd $EMBEDDED_ROOT_DIR
lilo -r /media/sda1 -C etc/target.lilo.conf

As usual, keep checking that the program is running from the expected directories. Lilo will take several seconds to run.

Once Lilo has finished, call umount, so the Compact Flash card's buffers are synced. If the umount was successful, the Compact Flash card can be removed and tried in the Axis board.

umount /media/sda1

If any programs have files (or directories) open on the Compact Flash card, umount will fail. If a failure occurs either close the programs down or change directory and then try again.


© HEBER LTD. 2005. This document and the information contained therein is the intellectual property of Heber Ltd. and must not be disclosed to a third party without consent. Copies may be made only if they are in full and unmodified. The information contained in this documentation is believed to be accurate and reliable. However, Heber Ltd. assumes no responsibility for its use, and reserves the right to revise the documentation without notice.
Document No: 80-17794, Issue 4r1    Release Date: 01.12.05     Email: support@heber.co.uk    www.heber.co.uk