Skip to content

Commit 558a1bd

Browse files
committed
fix(os): canonicalize squashfs input stream
1 parent c859e5d commit 558a1bd

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

os/mkosi/scripts/make-release-artifacts.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ rootfs="$OUT/files/rootfs.squashfs.verity"
2424
truncate -s 0 "$rootfs"
2525
# Privileged mkosi runs can inherit host default ACLs from their workspace.
2626
# The guest rootfs does not rely on xattrs, so exclude this host-only metadata.
27-
# A single compressor worker also avoids host-CPU-dependent fragment ordering.
28-
env -u SOURCE_DATE_EPOCH mksquashfs "$TREE" "$rootfs" \
29-
-noappend -all-root -no-progress \
30-
-no-xattrs -processors 1 -comp zstd -mkfs-time "$SOURCE_DATE_EPOCH" \
31-
-all-time "$SOURCE_DATE_EPOCH" >/dev/null
27+
# A sorted tar stream also removes backing-filesystem directory/inode order and
28+
# hardlink topology from the input. A single compressor worker then avoids
29+
# host-CPU-dependent fragment ordering.
30+
(cd "$TREE" && tar --sort=name --format=gnu \
31+
--mtime="@$SOURCE_DATE_EPOCH" --owner=0 --group=0 --numeric-owner \
32+
--hard-dereference -cf - .) | \
33+
env -u SOURCE_DATE_EPOCH mksquashfs - "$rootfs" -tar \
34+
-noappend -all-root -no-progress -exports -no-hardlinks -no-tailends \
35+
-no-xattrs -processors 1 -comp zstd -mkfs-time "$SOURCE_DATE_EPOCH" \
36+
-all-time "$SOURCE_DATE_EPOCH" >/dev/null
3237
data_size=$(stat -c %s "$rootfs")
3338
data_size=$(( (data_size + 4095) / 4096 * 4096 ))
3439
truncate -s "$data_size" "$rootfs"

os/mkosi/tests/acceptance.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ for service in dstack-guest-agent dstack-prepare app-compose wg-checker; do
2929
grep -q "$service" "$D/mkosi.skeleton/usr/lib/systemd/system-preset/80-dstack.preset"
3030
done
3131
grep -q 'artifact-manifest.json' "$D/scripts/make-release-artifacts.sh"
32+
grep -q -- '--hard-dereference' "$D/scripts/make-release-artifacts.sh"
33+
grep -q 'mksquashfs -.*-tar' "$D/scripts/make-release-artifacts.sh"
3234
grep -q 'image/assemble.sh' "$D/mkosi.postoutput"
3335
grep -q 'ovmf-build.sh' "$D/components/ovmf/ovmf.sh"
3436
grep -q 'fbe0805b2091393406952e84724188f8c1941837' "$D/components/ovmf/ovmf-build.sh"

0 commit comments

Comments
 (0)