@@ -19,16 +19,34 @@ install -m0644 "$kernel" "$OUT/files/bzImage"
1919
2020# Combined squashfs + dm-verity tree, matching Yocto's separate-hash=0 output.
2121rootfs=" $OUT /files/rootfs.squashfs.verity"
22+ sort_file=" $OUT /.squashfs-sort"
2223# mksquashfs -noappend overwrites its filesystem but does not reliably remove
2324# a longer dm-verity tail left by a previous invocation.
2425truncate -s 0 " $rootfs "
26+ # mksquashfs otherwise uses source-directory inode order as a tiebreaker. That
27+ # order differs between overlayfs/user-namespace and privileged CI builds even
28+ # when every path, mode and file byte is identical. Give every path a stable,
29+ # unique priority so packing order is independent of the backing filesystem.
30+ find " $TREE " -mindepth 1 -printf ' %P\n' | LC_ALL=C sort > " $sort_file .paths"
31+ if grep -q ' [[:space:]]' " $sort_file .paths" ; then
32+ echo ' rootfs paths containing whitespace are unsupported by mksquashfs -sort' >&2
33+ exit 1
34+ fi
35+ if (( $(wc - l < "$sort_file .paths") > 65535 )) ; then
36+ echo ' rootfs has too many paths for unique mksquashfs priorities' >&2
37+ exit 1
38+ fi
39+ awk ' { print $0, 32767 - NR }' " $sort_file .paths" > " $sort_file "
40+ rm -f " $sort_file .paths"
2541# Privileged mkosi runs can inherit host default ACLs from their workspace.
2642# The guest rootfs does not rely on xattrs, so exclude this host-only metadata.
2743# A single compressor worker also avoids host-CPU-dependent fragment ordering.
2844env -u SOURCE_DATE_EPOCH mksquashfs " $TREE " " $rootfs " \
2945 -noappend -all-root -no-progress \
46+ -sort " $sort_file " \
3047 -no-xattrs -processors 1 -comp zstd -mkfs-time " $SOURCE_DATE_EPOCH " \
3148 -all-time " $SOURCE_DATE_EPOCH " > /dev/null
49+ rm -f " $sort_file "
3250data_size=$( stat -c %s " $rootfs " )
3351data_size=$(( (data_size + 4095 ) / 4096 * 4096 ))
3452truncate -s " $data_size " " $rootfs "
0 commit comments