Tinycore: Compact Flash Install 

Installing Tinycore on to a Compact Flash card (or Pen Drive)


This how-to covers the installation of Tinycore Linux onto a Compact Flash card. At the time of writing I was creating a system for the VXL Percio which has an onboard Compact Flash socket - hence the choice of a Compact Flash card. It is equally applicable to a USB pen drive.

It has been written on the assumption that, for one reason or another, the installation cannot be performed on the target system. Therefore we're using another computer running Linux to prepare the card. This computer may be running Linux natively, or it may be running one of the many 'Live' distributions from CD or USB.

At the time of writing the Tinycore release was 3.4.


You will need:

  • A suitable Compact Flash Card
  • A computer running Linux
  • A Compact Flash reader/interface

My Linux system is currently running Fedora Core 14 and the description below is based on that. There will be variations for users of alternative Linux distributions.

Compact Flash Configuration

In it's simplest form a Tinycore Linux system comprises the kernel (bzImage), an initrd (tinycore.gz) and a few boot files. Subsequently applications are installed from the internet once the system is running. These applications can be made 'permanent' by storing them on the Compact Flash card in a tce directory or by 'remastering' the tinycore.gz file.

So, as a minimum, we need storage space for the base Tinycore files (~10MB) and also any applications we want permanently installed. In this example we'll pick on 16MB as a suitable size. You can of course use much larger cards, and in those cases you can either increase the size of the first partition and/or create additional partitions on the Compact Flash card for whatever user data you have.

So our aim is to create a 16MB partition (/dev/sda1) on a Compact Flash card containing the Tinycore system files. (There is no reason why you can't increase or decrease this size if that better suits what you want to do or have to hand).

Initial software Downloads

We require the following software on our development system:

  • The tinycore ISO file.
  • Grub 0.9 utilities.

As a normal user on your Linux system create a directory for this work say tc_cf

Go to the Tinycore download site and download the tinycore-current.iso file.

We're going to use grub as the boot loader. Whilst my Fedora box has grub installed, the release appears to be Fedora specific and is missing one essential file. We can fix this by using the tinycore grub distribution. Go to a Tinycore repository to download the file grub-0.97-splash.tcz.

Setting up the Compact Flash card

Note: For most of the following we need to be root or running as a user with root privileges. In Fedora I just open a terminal and then do an su and type in the root password. It may be different in your Linux environment. You may have to prefix some of the commands with sudo though be aware that if the sudo command is available to you then sudo su - should get you logged in as root.

Once you're logged in as root remember that you any thoughtless action may damage your system - you could delete or overwrite critical system information. Check that you've got it right before you hit the return key!

Step 1. Find your Compact Flash card.

Place the Compact Flash card into your reader (or what ever alternative interface you are using) and connect it to the USB port on your computer. The reaction you get at this point will depend on your flavour of Linux and whether or not the Compact Flash card you are using is formatted. The key thing is to see what has appeared in the system log file. In my case, having typed dmesg, I find that file ends:

[23975.679092] scsi 6:0:0:0: Direct-Access     Generic  Storage Device   0.00 PQ: 0 ANSI: 2
[23975.680417] sd 6:0:0:0: Attached scsi generic sg3 type 0
[23975.682693] sd 6:0:0:0: [sdc] 62976 512-byte logical blocks: (32.2 MB/30.7 MiB)
[23975.688341] sd 6:0:0:0: [sdc] Write Protect is off
[23975.688351] sd 6:0:0:0: [sdc] Mode Sense: 03 00 00 00
[23975.688357] sd 6:0:0:0: [sdc] Assuming drive cache: write through
[23975.692068] sd 6:0:0:0: [sdc] Assuming drive cache: write through
[23975.692083]  sdc: sdc1
[23975.698122] sd 6:0:0:0: [sdc] Assuming drive cache: write through
[23975.698133] sd 6:0:0:0: [sdc] Attached SCSI removable disk

i.e. My Compact Flash card has appeared as /dev/sdc. It may be different in your case. What ever it is note it down and use your version where ever you see /dev/sdc in the text below.

Having found the card we now need to partition it, format it, transfer the system files onto it and make it bootable.

Step 2. Ensure it is NOT mounted.

Run mount to see if your system has automounted any partitions on the Compact Flash card. If any partitions from it appear in the listing unmount them before proceeding.

[root@mantaray tc_cf]# umount /dev/sdc1

Step 3 Create the partition.

Run fdisk or cfdisk to create a single small partition at the start of the card. If you want you can create further partitions at this stage, but in this example we're only creating a single 16MB partition at the start of the Compact Flash card.

[root@mantaray tc_cf]# fdisk -u -c /dev/sdc

Command (m for help): p

Disk /dev/sdc: 32 MB, 32243712 bytes
4 heads, 32 sectors/track, 492 cylinders, total 62976 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *          32       62847       31408    4  FAT16 <32M

Command (m for help): d
Selected partition 1

At this point we have an empty card. We're now going to create a single primary Linux partition of 16MB and mark it as bootable.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
Partition number (1-4, default 1): 1
First sector (2048-62975, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62975, default 62975): +16M

Command (m for help): a
Partition number (1-4): 1

Command (m for help): p

Disk /dev/sdc: 32 MB, 32243712 bytes
4 heads, 32 sectors/track, 492 cylinders, total 62976 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *        2048       34815       16384   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@mantaray tc_cf]# 

Step 3 Format the partition.

