# Restoring pristine installation



## balanga (Nov 10, 2017)

Is there any way to restore FreeBSD to a pristine installation state? ie to remove everything that was added after the base system was installed...


----------



## ShelLuser (Nov 11, 2017)

Trash /usr/local and optionally any added stuff from the user(s) home directories.


----------



## rigoletto@ (Nov 11, 2017)

Just remember to first backup anything you need in /usr/local/.


```
pkg prime-origins > origins.txt
pkg delete -af
rm -rf /usr/local/*
rm -rf /var/db/pkg/*
rm -rf /var/db/ports/*
rm -rf /usr/ports/distfiles/*
rm -rf /usr/obj/*
mtree -deU -f /usr/ports/Templates/BSD.local.dist -p /usr/local
pkg install `cat origins.txt`
```

Also, do that while actually logged as root because after certain point you will not have more sudo/doas installed.


----------



## ShelLuser (Nov 11, 2017)

Odd that this isn't in the manual pages (prime-origins). I always rely on `pkg info -qo`, I think that's less typing too


----------



## ralphbsz (Nov 11, 2017)

Would it be faster to perform a new install?


----------



## rigoletto@ (Nov 11, 2017)

ShelLuser 


```
`prime-origins` is an alias to `query -e '%a = 0' '%o'`
```

I use `prime-list` often and one day I blind tried origins to see if I could get the list with the categories to avoid installing ports-mgmt/portmaster just for that. I wasn't aware of it not being present in the manual. 

ralphbsz 

That process is quite fast (bar uninstalling and installing the packages), and you can keep a list in there of everything you have installed to quick reinstall later, not to say sysctl.conf and friends. Very practical IMHO.


----------



## poorandunlucky (Nov 11, 2017)

ralphbsz said:


> Would it be faster to perform a new install?



What would be faster if if you would've taken a snapshot of your root filesystem and descendants as, for example, `zfs snapshot -r freebsd@11.1-RELEASE` at which point you could simply rollback to that snapshot within maybe three seconds, reboot for good measure, and you'd be on a fresh installation.

It wouldn't be faster, but there's some stuff that gets installed in /boot (like fuse), in /etc, and other places on the filesystem besides in /usr/local, though if you did `pkg remove -a`, that would remove all the software you installed except maybe a few files here and there, configuration, mostly, and some empty directories or directories with files the installation script doesn't know what it is...

As for going back to the original, if you don't have a ZFS snapshot, I'm afraid you should boot from DVD, and use the configuration wizard to install 11.1-REL on a ZFS filesystem, and configure it for it to boot from that for you, then take your snapshot when you first reboot and update.

I hope I'm making sense, I'm very tired...


----------



## balanga (Nov 17, 2017)

In answer to my own question... I just come across sysutils/clone... So what I intend to do next time I install FreeBSD, is to immediately run `clone` to copy the installation to a different location, and restore from it when I need a pristine build.


----------

