Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory reset with OSTree #1793

Open
AdrianVovk opened this issue Dec 26, 2018 · 9 comments
Open

Factory reset with OSTree #1793

AdrianVovk opened this issue Dec 26, 2018 · 9 comments

Comments

@AdrianVovk
Copy link

Hello!

What would be a safe way to "factory reset" an OSTree deployment?

I'm unsure what folders I can delete from /ostree to clear out /etc and /var without messing anything up.

It would be nice if there was an ostree admin reset command that would wipe out these folders safely

Thank you! Happy holidays!

@cgwalters
Copy link
Member

You generally shouldn't change anything under /ostree manually. Factory reset is mostly:

rm -rf /var/*
rsync -rlv --delete /usr/etc /etc

However, that will also e.g. remove /etc/fstab which some setups may not want.

We also don't currently have a model for "factory" kernel arguments, and hence no way to reset those.

But the high level intent is that almost all state is under /etc and /var.

@AdrianVovk
Copy link
Author

That is something I can do, but not from outside a deployment. If I wanted to do this from an installer, for example, it would be nice to be able to do something like ostree admin reset --sysroot=/mnt instead of somehow mounting /etc (?) and /var and then clearing them out...

Kernel arguments can be specified somehow from /usr or even be left blank like they are on the default deployment. They aren't an issue; anything important should be run with ostree deploy by the distro and anything the user added should disappear. I haven't looked into the ostree configuration dirs, but could one specify kargs in the repo config?

@akiernan
Copy link
Contributor

My factory restore is a secure erase of (a separate) /var and a rewrite of the rootfs from an image inside the bootloader. But being able to do a deploy without the three-way merge of /etc would be enough for me - getting a cleaned up deployment after someone's fiddled with /etc would be a useful developer workflow.

Then again my use case is for thousands of completely identical devices, modulo a very small amount of state which I store outside of the standard filesystem.

@AdrianVovk
Copy link
Author

@cgwalters I tested the commands you gave, and they have the right idea

I've had most success running this set of commands:

$ systemctl isolate emergency
[Type root password]
$ rm -rf /etc/{,.}*
$ rm -rf /var/{,.}*
$ rm -rf /home/{,.}*
$ rsync -aHX /usr/etc/* /etc
$ systemctl reboot

I have a goal of getting the system to boot with an empty /etc (which it cannot do at the moment). I'm waiting for systemd/systemd#11287 for this

It would still be nice to be able to wipe these directories from an external mount, like from recovery media. How would I do that?

Thank you

@wmanley
Copy link
Member

wmanley commented Apr 17, 2020

A factory reset that has worked well for me is:

mv /sysroot/ostree/deploy/$stateroot/var /sysroot/ostree/deploy/$stateroot/var.old
mkdir /sysroot/ostree/deploy/$stateroot/var
reboot
rm -rf /sysroot/ostree/deploy/$stateroot/var.old

This only covers /var, but works well for that case.

The beauty of it is that it doesn't affect the running system, and is not affected by programs using /var when it happens. The reset is applied atomically at reboot time. It's fast too. The old /var can be deleted in the background at your leisure after the reboot. It also doesn't rely on shell-globbing. We get an entirely fresh /var directory.

The one risk is that there may be a crash or poweroff between the mv and the mkdir. This could be avoided using renameat2(..., RENAME_EXCHANGE), at least with Linux 3.15+ to make it truly atomic.

@wmanley
Copy link
Member

wmanley commented Apr 17, 2020

One option would be to add an option to ostree admin deploy. Something like --reset-config which would throw away /etc changes rather than doing the 3 way merge.

cgwalters added a commit to cgwalters/ostree that referenced this issue Apr 21, 2020
All of the underlying libostree APIs have supported passing `NULL`
for a merge deployment for...a long time.  But we never plumbed
it up into the CLI.

Add a `--no-merge` option to aid people who want to do a "factory reset":
ostreedev#1793
@cgwalters
Copy link
Member

Well, that was easy: #2081

Do note though this will also reset kernel arguments; you can ostree admin deploy --no-merge --karg-proc-cmdline to avoid that, or just explicitly specify the kargs you want.

cgwalters added a commit to cgwalters/ostree that referenced this issue Apr 21, 2020
All of the underlying libostree APIs have supported passing `NULL`
for a merge deployment for...a long time.  But we never plumbed
it up into the CLI.

Add a `--no-merge` option to aid people who want to do a "factory reset":
ostreedev#1793
cgwalters added a commit to cgwalters/ostree that referenced this issue Apr 22, 2020
All of the underlying libostree APIs have supported passing `NULL`
for a merge deployment for...a long time.  But we never plumbed
it up into the CLI.

Add a `--no-merge` option to aid people who want to do a "factory reset":
ostreedev#1793
agners pushed a commit to agners/ostree that referenced this issue May 29, 2020
All of the underlying libostree APIs have supported passing `NULL`
for a merge deployment for...a long time.  But we never plumbed
it up into the CLI.

Add a `--no-merge` option to aid people who want to do a "factory reset":
ostreedev#1793
@liferooter
Copy link

liferooter commented Dec 14, 2021

Well, that was easy: #2081

Do note though this will also reset kernel arguments; you can ostree admin deploy --no-merge --karg-proc-cmdline to avoid that, or just explicitly specify the kargs you want.

Does it also clear /var?

@cgwalters
Copy link
Member

Does it also clear /var?

No, ostree will never touch /var.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants