On 15/06/2025 16:09, Alexey Gladkov wrote:
On Sun, Jun 15, 2025 at 03:35:17PM +0100, Harald van Dijk wrote:
On 15/06/2025 14:48, Alexey Gladkov wrote:
If a mounted image is used as root, overlayfs is typically used to
provide write access. In this case, it is safe to execute switch_root.
But when overlayfs is used, this does not guarantee that it is safe, and
does risk the exact sort of destructive behaviour that is meant to be
protected against. It's only safe with specific uses of overlayfs.
Hm. The overlayfs by design does not allow you to change lower layers.
Also, the filesystem does not propagate changes to lower layers.
In which case if the whole overlayfs root can it be dangerous to do
remove a root content ?
When there's important data in the upper layer. In your use case, the
upper layer is tmpfs and in that case, sure, it makes sense, but that is
not guaranteed and is not being checked.
util-linux's version of switch_root does the same ramfs/tmpfs check that
busybox does, but reacts to it differently: rather than exiting with an
error for other file systems, it simply prints a warning and carries on
without removing any files. Would doing that instead in busybox too be
enough to work for your use case?
Yes, it will absolutely be better than a fatal error. I'm using
switch_root in initramfs and of course I'd like to clean up root, but this
way at least I can use switch_root from busybox.
That should be a fairly simple change, that should just be a matter of
changing the bb_(simple_)error_msg_and_die to the non-_and_die variant
to continue printing the message but carrying on, and then skipping over
the delete_contents("/", rootdev).
Is it possible to add an option to delete content from root ?
Also a good suggestion.
Cheers,
Harald van Dijk
_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox