Posted by: Sue Loh
I attempted to document this behavior in the file that has become http://msdn.microsoft.com/library/en-us/wcedata5/html/wce50conUpgradingtheHiveBasedRegistry.asp. It is not very discoverable information though, I fear. And some of the information in that doc has gotten vague as more hands have crossed over it. I swear there used to be more information there, but it has disappeared into the void. Here I'll attempt to recreate it.
The system.hv and user.hv file on your device's persistent store are tied to default.hv and user.hv in ROM. All of these files have an MD5 hash of your "reginit.ini" file from your release directory stored in them. If you build a new image with a new system.hv/user.hv, then the MD5 hash in those files will be different than the hash in the ones on the persistent store. If you download the new image onto a device with persistent registry files that went along with a previous image, the persistent files will be deleted during boot. They MUST be deleted, really, because the persistent files contain many cross-links to the data inside the ROM files, which will be invalid if you change the ROM files. The registry would be severely broken. We don't delete the files just to be annoying, but because we have no choice.
You might find that on day-to-day rebuilds, you can keep your registry. That happens if you haven't changed any of the .reg files that go into your image, because reginit.ini would still be the same, so even if you rebuild new default.hv/user.hv files for ROM, they have the same hash stored inside them and the persistent files can still work. But as soon as you modify a .reg file, even just to add whitespace or comments, your persistent files will be wiped.
You actually have two options, if you need to update the image without losing the persistent registry.
Neither option is great, I know. The image update solution that is built into Windows Mobile 5.0 and that will possibly ** be available in future embedded releases deals with this problem basically by putting an empty default.hv/user.hv in ROM from the start, and importing everything during the first boot after an update.
** I have to say "possibly" because I can never promise what is going to be in future releases. I cannot guarantee anything.