dm-verity for Rootfs Integrity: Design, Trust and Recovery
How to design and implement dm-verity-protected root filesystems for embedded Linux, covering hash tree generation, kernel integration, error handling, and update strategies.

dm-verity provides transparent block-level integrity verification for read-only filesystems. Every block read from disk is checked against a pre-computed hash tree. If a block has been modified - whether by an attacker, bit rot, or a failed flash write - the read returns an error instead of corrupted data. For embedded devices with immutable system partitions, dm-verity closes the gap between secure boot and runtime integrity.
Where dm-verity fits in the security chain
Secure boot (covered in the FIT signatures guide) verifies the kernel and initramfs at boot time. But once the kernel is running and mounts the root filesystem, there is no ongoing verification of the blocks read from storage - unless you add it.
dm-verity provides that ongoing verification. The chain becomes:
- ROM → verifies SPL
- SPL → verifies U-Boot
- U-Boot → verifies kernel + initramfs (FIT signature)
- Kernel → verifies root filesystem blocks (dm-verity)
This chain authenticates the selected boot objects and reads through the protected mapping. Downloaded applications, firmware outside that chain and writable execution paths require their own policy.
dm-verity vs fs-verity vs dm-integrity
| Mechanism | Protected scope | Trust requirement |
|---|---|---|
| dm-verity | Read-only block mapping | Authenticate the expected root digest and enforce use of that mapping |
| fs-verity | Selected files made read-only on a supported filesystem | Authenticate file digests and enforce execution policy. Names and ordinary metadata remain outside its protection |
| dm-integrity | Integrity tags for writable sectors | Unkeyed checksums detect accidental corruption. Keyed HMAC or appropriate dm-crypt integration has different authentication properties |
Consider an illustrative device with an immutable operating-system image, separately delivered applications and writable state. dm-verity can protect the OS image. fs-verity can protect selected application file contents where the filesystem and loader policy support it. Writable state needs its own integrity and recovery design. Key protection, replay protection and application-level consistency remain separate questions. fs-verity and dm-integrity.
How dm-verity works
dm-verity uses a Merkle tree (hash tree) computed over the filesystem image. The tree structure:
- Data blocks: The actual filesystem content, divided into fixed-size blocks (typically 4096 bytes)
- Hash blocks: Each hash block contains the hashes of multiple data blocks
- Higher-level hash blocks: Each higher level hashes the blocks below it
- Root hash: A single hash at the top of the tree
The root hash is the trust anchor. If you know the root hash is correct (because it was signed or embedded in the verified kernel command line), dm-verity can verify every block on demand.
Generating the hash tree
Use veritysetup from the cryptsetup package:
# Create the hash tree
veritysetup format /path/to/rootfs.img /path/to/rootfs.hashtree
# Output includes:
# Root hash: 4a2c...
# Salt: 8b1f...
# Data blocks: 65536
# Hash algorithm: sha256
The root hash and salt must be recorded and passed to the kernel at boot time. Store the expected digest in an authenticated boot object and confirm that the enforced boot flow uses it. Record the format output and image size so the table geometry comes from the actual image.
Kernel command line integration
The following is an illustrative table layout. It has not been executed as an integrated boot sequence here. Replace all geometry with the output from your image and validate in a disposable environment:
root=/dev/dm-0
dm-mod.create="verity,,,ro,0 524288 verity 1 /dev/mmcblk0p2 /dev/mmcblk0p3 4096 4096 65536 1 sha256 ROOT_HASH SALT"
Replace ROOT_HASH and SALT with the values from veritysetup format. The command line parameters specify:
- The data device (
/dev/mmcblk0p2) - The hash device (
/dev/mmcblk0p3) - Block sizes (data and hash)
- Number of data blocks
- Hash algorithm
- Root hash and salt
A FIT signature does not automatically authenticate every boot argument. Trace the root digest from a verified object through the actual boot script and environment. Prevent mutable arguments from replacing that digest or bypassing verification.
Initramfs-based setup (recommended)
For more flexibility, set up dm-verity in the initramfs:
#!/bin/sh
# In init script
set -eu
: "${ROOT_HASH:?Missing authenticated root digest}"
if ! veritysetup open /dev/mmcblk0p2 rootfs /dev/mmcblk0p3 "$ROOT_HASH"; then
echo "Root verification setup failed" >&2
exit 1
fi
if ! mount -o ro /dev/mapper/rootfs /newroot; then
veritysetup close rootfs
echo "Verified root mount failed" >&2
exit 1
fi
exec switch_root /newroot /sbin/init
# A failed exec must terminate in the recovery environment.
exit 1
This illustrative fragment stops on mapping and mount failures. A supervisor or explicit boot recovery mechanism must handle failure. If this script is PID 1, exiting can panic the kernel; exit alone is not a recovery mechanism. Select a known signed recovery image, retain the failure reason and stop automatic retries after the configured limit. The snippet has not been boot-tested here and requires integration with the target init system.
Filesystem choices for dm-verity
dm-verity requires a read-only filesystem. Common choices:
- SquashFS: Compressed, widely supported, good tool ecosystem. Typical for embedded systems with flash storage constraints.
- EROFS: Evaluate compression and workload behaviour using the EROFS vs SquashFS comparison and benchmark method.
- ext4 (read-only): An ext4 image mounted read-only works with dm-verity but offers no compression. Useful when you need ext4 tooling compatibility.
Error handling strategies
The kernel dm-verity interface documents default I/O errors and optional restart_on_corruption and panic_on_corruption behaviour. These are mapping options. Configure the selected cryptsetup and kernel versions together and test the resulting table. A generic kernel parameter cannot stand in for this integration. Kernel dm-verity documentation.
Store bounded failure information outside the failing root mapping where possible. A panic can prevent userspace from writing a log. Test what your persistent console or bootloader records. Recovery should select an independently authenticated image, limit retries and provide an operator-visible failure if both slots fail.
Optional forward error correction needs its own generated metadata and measured allocation. Record the correction parameters and test corruption both within and beyond the configured correction capacity. Successful recovery still depends on a trusted expected digest.
Update strategies with dm-verity
Since dm-verity protects a read-only image, updates mean replacing the entire image and hash tree. This aligns naturally with A/B update schemes:
- Download new rootfs image + hash tree to the inactive slot
- Authenticate the update manifest and verify its image and hash-tree digests
- Update the boot configuration to point to the new slot
- Reboot
Plan OTA updates with RAUC, SWUpdate and Mender together with the slot-specific hash tree and authenticated root digest.
Writable overlay for runtime data
A fully read-only root filesystem is impractical for most systems. Logs, configuration changes, and runtime state need writeable storage. The standard pattern is an overlayfs mount:
mount -t overlay overlay -o lowerdir=/rootfs,upperdir=/data/upper,workdir=/data/work /merged
The lower layer is the dm-verity-protected read-only image. The upper layer is on a separate, writable partition. Changes appear in the upper layer without modifying the verified lower layer. Executables in that writable upper layer do not inherit authentication from dm-verity. Restrict execution sources or enforce an independent verification policy for updated applications.
Performance considerations
Measure the actual image, storage and workload with verification enabled. Retain cold and warm cache conditions, request sizes, kernel configuration and raw results. Account separately for image bytes, hash-tree bytes and any error-correction data. No general percentage predicts the cost on every device.
Use the boot-integrity review worksheet to record the trusted digest source and negative tests. Include changed image bytes, a wrong digest, mount failure and exhausted recovery attempts. Leave results pending until the complete boot path has been exercised.
Adoption across Linux distributions
dm-verity and immutable root filesystem patterns have become standard practice across modern Linux distributions. Distributions like Ubuntu Resolute Raccoon Features are increasingly shipping with immutable filesystem tooling and secure boot integration, reflecting how these patterns have moved from specialist embedded systems into general-purpose Linux environments. Understanding how these approaches work - and where their constraints lie - helps portable OS projects make informed architectural decisions.
Integration with ProteanOS
ProteanOS build workflows can integrate dm-verity hash tree generation as a post-build step. Review the ProKit documentation and selected source before assuming a post-processing interface exists.
For new hardware platforms, the board bring-up documentation includes dm-verity validation as a security milestone after basic boot and secure boot are working.
Summary
dm-verity provides runtime integrity verification for read-only root filesystems. Combined with secure boot, it can protect the explicitly verified execution path. The implementation involves generating a hash tree, passing the root hash through a verified channel (signed kernel command line or initramfs), and handling corruption gracefully. Plan your partition layout and update strategy around the read-only constraint from the start.