bootc icon indicating copy to clipboard operation
bootc copied to clipboard

install: Support reinstallation (factory reset)

Open cgwalters opened this issue 2 years ago • 21 comments

https://github.com/containers/bootc/pull/137 is tracking part of this, a lot of related discussion in https://github.com/coreos/fedora-coreos-tracker/issues/399

Basically we should support something like bootc install factory-reset that would configurably wipe local system state.

On the implementation side...I think the best way to do this would be something like:

  • Create new deployment with fresh etc targeting a new stateroot
  • Boot into it
  • optional: clean up old deployment + stateroot

The beauty of this approach is that the "factory reset" would actually also be fully transactional, i.e. you could roll back into the previous state. It'd be easy to copy over any desired state (SSH host keys, cached container images e.g.) from the previous boot before deleting it.

Active work

  • https://github.com/bootc-dev/bootc/pull/1389

Goals:

  • Make stateroots more visible, e.g. at least status should show them if different
  • Need to support explicit pruning of deployments e.g. bootc deployment rm (like ostree admin undeploy) so that I can get rid of old stateroots

Ideas:

  • Add bootc mount <deployment> /run/tmp-next-root so that I can cp -a --reflink=always /var/home /run/tmp-next/root/var/home

cgwalters avatar Mar 19 '24 14:03 cgwalters

BTW one tricky thing in this is kernel arguments...cc https://github.com/containers/bootc/pull/401

And also related to this, we should probably go to some effort to preserve the original kargs.


An entirely different way to implement this would be to retain a pinned version of the original installed deployment. Some people will want to do that, and we already effectively support it with ostree admin pin. However...rolling back to that in the general case will imply rolling back to something pretty outdated, which we don't want to encourage. So I think we should focus more on better capturing and maintaining the bits of state that we want from that which mostly I think boils down to kargs.

cgwalters avatar Mar 20 '24 13:03 cgwalters

One question came up tangentially related to this too - why does the current install integration test suite not work on an ostree based system?

First there's two things; the to-disk code; that works everywhere, it's easy we just use loopback.

For the alongside install tests, it's basically because of this. We'd need to be sure to use an alternative stateroot vs the booted one, etc.

cgwalters avatar Sep 04 '24 12:09 cgwalters

I'd love to have such a reset functionality for bootc-{switch,update} as well.

vrothberg avatar Oct 10 '24 12:10 vrothberg

Maybe an option to reset state on just a single file in etc or a path under etc too, rather then a complete reset.

kfox1111 avatar Oct 16 '24 13:10 kfox1111

Hello folks, is there a clear path of what to do next to make this happen?

Malix-Labs avatar Jan 10 '25 19:01 Malix-Labs

So https://github.com/containers/bootc/pull/137 landed some important preparatory code here. However...that's covering the "reinitialize system from a different bootc container image". What we obviously could streamline is the flow of "reinitialize system from the booted image".

Probably something like bootc install to-existing-root --from-booted? And we need to bikeshed what state preservation options we support.

cgwalters avatar Jan 17 '25 00:01 cgwalters

How should /home and /etc/passwd be handled?

imbev avatar Jun 05 '25 21:06 imbev

Opened https://github.com/bootc-dev/bootc/pull/1389 for this

cgwalters avatar Jun 30 '25 12:06 cgwalters

How should /home and /etc/passwd be handled?

