Marc
Marc

Reputation: 479

Changing qcow2 st_ctime

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

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

Upvotes: 0

Views: 105

Answers (1)

Rich
Rich

Reputation: 966

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 run debugfs directly on it, and then copy the raw filesystem into the final image using the guestfs upload API (the opposite of this).

Upvotes: 0

Related Questions