# How do I factory reset FreeBSD?



## badasahog (Sep 12, 2022)

On Windows (the OS I'm most familiar with) you can factory restore the system so that it appears in the same way that it did when Windows was first installed.

Is this an option for FreeBSD?

I cluttered my system pretty bad when I was first learning and I want to start over without deleting and recreating partitions and stuff and reflashing the ISO


----------



## K5KGT (Sep 13, 2022)

I believe I installed FreeBSD >20 times trying to figure out my video card settings.  Kept thinking I was locking myself out until I learned how to boot to single user, mount up root read/write, fix things then reboot.  That lesson learned saved me lots of time later.  Moral of story, it's painless initially to just reload FreeBSD from scratch.  That's its "factory restart" I'm afraid.  Repetition is learning.  

Good luck, don't give up.  It's worth it from a learning experience and the end result.

K5KGT.

Edit: Added strike-through above, having a good time taking notes off of the answers below.  Thanks guys!


----------



## SirDice (Sep 13, 2022)

`pkg delete -af` and then `rm -rf /usr/local/*`.


----------



## mer (Sep 13, 2022)

This is one of the nicest thing about ZFS and boot environments.  Install then after a final reboot, before you do anything, create a new BE, activate it, reboot.  Then everything you do like installing SW you do based off the new one, you always have a pristine one after install that you can reset to.

ETA:
Don't forget that you can alway mount boot environments temporarily.  bectl mount command.  That makes it really handy for debugging a broken one, especially if the problem is in config files.  Boot into a good one, bectl mount the broken one,  fix the broken one, bectl umount, reactivate, reboot.
Yes, I'm speaking from hands on knowledge with this one.


----------



## zirias@ (Sep 13, 2022)

SirDice said:


> `pkg delete -af` and then `rm -rf /usr/local/*`.


Plus if base configuration was fiddled with, `etcupdate diff` will list all local changes, and you can use `etcupdate revert` to restore stock versions of individual config files. But be careful not to e.g. kill local users and groups you still need (diffs in /etc/master.passwd and /etc/group).


----------



## CuatroTorres (Sep 13, 2022)

You may want to run `pkg clean` after removing installed packages and removing non-relevant configuration from your /home user.


----------



## Alain De Vos (Sep 13, 2022)

pkg clean -a


----------



## scottro (Sep 13, 2022)

Back to ZFS, if things go wrong after an update, and you've created the boot environment, Michel Lucas, as always has an easy to follow, even for beginners, guide at https://mwl.io/archives/2363

He uses beadm, which is a 3rd party program to be installed, nowadays you can use bectl, which is included with the base install. It takes the same commands he gives for beadm.


----------



## SirDice (Sep 13, 2022)

CuatroTorres said:


> You may want to run `pkg clean` after removing installed packages


Do this _before_ doing `pkg delete -af` because that command will also remove pkg(8), which then needs to be bootrapped again.


```
-a, --all	Deletes	all installed packages except for pkg(8) from the sys-
		tem and	cleans the database of information related to removed
		packages.
{...}
 -f, --force
		Forces packages	to be removed despite leaving unresolved de-
		pendencies.  In	combination with the -a	or --all flag, causes
		pkg(8) to be removed as	well as	all other packages.
```


----------



## zirias@ (Sep 13, 2022)

While that's nice for cleanup, `pkg clean` can't be considered as a part of a "factory reset", because all it does is clean up a cache with no influence on functionality.

To the OP, you now know all bits and pieces to do "something like a factory reset" yourself. I just want to add, a dedicated "factory reset" function does not exist because nobody would ever need it. On FreeBSD, you have all the tooling at your hands to manage your installation (stay in control and know what's going on). On Windows, that's not possible, for example because there is no central packaging system, instead software publishers provide their own packages ... at least, nowadays, this can be in some standard format (MSI), but that's still far from the level of control you can have with something like pkg(8) (and then, there's still lots of software for Windows not using MSI but some 3rd-party installer instead).

Of course, it will take time to master the tooling  ... so it makes sense to ask about resetting things, and I guess the answers in this thread now give a complete picture!


----------



## mer (Sep 13, 2022)

zirias@ said:


> I just want to add, a dedicated "factory reset" function does not exist because nobody would ever need it.


Expectations.  Every cell phone comes with a "factory reset", Windows comes with a factory reset, does MacOS come with a factory reset?
A lot of devices in use every day have that, so I can expect a newcomer to expect that.
But then this is where the forums come in handy:  answers and recommendations.


----------



## covacat (Sep 13, 2022)

bsds are probably the easiest oses to troubleshoot (msdos does not qualify), you don't really need a factory reset
up to including 4.x every binary on / fs was static, so it was even harder to fuck up


----------



## mer (Sep 13, 2022)

covacat said:


> bsds are probably the easiest oses to troubleshoot (msdos does not qualify), you don't really need a factory reset
> up to including 4.x every binary on / fs was static, so it was even harder to fuck up


Oooh the a.out to ELF transitions.


----------



## covacat (Sep 13, 2022)

mer said:


> Oooh the a.out to ELF transitions.


elf came before 4.x but can't remember if it was 2.2.x or 3.0


----------



## freezr (Sep 13, 2022)

I'd like to know which factory actually manufactures FreeBSD...

This sounds like _*"Directory vs Folders"*_... Damned M....


----------



## kpedersen (Sep 13, 2022)

FreeBSD could easily have a factory reset feature rivaling what Windows effectively offers.
Just symlink /bin/factoryreset to /bin/true.


----------



## getopt (Sep 13, 2022)

The OP obviously want a "Windows" like factory reset. Therefore this is the wrong advice:


zirias@ said:


> But be careful not to e.g. kill local users and groups you still need (diffs in /etc/master.passwd and /etc/group).


This is because Computer factory resets will restore the computer to the computer's original operating system and *delete all of the user data stored on the computer*.


----------



## zirias@ (Sep 13, 2022)

getopt, windows "factory reset" has two options, only one of them removes "personal data".

If you're trying to play smart-ass, especially calling others "wrong", it would be wise to check your facts first.


----------



## schweikh (Sep 13, 2022)

The easiest low-tech thing to factory-reset FreeBSD is with a little thinking ahead. In particular it requires two easy steps:

Use ZFS
Take a snapshot after your initial install
With ZFS all you do after your initial install is take a snapshot of your data set(s) with `zfs snaphot tank/root@factoryreset`. Replace "tank" with your pool name and "root" with each of your data sets you want to be able to reset.

Then, when a SNAFU hits, you execute the factory reset with `zfs rollback tank/root@factoryreset`. Voilà!

The cool thing is, you can create more snapshots later on, say after you have installed a number of applications. Then you can rollback to a system that's already usable with the apps you like.


----------



## getopt (Sep 13, 2022)

zirias@ said:


> If you're trying to play *smart-ass*,


Your wording is not appropriate. You are starting a personal attack.


----------



## SirDice (Sep 13, 2022)

Let's not make a mountain of a molehill. 



badasahog said:


> I want to start over without deleting and recreating partitions and stuff and reflashing the ISO



To me this sounds like a perfectly fine _working_ base and there's really no need for anything more than just removing all your packages and removing the contents of /usr/local/. 

Please stop bikeshedding over the 'exact' definition of things. We all know what's intended and not everybody speaks perfect nerd jargon.


----------



## getopt (Sep 13, 2022)

SirDice said:


> Let's not make a mountain of a molehill.


SirDice 
Using "smart-ass" is not a molehill. Are you going to to accept such wording in the FreeBSD forums?


----------



## hunter0one (Sep 14, 2022)

K5KGT said:


> I believe I installed FreeBSD >20 times trying to figure out my video card settings.  Kept thinking I was locking myself out until I learned how to boot to single user, mount up root read/write, fix things then reboot.  That lesson learned saved me lots of time later.  Moral of story, it's painless initially to just reload FreeBSD from scratch.  That's its "factory restart" I'm afraid. Repetition is learning.


I think I'm close to that record, probably installed FreeBSD at least 15 times on two machines in the span of a year. I'm pretty OCD and although FreeBSD does have a few "hard reset" options (such as `pkg delete -a`) I still feel like there's unnecessary configs laying around so instead of removing them, I just reinstall. This isn't a problem if I stick to one environment, but I have a habit of not doing this. There's nothing rational about it, this is a literal addiction I have to try and solve myself 

Because FreeBSD separates ports/packages from the base system, it's much simpler to get back to square one as long as you follow the directions to remove orphaned groups or configuration files. Good luck getting just the "base system" back on Linux.


----------



## kpedersen (Sep 14, 2022)

hunter0one said:


> Good luck getting just the "base system" back on Linux.


Indeed, the i.e Debian installer actively prevents getting a "base install". You have to manually abort it at just the right time. If it reaches `popcon`, you have gone to far and it has spammed your install with a bunch of random crap.



hunter0one said:


> I just reinstall. This isn't a problem if I stick to one environment, but I have a habit of not doing this. There's nothing rational about it, this is a literal addiction I have to try and solve myself


I have a similar compulsion when dealing with Windows or Mac but I do find in FreeBSD that I can just list the filesystem by modification date and get a fairly reliable idea of what cruft has been left in the system. It might help to keep the "reinstall" cravings at bay.


----------

