Reproducible Builds
When KIWI NG creates an image twice from the exact same root tree, for
example with kiwi-ng system build followed by kiwi-ng system create
on the resulting root tree, the two images are by default not bit
identical. The data files inside the image are the same, but many tools
involved in creating the image add data that changes with every call:
timestamps, randomly generated UUIDs, random salts or the order of
directory entries.
Enabling Reproducible Builds
KIWI NG follows the SOURCE_DATE_EPOCH specification. If the
environment variable SOURCE_DATE_EPOCH is set to a UNIX timestamp,
KIWI NG and the tools it calls use this value instead of the current
time, and derive identifiers from it instead of creating random ones.
If the variable is not set, nothing changes.
Set the variable for every KIWI NG call that creates image data. Note
that sudo removes environment variables by default:
$ export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)
$ sudo --preserve-env=SOURCE_DATE_EPOCH kiwi-ng system build \
--description <description> --target-dir <target>
$ sudo --preserve-env=SOURCE_DATE_EPOCH kiwi-ng system create \
--root <target>/build/image-root --target-dir <target2>
To find the remaining differences between two images, use a tool like diffoscope.
Warning
Without SOURCE_DATE_EPOCH, KIWI NG creates random identifiers on
purpose, such that two images never share them. With
SOURCE_DATE_EPOCH set, identifiers like filesystem UUIDs and GPT
partition GUIDs only depend on the value of SOURCE_DATE_EPOCH and
on names like the filesystem label. Two different images built with
the same SOURCE_DATE_EPOCH value and the same labels share these
identifiers. Do not attach such images to the same system at the
same time, or use different SOURCE_DATE_EPOCH values for them.
What KIWI NG Makes Deterministic
With SOURCE_DATE_EPOCH set, the following parts of an image no
longer change from build to build:
Component |
Handling |
|---|---|
Filesystem UUIDs |
Derived from |
ext2, ext3, ext4 |
The seed of the directory hash is set to the filesystem UUID
with |
FAT |
The volume ID is derived from the filesystem UUID. |
GPT partition table |
The disk GUID and the unique partition GUIDs are derived from
|
MBR disk identifier |
The disk identifier, also written to the |
dm-verity |
The salt and the UUID of the verity hash data are derived from
|
SquashFS |
|
EROFS |
|
ISO 9660 |
|
EFI FAT image of ISO media ( |
Created like FAT filesystems above. |
initrd |
|
tar archives |
Archive members are sorted by name, modification times newer
than |
cpio archives |
Archive members are sorted by name, and inode and device numbers of the build host are not stored. Requires cpio 2.12 or later. |
gzip compressed files |
The original file name and timestamp are not stored. |
xz compressed files |
|
OCI and Docker containers |
With the default |
Known Limitations
The following differences remain even with SOURCE_DATE_EPOCH set.
KIWI NG cannot remove them, because they are caused by the Linux kernel
or by the tools KIWI NG calls, or because they exist on purpose.
- Filesystems that are populated through a mount
For disk images, KIWI NG creates the ext2, ext3, ext4, XFS, Btrfs and FAT filesystems on a loop device, mounts them and copies the root tree into them. The kernel then writes the current time into the inode change time of every file and, for some filesystems, into the file creation time. It also records the mount and write times in the superblock and writes journal or log data. The placement of data blocks and inodes is decided by the kernel and can differ from run to run. Disk images with such filesystems are therefore not bit identical, even if all identifiers match. The same applies to the EFI system partition image created for the
systemd-bootbootloader, which is mounted to install the bootloader.If a bit identical disk image is required, create it with
systemd-repart, which populates the filesystems without a mount, see Building Disk Images with systemd-repart. This requires mkfs tools on the build host that supportSOURCE_DATE_EPOCH: e2fsprogs 1.47.1, btrfs-progs 7.3 and xfsprogs 6.18 or newer. Alternatively, use a read-only root filesystem that is created from the root tree without a mount: SquashFS or EROFS, for example withoverlayroot="true"for disk images or theisoimage type.- Files created in the create step
Files that KIWI NG writes into the root tree in the create step, like the bootloader configuration, carry the current time as their modification time. SquashFS, EROFS, ISO 9660 and tar archives clamp these times to
SOURCE_DATE_EPOCH. The systemd-repart disk builder clamps them in its staging directory as well. Filesystems populated through a mount and cpio archives keep them.- LUKS encryption
cryptsetupcreates a random volume key, random key slot salts and a random UUID. This is required for the security of the encryption, so encrypted images are never reproducible.- LVM
LVM creates random UUIDs for physical volumes, volume groups and logical volumes, and stores the creation time and the host name in its metadata.
- Software RAID
mdadmcreates a random array UUID and stores timestamps in the RAID superblock.- dm-integrity
KIWI NG does not set any identifiers for
integritysetup. It has not been verified whether its result is deterministic.- Disk formats created with
qemu-img The
vmdkformat, also used inovaimages and VirtualBox Vagrant boxes, contains a random content ID. Thevhdandvhd-fixedformats contain the creation time and a random UUID. Thevhdxandvdiformats contain random UUIDs. Theqcow2format and the raw disk image are not affected.- xz compression
The output of
xzdepends on the version ofxzand the caller options with regards to thread usage. KIWI NG makes explicitxzcalls in the build deterministic but tools which compress data themselves, use their ownxzsettings. KIWI NG covers this for known tools in the process likedracutormksquashfs. Should there be other tools part of the build process running axzbased compression task, this will make the build no longer deterministic.- Order of directory entries in the EFI FAT image
mcopycopies files in the order the filesystem of the build host returns them. Building on hosts with different filesystems can result in a different order of the entries in the EFI FAT image.- Versions of the build tools
Different versions of the tools on the build host, like
mkfs.*,xorriso,mksquashfs,grub2-mkimageor the compressors, create different results. Use the same build host environment, for example a container or theboxbuildcommand described in Alternative Build Methods, for builds that must be compared. With tar older than 1.29 or cpio older than 2.12, KIWI NG prints a warning and creates the archives without the reproducible options.