Is there a way to modify the st_ctime_sec attributes for a qcow2 image?
I am trying to have a reproducible qcow2 build, with the end goal being that I can recreate qcow2 files and still have byte for byte identical contents.
I am down to have the ctime's being different between my original and my reproduction build.
Using virt-diff -a orig.qcow2 -A rebuild.qcow2 --atime --dir-times --times I only get differences like:
changed: st_ctime_sec
- d 0755 4096 2017-11-21 22:35:00 2017-11-21 22:35:00 2017-11-22 02:34:36 /boot/efi/EFI
- d 0755 4096 2017-11-21 22:35:00 2017-11-21 22:35:00 2017-11-22 11:10:48 /boot/efi/EFI
I found a solution that works as root, but I am looking for something that can be run as a normal user.
From mount qcow as device
modprobe nbd max_part=8
qemu-nbd -c /dev/nbd0 guest.img
mount /dev/nbd0p1 /mnt/guest
Then from change ctime
debugfs -w /dev/sda1 < changes
where changes contains lines like
set_inode_field /grub2/locale/ast.mo ctime 201001010101
set_inode_field /grub2/locale/ca.mo ctime 201001010101
set_inode_field /grub2/locale/da.mo ctime 201001010101
set_inode_field /grub2/locale/de.mo ctime 201001010101
You can do atime and mtime with the libguestfs API guestfs_utimens. However ctime is not settable with libguestfs, largely because it appears there is not a "good" way to do it in Linux. You could code up the
debugfs
approach as a new libguestfs API (or use the debug backdoor). Or if your image is a raw filesystem (not qcow2) you might just rundebugfs
directly on it, and then copy the raw filesystem into the final image using the guestfs upload API (the opposite of this).