coreos / bootupd

Bootloader updater
Apache License 2.0
113 stars 22 forks source link

Update the ESP by creating a tmpdir and RENAME_EXCHANGE #454

Closed martinezjavier closed 1 month ago

martinezjavier commented 1 year ago

Since Linux v6.0 the vfat filesystem has support for renameat2(..., RENAME_EXCHANGE):

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=da87e1725ae2

So bootupd could instead of applying the diff files one by one to the destination dir, it could create a temporary dir that is a copy of the existing ESP, apply the diff to that temp dir and finally do an atomic rename exchange of the two directories.

That way, the update mechanism will be safer since it would only require a single renameat2() system call.

martinezjavier commented 1 year ago

openat::Dir already has a local_rename that seems to support this: https://docs.rs/openat/latest/openat/struct.Dir.html#method.local_rename

cgwalters commented 1 year ago

The cost here is write amplification; because FAT doesn't have reflinks, every update to the ESP would require rewriting every file, and a transient doubling of disk space.

travier commented 3 months ago

It looks like local_exchange does what we want in Rust:

It calls renameat2 with RENAME_EXCHANGE.

travier commented 3 months ago

So the logic would be: