Reinstalling FreeBSD while preserving contents of home directory.

Wanted to seek advice before I tried to test reinstalling FreeBSD without wiping home directory. Are there any guides that I can follow other than Google's AI? Based on what I uncovered, it will be necessary to use manual mode in the installer, rename the home, destroy old os datasets, recreate them and bring home back into the active layout.

Just wanted to know I anyone is aware of a simpler method before I spend a lot of time trying this out on a spare system that I have to experiment with. I'm planning on using ZFS on 15.1.
 
Backup your home dir onto an external storage medium, ensure the backup is good, reinstall FreeBSD and then restore your home dir. With "smarter' solutions there is a higher prob. of messing up!
 
If the home is on its own zfs, which is generally a good idea, you can just use zfs send to get it to a new file. Otherwise, you can always tar it up and save it somewhere that's not going to be in your system when you do the reinstallation.
 
If the home is on its own zfs, which is generally a good idea, you can just use zfs send to get it to a new file.
In cases of ZFS, I'm not sure whether /home is created as dedicated dataset or not, if /home is a dedicated dataset, simply unmount it, delete actually blank (skeleons only) created /home if any, and mount previous /home dataset may be sufficient. What's essential in this case is to (somehow) backup /etc/master.passwd, /etc/spwd.db and /etc/group at minimum before reinstall and restore them after reinstall.

If on ZFS and /home is NOT a dedicated dataset, create new dataset without defining mountpoint, temporarily mount it to any blank directory and copy /home into the dataset before reinstall, then, after reinstall, blank /home and set mountpoint of the dataset having former /home to /home before restarting. The culprit would be NOT destroying any datasets and reuse them for reinstall.
 
The default ZFS install I believe has a separate dataset for /usr/home and there is a symlink /home that points to it.
If you are reinstalling ZFS, do you have room to add another device? If so I would suggest use that new device for your user/home dataset so you wind up with 2 devices, one is the "OS" the other is user data.
 
Are there any guides that I can follow other than Google's AI?
Always!
And most of the times, even better ones.

Never blindly 100% trust in anything any AI chatbot says! Especially not on something crucial fundamental and critical like backup and restore your home or data!
Apart from those chatbots often confuse FreeBSD with Linux, sh with bash etc., anybody not completely stupid experienced AI chatbots not seldom tell complete bogus. And when you say, 'Dude, that is completely wrong' the bot answers, 'you are right...' You don't want that happen with something like the contents of your /home/, telling the bot, 'That didn't work! Now the contents of my home are deleted!' 'I am sorry. You are right.' 🤬
AI could be seen as a summarization of websearches instead delivering several choices of answers you can pick from, compare and decide yourself, you get just one single answer constructed by a very, very stupid machine that is just very, very fast with scissors and glue but doesn't have a clue at all.
Don't be fooled by the way it "talks". All this seemingly polite verbiage ain't not an endless patient, understanding, wise grandmother, but come from a very, very stupid machine that's just very fast with scissorcs and glue.
Short:
AI is a very helpful assistant on searching for patterns in large heaps of things already existing. And you better already have an idea of what's in that heap, what you're looking for, what a correct answer may look like, and know how to rate the answer. Otherwise it's very likely the chatbot helps you only to shoot you in your own foot.
Don't use any AI chatbot on anything new or that needs understanding aka learning. Because that presupposes thinking, and that's exactly what those machines just cannot do at all. There is more to thinking than just have fast access to large databases and being fast in finding patterns. A lot much more. Life experience: The ones answering fastest do not deliver the best results. 🤓
Always remember: No machine can think, and never will.

You better also always do "traditional" searches. Many FreeBSDer prefer duckduckgo.com. It also often delivers better results on FreeBSD related topics, and finds good links to the vast amount of good knowledge stored in this forums, too. Almost all (99%) you need to know about FreeBSD you find in the HB, the man pages, and this forums. You just need to dig for it, and ddg does a good job on it, particulary to dig the forums.
Also the results you find leading to stackoverflow, geeksforgeeks et al are most of the times way better than what some AI chatbot tells. There are also many personal webpages people use to record their experiences and provide them openly for others you can get some useful things from, like Vermaden's blog, scottro's blog, PHK's Bikeshed and many, many others.
This way, you learn.
Using AI chatbots do not really teach you much, and so you stay depending on them aka stupid. 😁😎🤓

Back to the original topic:

I second what the others already say:
1./home/➡️💾 store it to an external drive (USB thumb drives are not really reliable to be trusted in having an only copy of valuable data.)
2.reinstall FreeBSD (a tiny Beastie as a smily was nice. 🤓)
3.💾➡️/home/

Also my advice was to not use simple cp -R ... ... for the backup and restore job (➡️) but use rsync(1). AFAIK rsync does not come with the base system, so must be installed first. But for anybody ever used it once it's an essential tool, must have. Its man page is full of practical useful examples, and you'll also find a lot about it here in the forums. Perhaps easy, simple and good for the start is rsync -auqd /home /path/to/BUdestination/ will produce under ...BUdestination/ an exact copy of home.

Or, as the others said, if you are on ZFS, you can use the ZFS' tools to create a copy of your home.
Don't just use snapshots as BU! Snapshots are a very nice thing, but they are not a 1:1 copy. They contain the changes, only. By default snapshots are somewhere stored under /. So, when you reinstall the system, even clean the disk first, so your snapshots are gone, too.🖕

Doing a reinstallation as a beginner mostly comes from, 'Now I'm a bit into the system - dude, what messed I things up. Better wipe it and start all over with a clean, new installation again. Now I have a better clue, how things better should be.' (Guess, why I do know that! Tip: It's not reading minds. 😁)
Which means, it's a good chance to reconsider some things and to throw in some ideas, maybe not only own experiences. For you get a better re-start. Not a complete new one. You asked here for how to preserve your home best, which proves, you're doing it right: Think and ask questions first, before you shoot.👍 So a lesser chance fo another reinstallation. Which sometimes can be needed and was annoying, yes, but is no real problem if you already have some BU plan, that guarantees no data in home and other things are lost.
Reinstallation also means, you are serious to dig deeper into the system, actually use it, which means it will become more valuable, it will contain more work you put into it: files, data, edited config files (don't miss also to have a BU of /etc/, /usr/local/etc, and maybe /boot/loader.conf) - all files you spent time on. Save them, save your time! Do backups!
Setting up BUs should be the very first task to be done on any new system, when you decide to use it seriously.

Anyway as already the others mentioned here more than once is, it's by principal a good idea to have /home/ and all the other stuff which is not the system or the application software, separated. Best stored on its own physical drive(s), if your machine is capable to provide more than a single drive (external drive with an USB to SATA converter was another option.) ZFS pool or "just" an UFS drive, is a second thought you may give. But the primary idea is to keep all the personal, individual files separated from the system, and have BUs on another additional drive.
This way no data, no config files, nothing you ever spent time on can get lost due hardware failure or fatfingering. So, anything you do, including manipulating the system, including wipe the entire drive clean and reinstall the whole system by scratch ain't no reason to become worried about something of even the slightest value could get lost.
 
I run the ufs filesystem on small machines. I always put the /home directory, and anything else I want to save, either in it's own partition, or on a separate drive. On a laptop with only one drive, I mount /home on a separate partition. On machines with more than one drive, I usually set up a separate small SSD as the boot drive, and have /home completely isolated on a separate drive. Then when installing a new o/s, leave the partition or drive containing /home untouched. After installation, when everything is running and you're happy it worked, then add an entry to /etc/fstab to mount the old /home. Doing that largely protects you from losing the contents of /home if anything goes wrong during installation. It also preserves all your config settings, browser history, etc, that you want to keep across an o/s install. In extremis, if you really, really don't want to run the risk of losing any data, you could physically disconnect the drive containing /home while installing the o/s, and then reconnect and mount it once installation is complete.

One caveat to beware of is crappy uefi bioses that change the assignment of drives between different sata ports, seemingly at random and for no logical reason, that can mess you up big time, and you will have to go and play around with your fstab, or mess around with cables. I'm looking at you, lenovo M-series. If you're running on nvme drives, I think that may not be a problem.
 
Move /usr/home to some not-system location and move the content back to the new home dir later, or overwrite it entirely if you trust the old config files and file permissions?
 
A good rule of thumb: If you do not have a copy of your files on an offline, external storage device, then you do not have any files at all; It will just be a matter of time, before as little as a single command or mouse click will wipe your files from all synchronized locations in seconds.
 
A good rule of thumb: If you do not have a copy of your files on an offline, external storage device, then you do not have any files at all; It will just be a matter of time, before as little as a single command or mouse click will wipe your files from all synchronized locations in seconds.

Yup -- I live by this rule too !
 
I always manually drag and copy personal files in /home to a zfs pool on a second drive. I also tend to have at least one full system backup using tar. This take a long time so I'm interested in something that would allow incremental backups for that. Is there something comparable in zfs? I never reinstall without having the backups on my second drive. I also have an external usb drive that I backup personal files to but have sometimes had access errors. I'm interested in what others have found to be ultra reliable, especially in zfs.

The main issue is that when I reinstall the system it's necessary to copy files from another drive to the new installation's /home. I have a lot of data and wondered if there is a way I can avoid moving the data by simply preserving where it is located. I will always insist on having data backed up to another drive either way.

As Maturin pointed out, I too have learned that AI is unreliable. On one occasion a command it gave me to use triggered an invalid error message. A day or two later I asked google what is wrong with the instruction it gave me and it also said that it was invalid. I told it I got the command form you (Google's AI). it apologized and explained that it must have confused things. That's not the only time it gave me completely incorrect information. The times that it helped was when it gave simple instructions to things I could look up myself. I know not to blindly trust it. I'd rather rely on forum members knowledge and experience. I've already have more ideas on exactly what to backup just from the posts I've read so far.
 
I'm interested in what others have found to be ultra reliable, especially in zfs.
Well, it depends on what you mean by "ultra reliable", but I'm using ZFS mirrors and some self written shell scripts that do rsync to my NAS - but there are other solutions of course, particulary when you're looking for incremental BU.
Another Tip: Keep your /home as large as needed but as small as possible. Store files that never change (videos, music, pictures, PDFs, ebooks etc.) in another location, not your /home. No need to stress your BU routine with files never change, but just need to stored savely.

You may also skim some other of my posts on that topic:
Backup Plan
About Backups
About Backups
About Backups
About Backups
How to build a NAS
My Machines
 
A good rule of thumb: If you do not have a copy of your files on an offline, external storage device, then you do not have any files at all; It will just be a matter of time, before as little as a single command or mouse click will wipe your files from all synchronized locations in seconds.
Yep, that's why I've got a copy on a collocated HDD, another on an external HDD as well as a bunch of ZFS snapshots. Most of the time, the ZFS snapshots are where I restore from, then the external HDD and finally the remote copies. Most data loss is from typing the wrong things in, so the local backups are the ones you're most likely to actually use.
 
Yeah, as mentioned: why do you want to reinstall? What is broken?

In the classic days the way to do what you want is/was to just untar distribution tarfiles for kernel and base, with or without /etc. I've never done that with a ZFS-for-root install, but I don't see why it wouldn't work.

Or `make world`. Tell us what you want to achieve.
 
In the classic days the way to do what you want is/was to just untar distribution tarfiles for kernel and base, with or without /etc. I've never done that with a ZFS-for-root install, but I don't see why it wouldn't work.
In the past, I think running the installer on a ZFS on root system would ask (roughly) "do you want to update or install into a new BE".
That would let one do the equivalent of "untar distribution" into an empty BE. I don't know if this is still available from installer but it may be an option
 
I don't need to reinstall at the moment. I'm anticipating a future install, maybe on another system, as well as simply wanting to fill in this gap of knowledge.

On Linux I had my home data backed up to an external drive but I avoided having to restore from it by not formatting the home directory during a new installation. This was a matter of convenience.

Full system tar backups and restores work well on FreeBSD but isn't as simple on Linux due to restoring my Debian based system often produced errors. There was an issue with restoring boot which I never looked much into since FreeBSD works well. My current issue is that I realize backing up the entire system is inefficient and time consuming.
 
In the past, I think running the installer on a ZFS on root system would ask (roughly) "do you want to update or install into a new BE".
That would let one do the equivalent of "untar distribution" into an empty BE. I don't know if this is still available from installer but it may be an option

I think one problem here is that the more experienced users don't do "reinstalls" and hence aren't really familiar with the details of the options.

One more reason to not admid defeat by reinstall.
 
I'm not that family with zfs, having only used it for a few simple things, but I will review the handbook. Thanks cracauer. This may be exactly what I was looking for.
 
This should actually be pretty easy (relatively speaking), because the only thing the installer really does are 3 - 4 things:
  • Asks for some info so that it can be added to the installed OS.
  • Sets up the disk hierarchy (which is an optional step!).
  • Then actually sets up mandatory info like your network set up, but also timezones.
  • Optionally sets a password.
But here's the funny (and important!) part: the whole installation procedure is essentially nothing more (!) than the extraction of a few archives; where the bare essentials are: kernel.txz, base.txz and of course lib32.txz. That's it!

After that some maintenance will be done (like adding your network info to /etc/rc.conf, setting the timezone by running tzsetup (this isn't even done by the installer ;)), and of course your password.

My point being? You don't need the installer for any of this. This guide of mine actually covers this: manually installing FreeBSD, and even though it's dated it's still very much relevant today (or can be).

I'd boot from installation media, don't even bother with the installer at all but simply make sure to 'empty' or clear your existing installation (I'd preserve some of the files in /etc such as rc.conf), then extract the archives (which should be on the install media), do the post configuration and don't forget to bootstrap your setup with the new bootcode and/or EFI partition.

(edit): I forgot about the swap part and to update things, but even so: that shouldn't be too much of an issue because... you wouldn't need to redo the whole partitioning anyway; basically only the (relevant) ZFS datasets.
 
Thanks for this guide. It seems super useful. I will be able to try it on a spare system I use for testing.
 
You should probably think twice before taking any of my advice, as nobody can really mess things up as thoroughly as I can.

However, that being said, the below rsync based scripts have worked pretty well for me whenever I managed to create an unrecoverable problem for myself.

Below is the script I used to backup my home folder, along with a few other folders as well.
Code:
#!/bin/sh

# Check if the script is being run by root
if [ "$(id -u)" -ne 0 ]; then
    echo "This script requires superuser privileges."
    echo "Please enter the root password below:"
   
    # Re-run the script with su
    # -m preserves the environment
    # -c executes the following command
    exec su -m root -c "/bin/sh $0 $@"
fi

# Your actual script logic starts here
echo "Success! You are now running as: $(whoami)"
# Add your administrative commands below

# Acknowledge the input securely
echo "Password received (length: ${#password})"

# Use the variable $password for the intended secure operation
# Payload starts below
# USING RSYNC TO BACKUP AND RESTORE SYSTEM DIRECTORIES

# +++ Copy settings and home directory to backup: +++

mkdir -p /diskbkp/backup/boot
mkdir -p /diskbkp/backup/usr/local
mkdir -p /diskbkp/backup/home
mkdir -p /diskbkp/backup/etc
mkdir -p /diskbkp/backup/var/cache/pkg

# Prepare a list of installed packages with below command:
pkg prime-list > /diskbkp/backup/packagelist.txt
# Prepare a list of installed packages and version numbers with below command:
pkg info > /diskbkp/backup/packagelistv.txt
# Prepare a list of installed packages with file extensions:
pkg query "%n-%v.pkg" > /diskbkp/backup/packagelist_ext.txt
# Prepare a list of third party packages with below command:
grep -v "^FreeBSD-" /diskbkp/backup/packagelist_ext.txt > /diskbkp/backup/third_party_only.txt
# Prepare a list of base os packages with below command:
grep "^FreeBSD-" /diskbkp/backup/packagelist_ext.txt > /diskbkp/backup/base_os_only.txt

# COPY SYSTEM DIRECTORIES WITH METADATA PRESERVATION
# -H preserves hard links, -X preserves extended attributes, --delete cleans old files
rsync -avhpoHX --progress /boot/loader.conf /diskbkp/backup/boot/loader.conf
rsync -avhpoHX --progress /usr/local/etc/ /diskbkp/backup/usr/local/etc/
rsync -avhpoHX --progress /home/ /diskbkp/backup/home/
rsync -avhpoHX --progress /etc/ /diskbkp/backup/etc/

pkg create -a -o /diskbkp/backup/var/cache/pkg
echo "Script finished."
exec /bin/sh

An important thing to be aware of is that "/diskbkp" in the above example is actually a UFS partition located on a second internal hard drive installed within this machine. I'm not using ZFS at all because of my antiquated hardware, and the method that I'm using is probably not the most efficient way to get things done, but for me it does work. Also, when you reinstall FreeBSD, don't create any users, because apparently the UUID number of the user you create during the installation process will conflict with the user data stored within /diskbkp/backup/home/, or at least that has been my experience.

Below is the script which I use to restore after doing a fresh installation. BTW, the below should re add all of your packages, if the first script worked perfectly.

Code:
#!/bin/sh

# Install FreeBSD in the usual way then use below commands to restore settings & home directory:

# RESTORE SYSTEM DIRECTORIES WITH METADATA PRESERVATION
rsync -avhpoHX --progress /diskbkp/backup/boot/loader.conf /boot/loader.conf
rsync -avhpoHX --progress /diskbkp/backup/usr/local/etc/ /usr/local/etc/
rsync -avhpoHX --progress /diskbkp/backup/home/ /home/
rsync -avhpoHX --progress /diskbkp/backup/etc/ /etc/

# NEW: Safely loop through only third-party applications with extensions
while read -r filename; do
    echo "Restoring: $filename"
    pkg add "/diskbkp/backup/var/cache/pkg/$filename"
done < /diskbkp/backup/third_party_only.txt
echo "Script finished."

Again, I'm certainly no expert, so please take everything I say with a grain of salt. Also, if you're only interested in working with your home directory, and nothing else, then I suppose that you could possibly run the below commands individually, but you will have to adjust the below paths to fit your needs.

Code:
# Make a backup folder
mkdir -p /diskbkp/backup/home

# Copy contents of your home folder to backup
rsync -avhpoHX --progress /home/ /diskbkp/backup/home/

# Restore home folder after reinstallation of OS.
rsync -avhpoHX --progress /diskbkp/backup/home/ /home/
 
Back
Top