I think in the core design (as used by #1389) it's ~trivial to copy over whatever state one wants from the previous root. But it'd definitely be nice to add some sugar for this.

cgwalters avatar Jun 30 '25 13:06 cgwalters

xref https://www.freedesktop.org/software/systemd/man/devel/systemd-factory-reset.html - some integration work to do here

cgwalters avatar Aug 04 '25 18:08 cgwalters

But it'd definitely be nice to add some sugar for this.

I'm trying to think of areas users may hurt themselves with this. I'm not sure we can add sugar for everything, but I agree w/ @imbev that users & /home dirs are a good starting point. Other contenders could be fstab or mount unints, host ssh keys (probably not that important), Networking (static IPs or bonds), hostname? I wish we had a clean way to reapply whatever anaconda did and/or cloud-init. In lieu of that, maybe some command flags to preserve some things items will help w/ foot guns. $0.02

mrguitar avatar Aug 04 '25 22:08 mrguitar

But it'd definitely be nice to add some sugar for this.

I'm trying to think of areas users may hurt themselves with this. I'm not sure we can add sugar for everything, but I agree w/ @imbev that users & /home dirs are a good starting point. Other contenders could be fstab or mount unints, host ssh keys (probably not that important), Networking (static IPs or bonds), hostname? I wish we had a clean way to reapply whatever anaconda did and/or cloud-init. In lieu of that, maybe some command flags to preserve some things items will help w/ foot guns. $0.02

Anaconda could be used with the /root/anaconda-ks.cfg generated by the initial installation, but that is an additional dependency.

I agree about the value of the factory reset having flags and file config options for each part.

imbev avatar Aug 04 '25 22:08 imbev

Note that in the current design we will always default to a nondestructive factory reset by creating a new stateroot. Then users are required to clean up the prior stateroot when they're happy. If it doesn't work, then a rollback into the previous deployment undoes everything.

cgwalters avatar Aug 05 '25 11:08 cgwalters

Yeah I get that. I think we both want to avoid users resetting their systems, rebooting, and not being able to log in. :) Is the sugar you were thinking of doing the copy for the user? Or were you thinking it could work differently?

mrguitar avatar Aug 05 '25 11:08 mrguitar

My instinct here is to land some experimental form of this ASAP and gather feedback from ~real world experience.

cgwalters avatar Sep 08 '25 14:09 cgwalters

Anaconda could be used with the /root/anaconda-ks.cfg generated by the initial installation, but that is an additional dependency.

Yes! We had a team chat around this issue and for sure it'd be awesome to have Anaconda be useful in this setup to do a reinstallation into a new stateroot.

In theory we could have something like factory reset plugins /usr/lib/bootc/factory-reset.d or something that could help guide users who did an install with anaconda to also do a factory reset that way? Or well, a fedora-derivative feature flag that

bootc-image-builder/osbuild are not really designed for this, but maybe could be reworked to do so.

cgwalters avatar Sep 11 '25 20:09 cgwalters

Ideally we minimize "magic" here; admins should know where the data is coming from and why it's preserved.

cgwalters avatar Sep 22 '25 19:09 cgwalters

As far as "being able to log in", one pattern we use for https://github.com/bootc-dev/bcvk (and is also used by podman-bootc) is https://github.com/bootc-dev/bcvk/blob/aae33b4a252fea309bd38bfd3dba992187656b22/crates/kit/src/sshcred.rs#L16 where we use systemd credentials to add a tmpfiles.d unit that injects a SSH key via SMBIOS (virt level creds). Notably, factory reset at the bootc level won't get rid of that key.

cgwalters avatar Sep 22 '25 19:09 cgwalters

How should /home and /etc/passwd be handled?

I'm not a dev, just a hobbyist, but I'd like to provide my thoughts regarding the matter. Atleast on Silverblue with OStree, when I attempted a "Factory Reset" (see this) the GNOME OOTB/firstboot wizard appeared just like during the first boot after a fresh install and all the relevant files were auto-generated.

Instead of copying/migrating files like /etc/passwd, bootc or another program could provide a firstboot/OOTB experience. I was thinking something like a systemd service like bootc-firstboot.service, which checks for a file named /etc/bootc-firstboot-complete (could be another file) and if it doesn't exist, prompts the user to configure their locale, keyboard layout and setup users just like the GNOME OOTB/firstboot wizard, or maybe even prompt the user for a "setup file" that contains all that information.

ScatteredCognition avatar Sep 29 '25 10:09 ScatteredCognition

I was thinking something like a systemd service like bootc-firstboot.service,

What would it provide over systemd-firstboot and gnome-initial-setup (and other tools like Ignition or cloud-init)?

Now one issue right now is the Fedora bootc base image has this https://gitlab.com/fedora/bootc/base-images/-/blame/main/minimal/manifest.yaml#L18 but that's effectively a legacy bug. Though changing it would require analysis of consumers.

cgwalters avatar Sep 29 '25 11:09 cgwalters