I've picked on an ext2 file system. While it has been mostly supplanted by versions 3 and 4, ext2 is a reasonable choice for solid-state devices such as Compact Flash. This is because it does not have a journaling function, so it generally makes fewer reads and writes to the drive, effectively extending the life of the device. Also, our root partition will be rarely written to and we don't need resilience of a journaling file system that's designed to recover from things like power failures in the middle of disk writes.

[root@mantaray tc_cf]# mkfs.ext2 -L TINYCORE /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=TINYCORE
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
4096 inodes, 16384 blocks
819 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=16777216
2 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 

Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@mantaray tc_cf]# 

Step 4 Copy over the Tinycore files.

We do this by mounting the tinycore.iso image and the Compact Flash card and then copy over the files from one to the other. In Fedora mount points appear in the /media directory so I'll use that. You obviously can use what ever you choose. I picked on mount points of cf for the Compact Flash card and tc for the Tinycore iso image.

[root@mantaray tc_cf]# mkdir /media/tc /media/cf
[root@mantaray tc_cf]# mount -o loop tinycore-current.iso /media/tc
mount: warning: /media/tc seems to be mounted read-only.
[root@mantaray tc_cf]# mount /dev/sdc1 /media/cf
[root@mantaray tc_cf]# mkdir -p /media/cf/boot/grub
[root@mantaray tc_cf]# cp -p /media/tc/boot/* /media/cf/boot
cp: omitting directory `/media/tc/boot/isolinux'

We create a tce entry for persistence of anything we might install - such as keymaps for non-us keyboards.

[root@mantaray tc_cf]# mkdir -p /media/cf/tce
[root@mantaray tc_cf]# touch /media/cf/tce/mydata.tgz
[root@mantaray tc_cf]# 

Step 5 Install Grub.

The last step is to install the boot loader grub. We need to copy the appropriate files to the grub directory on the Compact Flash card. The files may already be available as part of your distribution and can be copied over from there. If, like me, you are working with the Tinycore grub-0.97-splash.tcz file, this is actually a squashfs file and so can be mounted. In this particular case I mounted the file on /tmp/grub

[root@mantaray tc_cf]# mkdir /mnt/grub
[root@mantaray tc_cf]# mount -o loop grub-0.97-splash.tcz /mnt/grub
mount: warning: /mnt/grub seems to be mounted read-only.
[root@mantaray tc_cf]# ls /mnt/grub/usr/lib/grub/i386-pc/
e2fs_stage1_5  ffs_stage1_5      jfs_stage1_5    reiserfs_stage1_5  stage2           ufs2_stage1_5    xfs_stage1_5
fat_stage1_5   iso9660_stage1_5  minix_stage1_5  stage1             stage2_eltorito  vstafs_stage1_5

Having mounted it we then copy the files over to the Compact Flash card.

[root@mantaray tc_cf]# cp -p /mnt/grub/usr/lib/grub/i386-pc/* /media/cf/boot/grub/
[root@mantaray tc_cf]# 

With the files in place we need to add a simple boot menu. You can either do this in the terminal window using vi or use an editor within your Linux system. In the latter case you'll probably have permission problems as these files and directories are owned by root. Create the file /media/cf/boot/grub/menu.lst with the contents:

default 0
timeout 10
title tinycore
kernel /boot/bzImage quiet
initrd /boot/tinycore.gz

Note: I subsequently found that the version of Grub I used was actually looking for grub.conf. Create a link so that both filenames are there but are actually the same file:

ln -T /media/cf/boot/grub/menu.lst /media/cf/boot/grub/grub.conf

Next there is a slight complication in that grub kind-of assumes that you're installing it on the system that it's going to run on. In our case this isn't so. Whatever the Compact Flash card is appearing as now, once we plug it into the target system it will become (hd0) and our boot partition will be (hd0,0). Luckily this is easily solved by creating a mapping file and telling grub to use that.

In the tc_cf directory type:

[root@mantaray tc_cf]# echo '(hd0) /dev/sdc' >grub-device.map

What this single line text file does is to tell grub that, whilst we're installing it, for anything it does on (hd0) it should use the linux device /dev/sdc (i.e. our Compact Flash card).

We can now run grub and tell it to use our device map file:

[root@mantaray tc_cf]# grub --device-map=grub-device.map 

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]

Next we tell grub that we want to boot the operating system on the first partition on the first disk. In grub terms this is partition 0 on disk 0.

grub> root (hd0,0)
root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

Note at this point you do get confirmation that all is looking good. Grub has had a look and is telling us that the root file system we've selected - (hd0,0) - is an ext2 one. On my Fedora system the main file systems are all ext4. Hopefully it is similar in your case. If you see something other than ext2fs then STOP. Quit grub and correct your mistake.

If all looks ok then carry on with installing grub:

grub> setup (hd0)
setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  15 sectors are embedded.
 Running "install /boot/grub/stage1 (hd0) (hd0)1+15 p (hd0,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
grub> quit
[root@mantaray tc_cf]# 

You now have a Compact Flash that should boot Tinycore kernel when connected to the IDE interface on a thin client (or any other computer come to that).

We can now umount all our various file systems.

[root@mantaray tc_cf]# umount /mnt/grub
[root@mantaray tc_cf]# umount /media/cf
[root@mantaray tc_cf]# umount /media/tc
[root@mantaray tc_cf]# 

Remove the Compact Flash card and label it.



Any comments? email me.    Last update January 2011