Tuesday, November 09, 2010

Repairing TCT CF disk

The TCT uses Compact Flash (CF) as it's storage device, the CF technology is cheap now. Depends on CF quality, CF operate in variety of speed, some well known manufacturer produce high-speed transfer rate CF. TCT uses Sandisk Ultra CF which expected to work at 15MB/s theoretically.

Like another flash-based memory that use NAND, beside it has write cycle endurance it also being sensitive with electro static and improper handle. Many TCT's CF were suffer from this, fortunately, this problem didn't affect all memory part of the CF, usually errors only located on several block segment.

First for all notice that in this writing, the CF has master disk with device's name /dev/sdc, to diagnose the bad block, we need to scan the broken CF then it should show up some warnings, maybe something like these

#e2fsck /dev/sdc1
Buffer I/O error on device sdc, logical block 1082045
end_request: I/O error, dev sdc, sector 1082045
Buffer I/O error on device sdc, logical block 1082050
end_request: I/O error, dev sdc, sector 1082050

Now we know the damaged block, with fdisk we can create a partition with this trick.

Let assume the CF has 1964088 logical block, we noticed in above e2fsck log that blocks upto 1082044 were unusable, we can safely create a partition which has about 1082044 logical block by set the last logical block equal or less than 1082044.

#fdisk /dev/sdc

Command (m for help): u
Changing display/entry units to sectors
Command (m for help): n
Command action
e extended
p primary partition (1-4)
Partition number (1-4): 1
First sector (62-15761087, default 62):
Using default value 62
Last sector, +sectors or +size{K,M,G} (62-1964088, default 1964088): 1082044
The partition table has been altered!

After the new partition has been created, first make sure the partition boot flag also already been activated with fdisk, then create the root filesystem of type ext3 with

#mke2fs -j /dev/sdc1

We need to extracting tar.gzip'ed TCT root filesystem to the partition with

#mount -t ext3 /dev/sdc1 /mnt
#tar xzf tct-rootfs.tar.gz -C /mnt

The tar.gzip'ed root filesystem created by compressing a previously working filesystem, assuming that the current working directory is the root directory of working filesystem.

#tar czf /path/to/save/tct-rootfs.gz .

Now we have a working root filesystem, but one feature that is still missing is bootloader, using GRUB is very complicated, why not use a small and simple bootloader EXTLINUX, from this time the TCT system should use EXTLINUX instead GRUB.

#extlinux --install /mnt/boot
#cat /usr/lib/syslinux/mbr.bin > /dev/sdc

Create a simple configuration file, similar to syslinux configuration file. Use blkid to retrieve device UUID.

# /boot/extlinux.conf
KERNEL /vmlinuz
APPEND initrd=/initrd.img root=UUID=06e8bee6-ad09-41e8-8290-87ef6aa71df8 ro quiet vga=0x314 8250.nr_uarts=12

Unmount and test for it, hopefully it should works!

When working with this problem, I made stupid thing by rm -rf /media, this fuck my important data.