Remote Upgrade Using RTP

Hi all,
I’m trying to find out a way to do remote upgrading for embedded system.
This is how I’m doing it now. Plz note that I have 2 hard disk in the
machine… a compact flash hard disk & a normal hard disk.
1)A tar file consisting of the upgraded OS and neccessary
applications(around 25mb before tar) will be sent down from the server to
the machine harddisk.
2)The machine will mount harddisk as ‘/’ instead of the compact flash
harddisk during the next bootup but it’s still booting up from the compact
3)The boot image will call a program to untar the tar file into a temp dir
and copy the contents over to the compact flash using ‘cp -c -L -R’ command
thus overwriting all data in it.

The problem is during the testing,‘cp’ fails almost EVERYTIME. I can’t
remember the lengthy error message generated but it’s something like " Unable to create destination file!
…… Corrupted filesystem detected!". When I tries to run the copy
command manually, everything works fine. Eventually, I decide to use tar
instead of cp. Instead of untar-ing the tar file into a temp dir, I untar
the contents straight onto compact flash, overwriting all data in it. Though
error messages similiar to ‘Corrupted file detected’ are spotted during the
untar process at times(and discovered either some dirs/files are not copied
over or corrupted files are detected), it actually works at times! The
files/dirs affected are not fixed, sometimes /usr/sbin doesn’t even exist
after untar, sometimes a devg_t is created in /etc/skels(can anyone tell me
what is it? There is NO such file existing in source dir!). Can anyone