Diff / Delta file between two rootfs images #toolchain #yocto
Hello,
I'd like to create a diff/delta file between two rootfs images. I thought it would be as easy as using diff / rsync with some options, but it doesn't seem to be possible with just that, at least I couldn't manage it. So I wrote my own tool and it works, but it requires root to manipulate the files owned by other UIDs and GIDs (especially root).
I know there's fakeroot, but my images have files owned by root and another ordinary users, so I cannot just make everything be owned by root. Here's the breakdown of my program and what I tried. I'd like any suggestion on how to achieve this easier and without sudo / root account.
Oh and btw I am using ext4 images because I am using Mender (the over the air update software - https://mender.io/ ) and their final "mender artifact" is just the ext4 rootfs image with some extra metadata. I'd like to make a system that can produce a delta between these images. But if that's not possible I can just use the tarball created by Yocto (I'd just need to keep both or maybe Mender can be configured to use tarballs... not sure).
Mount ext4 images at dir1 and dir2 (can be done without root using fuse2fs, but in that case no files can be listed when using sudo... strange)
For all files in dir1 check if it exists in dir2, if not, write its name to ".deleted" file
For all files in dir2 check if file exists in dir1. If not, copy it to output-dir
If both files exist compare them (size, uid, guid, st_mode, finally calculate and compare a hash)
if any of the above is different, copy it (using cp -a, which preserves all attributes). Also make all the directories for that file (mkdir -p).
For all directories in output-dir check if it exists in dir2, if yes then copy all its attributes (stat -> chmod + chown). This is needed for all the directories we created using mkdir -p
This leaves us with all the files that were different in output-dir and a list of files to be removed.
Here's what I thought of doing:
Do this in a docker image as a root (without the docker itself having any privileges). Can't make it work with ext4 being mounted, docker container can't access it (mountpoint is owned by root).
If you are using Mender's hosting option, delta updates are already a feature, see this blog post:
https://hub.mender.io/t/robust-delta-update-rootfs/1144
Not sure what the options are if you aren't using their hosted solution, but maybe their docs provide further information.
Quoted 64 lines · patryk seregiet via lists.yoctoproject.org
Hello,
I'd like to create a diff/delta file between two rootfs images. I thought it would be as easy as using diff / rsync with some options, but it doesn't seem to be possible with just that, at least I couldn't manage it. So I wrote my own tool and it works, but it requires root to manipulate the files owned by other UIDs and GIDs (especially root).I know there's fakeroot, but my images have files owned by root and another ordinary users, so I cannot just make everything be owned by root. Here's the breakdown of my program and what I tried. I'd like any suggestion on how to achieve this easier and without sudo / root account.
Oh and btw I am using ext4 images because I am using Mender (the over the air update software - https://mender.io/) and their final "mender artifact" is just the ext4 rootfs image with some extra metadata. I'd like to make a system that can produce a delta between these images. But if that's not possible I can just use the tarball created by Yocto (I'd just need to keep both or maybe Mender can be configured to use tarballs... not sure).
Mount ext4 images at dir1 and dir2 (can be done without root using fuse2fs, but in that case no files can be listed when using sudo... strange)
For all files in dir1 check if it exists in dir2, if not, write its name to ".deleted" file
For all files in dir2 check if file exists in dir1. If not, copy it to output-dir
If both files exist compare them (size, uid, guid,
st_mode, finally calculate and compare a hash)if any of the above is different, copy it (using cp -a, which preserves all attributes). Also make all the directories for that file (mkdir -p).
For all directories in output-dir check if it exists in dir2, if yes then copy all its attributes (stat -> chmod + chown). This is needed for all the directories we created using mkdir -p
This leaves us with all the files that were different in output-dir and a list of files to be removed.
Here's what I thought of doing:
Do this in a docker image as a root (without the docker itself having any privileges). Can't make it work with ext4 being mounted, docker container can't access it (mountpoint is owned by root).-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#63611):
https://lists.yoctoproject.org/g/yocto/message/63611
Mute This Topic: https://lists.yoctoproject.org/mt/107633647/7581472
Mute #toolchain:
https://lists.yoctoproject.org/g/yocto/mutehashtag/toolchain
Mute #yocto:https://lists.yoctoproject.org/g/yocto/mutehashtag/yocto Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Hi Patryk,
The Mender dude here :-)
As already pointed out by Logan, yeah, the most straightforward thing is to use the delta updates feature which we offer, as it already packages the workflow in a known good way. And for larger fleets, the delta generation can also be moved to the hosted backend.
Having said that, there are definitely a couple of things you can explore respectively think about.
By default Mender uses ext4, that's right. The key here is, looking such an .ext4 image means that it is being treated as a purely binary blob, no considerations on payload structure (like files) or metadata (like permissions) are needed. It should be quite straightforward to change this to a different filesystem, as UBIFS is already supported, for example - but in the end, Mender treats things (by default) just as binary blobs to get out of the was. Side note: when you change things, remember the boot loader has to be able to access it and load files from it.
You can of course adjust that to your needs. Starting with Client 4.0, the logic for root filesystem upgrades has been factored out:
https://github.com/mendersoftware/mender/blob/master/support/modules/rootfs-image.
So you can take that, extend it with handling for filesystem aware tarballs, or an alternative delta-mechanism, it's definitely all possible. Over on hub.mender.io we can also discuss this in more detail :-)
My personal (somewhat educated guess) would be that if you want to do filesystem, and therefore ownership/permission aware magic here, then a custom image type in Yocto is probably the way to go. This allows you for pseudo to take care of all these peculiarities, and you can just "do as root would do".
Greets,
Josef
Quoted 78 lines · Logan Grosz via lists.yoctoproject.org
If you are using Mender's hosting option, delta updates are already a feature, see this blog post:
https://hub.mender.io/t/robust-delta-update-rootfs/1144Not sure what the options are if you aren't using their hosted solution, but maybe their docs provide further information.
Quoted 42 lines · patryk seregiet via lists.yoctoproject.org
Hello,
I'd like to create a diff/delta file between two rootfs images. I thought it would be as easy as using diff / rsync with some options, but it doesn't seem to be possible with just that, at least I couldn't manage it. So I wrote my own tool and it works, but it requires root to manipulate the files owned by other UIDs and GIDs (especially root).I know there's fakeroot, but my images have files owned by root and another ordinary users, so I cannot just make everything be owned by root. Here's the breakdown of my program and what I tried. I'd like any suggestion on how to achieve this easier and without sudo / root account.
Oh and btw I am using ext4 images because I am using Mender (the over the air update software - https://mender.io/) and their final "mender artifact" is just the ext4 rootfs image with some extra metadata. I'd like to make a system that can produce a delta between these images. But if that's not possible I can just use the tarball created by Yocto (I'd just need to keep both or maybe Mender can be configured to use tarballs... not sure).
Mount ext4 images at dir1 and dir2 (can be done without root using fuse2fs, but in that case no files can be listed when using sudo... strange)
For all files in dir1 check if it exists in dir2, if not, write its name to ".deleted" file
For all files in dir2 check if file exists in dir1. If not, copy it to output-dir
If both files exist compare them (size, uid, guid,
st_mode, finally calculate and compare a hash)if any of the above is different, copy it (using cp -a, which preserves all attributes). Also make all the directories for that file (mkdir -p).
For all directories in output-dir check if it exists in dir2, if yes then copy all its attributes (stat -> chmod + chown). This is needed for all the directories we created using mkdir -p
Quoted 11 lines
This leaves us with all the files that were different in output-dir and a list of files to be removed.
Here's what I thought of doing:
Do this in a docker image as a root (without the docker itself having any privileges). Can't make it work with ext4 being mounted, docker container can't access it (mountpoint is owned by root).-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
You automatically follow any topics you start or reply to. View/Reply Online (#63618):
https://lists.yoctoproject.org/g/yocto/message/63618
Mute This Topic: https://lists.yoctoproject.org/mt/107633647/4689568
Mute #toolchain:
https://lists.yoctoproject.org/g/yocto/mutehashtag/toolchain
Mute #yocto:https://lists.yoctoproject.org/g/yocto/mutehashtag/yocto Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-