| Persistent Registry: Hive-Based Images
ADS CE 4.x and 5.0 images built since 2004 use hive-based registries. Hive-based images save updates to the device's registry on the flash disk in conventional system files [MSDN article 322269]. With a single API call, Windows CE will persist all registry changes.
- The Hive-based registry is stored in hidden .hv files under the "\FlashFX Disk\Documents and Settings\" folder.
- To save the latest changes to the registry, call the RegFlushKeys() API. Applications that call this API include the CAB file installer (wceload.exe), putting the system to sleep and the \Windows\RegFlushKeys.exe app included on most ADS systems.
- The registry is stored as a diff from the base, system registry reginit.ini, which comes packaged as an informational file with each CE build
- The hive files can be erased manually, if they are not in use. CE seems to keep the user hv file open all the time, so you may need to unmount and remount the disk to be able to delete some hv files.
- CE currently erases the persistent registry every time you load a new CE build (detects that the base registry, reginit.ini, has changed).
Edited by akidder 28-Mar-2006: Add the Details section, above.
Edited by akidder 12-Jul-2007: Make this the topic index for Persistent Registry. Add note about RegFlushKeys() API. Change title from "Hive-Based Registry". Add backslashes back to paths.
Here is some further reading from MSDN about hive-based registries:
- Windows CE .NET 4.0 supports two different registry types: the object-store-based registry and the hive-based registry.
The object-store-based registry stores all registry data within the object store. This is efficient in terms of speed and size in devices that have battery-backed RAM. Devices that do not power the RAM while turned off must back up the registry during power off and restore the registry when power is restored.
The hive-based registry stores registry data inside files, or hives, which can be kept on any file system. This removes the need to perform backup and restore on power off.... The hive-based registry is intended for use on devices that cold boot often, but rarely or never warm boot.
full MSDN article
- A registry hive is a group of keys, subkeys, and values in the registry that has a set of supporting files containing backups of its data.
full MSDN article 256986
- No work is necessary on boot or shutdown to preserve registry data, with the possible exception that the OEM may need to flush the registry using RegFlushKey if a typical software shutdown is not done.
Some additional options are available if the OEM wants to perform a final backup. This may be necessary if the data stored in the registry renders the system somehow not viable. In this case, the OEM can use RegSaveKey to save a known viable registry, and use RegReplaceKey to restore it. This solution requires a system reboot after calling RegReplaceKey, but should only be necessary in rare cases.
RegSaveKey operates on one hive at a time; calling this API on HKEY_LOCAL_MACHINE will save the system hive to a file, and calling it on HKEY_CURRENT_USER will save the current user's hive. Conversely, RegReplaceKey can only be used with HKEY_LOCAL_MACHINE. It replaces the system hive only. To replace a user hive, the OEM may call SetCurrentUser with a NULL user name to log off the current user, and then call CopyFile to replace the user's invalid hive with a saved known viable hive.
Another case in which last known good support is useful is the case in which the registry hive files become corrupted, perhaps by a file system error. When the system detects a corrupt hive file during boot, the file is deleted and a clean one created in its place. This enables the system to boot successfully. You can detect this event by looking for a particular value under HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER, as shown in the following registry key example.
If this value is present under HKEY_LOCAL_MACHINE, it indicates that the system hive has been restored successfully. If it is present under HKEY_CURRENT_USER, it indicates that the user hive was successfully restored. Its absence indicates a clean boot, in which case the hive was created new. If the value is absent, you can set up verification for this value and restore a stored last known hive.
full MSDN article
- The system hive contains system settings that do not pertain to any one user. The OEM selects the system hive file name and location. The system hive file is typically named System.hv, but the location may vary.
By default, the system and user hives are separated into two locations. When the system boots, it reads the ROM-based version of the hives. Any change to the registry data is written to the hive that exists in the file system. On a cold boot, the portion of the registry that is stored in a file system is essential empty until a write operation occurs.
full MSDN article