2005年9月26日

Booting from CF card

Using CF card or micro hardisk to construct a simple embedded system:

1. Format CF card (The CF card is connected to Slave IDE-1.)
# fdisk /dev/hdc
// d 1 (Delete the partition)→ n (Create a new partition)→ w (Confirm the change and store the setting.)
# mke2fs /dev/hdc1 (Do Ext2 format) or
# mke2fs –j /dev/hdc1 (Do Ext3 format) or
# mkfs.ext3 /dev/hdc1 (Do Ext3 format)

2. Create new directories and files
# cd /mnt
# mkdir CF
# mount –t ext2 /dev/hdc1 CF
# mkdir CF/boot
# mkdir CF/boot/grub
# cp /boot/grub/* CF/boot/grub/
// Copy all grub relevance files to CF card.

3. Modify grub.conf and menu.lst
{
default=0
timeout=10
#splashimage=(hd0,0)/grub/splash.xpm.gz
title Embedded Linux On CF
root (hd0,0)
kernel (hd0,0)/boot/vmlinuz ro root=/dev/hdc1
#CF card is on Slave IDE,thus the root is /dev/hdc1.
initrd (hd0,0)/boot/initrd-new.img
}

4. Construct boot sector on CF card
# grub > root (hd1,0)
// Since the CF card is not current bootup hard disk, thus the parameter here is hd1, not hd0
// The fist is hd0, 2nd is hd1, ....
# grub > setup (hd1)
// Install grub to CF card.
# grub > quit

5. Create kernel image.
The CF card is on the same x86 machine, thus we can use the original vmlinuz image which is under /boot directory.

6. Create root file system.
The CF card is on the same x86 machine, thus we can use the original initrd image which is under /boot directory.