i know whats the problem
at first, you do the fdisk stuff, then you do something else and then you overwrite the mbr with the grub stuff and your overwrite the created partition entries. thats the fault, because with the next boot, the partition values stored in grub.mbr are used. so first do the grub stuff and then use your fdisk script. take care that the partition table in grub.mbr is empty.
a few hints:
1) do not use fixed head start values in the fdisk script, use the value that fdisk says with an empty line
2) you do syncs and sleeps. sync forces to finish all writes from ram to the device. sync is not needed because an umount does the sync automatically before it releases the device. so you can remove the sleeps and syncs.
edit:
btw, when you want to use the partition values stored in grub.mbr then simply use this after you wrote grub.mbr
fdisk $DEVICE_GRUP << EOF
w
EOF
that the system loads the partition values
regards
elmar