I am using an 8G CF card. (I was using dd to duplicate the card with
different size cards I was advised not to).
So I wrote the script below which basically:
1) runs fdisk to setup the device
2) makes the ext3 file system and the swap
3) mounts my old image "/" filesystem and the new partition
4) tar and untar the directories
5) run grub on it
6) set label for "/"
# mount the first partition in the image file
mount -t ext3 -o loop,offset=32256 ebox4300.centos.5.5.cf.img /mnt/from_image
mount -t ext3 $PARTITION_1 /mnt/to_image
# Directories to copy
for DIRECTORY in bin boot dev etc home install lib misc net opt root sbin selinux srv tftpboot tmp usr var
tar -cf - $DIRECTORY | (cd /mnt/to_image; tar -xpvf - )
# Skip these directories above and just make them for mounting