Solved ZFS and Home Directory

Hi
I am using FreeBSD with UFS. However, for the last week or so, I am learning and working on ZFS (in Virtual Machine). I must say that I am impressed by its features (especially Snapshots, Properties etc.). After going through ZFS Chapter in FreeBSD Handbook, a lot of my confusion regarding ZFS are cleared. Now, I know about Pools, Datasets and their Properties. However, there is one thing that I did not find in the Handbook. Let me explain it:
In my UFS installation, I created following layout for my partitions:
ada0p1 freebsd-boot 512KB
ada0p2 freebsd-swap 2GB
ada0p3 freebsd-ufs 100GB /
ada0p4 freebsd-ufs 600GB /home
In this layout, I have placed my "/home" drive on separate partition. So, that if any unexpected event happens, and I have reinstall the base system, then most probably it will not affect my /home partition.
However, I did not find similar concept in ZFS documentation. According to the help provided in the documentation, ZFS takes over entire Drive and creates Datasets. So, it raises a question that in the presence of ZFS, if I need to reinstall the base system, then how can I prevent my data from deletion?
PS: I have backup :)
 
You can easily use zfs-send(8) and zfs-receive(8) to backup/restore the dataset, transfer it to another pool or even another machine.
Yes, it was mentioned in the chapter that one can send snapshots to other machines (ssh) or other pools. I will definitely experiment with it tomorrow (in Virtual Machines). However, there is a confusion in my mind:
That is, It is easy if there are two Hard Drives (to create two separate pools), but unfortunately my Laptop has only one Hard Drive. So, is it possible to divide a single Hard Drive into two pools? One pool for Base system and other for Data?
PS: I know that it was also mentioned in the Documentation that the concept of Partitions does not apply in ZFS.
 
So, it is possible to divide a single Hard Drive into two pools? One pool for Base system and other for Data?
Possible, yes. Just create two freebsd-zfs partitions and assign each partition to its own pool. Not really recommended though. Snapshots and backups are a better solution, it's always good to have a backup of your data for a variety of reasons (your disk suddenly dying for example).
 
offtopic:
Snapshot works very well with UFS.
For smallsized storage like your 700GB - UFS and geom* might be a better choice for most cases.
 
In this layout, I have placed my "/home" drive on separate partition. So, that if any unexpected event happens, and I have reinstall the base system, then most probably it will not affect my /home partition.
However, I did not find similar concept in ZFS documentation. According to the help provided in the documentation, ZFS takes over entire Drive and creates Datasets. So, it raises a question that in the presence of ZFS, if I need to reinstall the base system, then how can I prevent my data from deletion?
Simple: manual partitioning / setup.

Don't forget that the installation process is basically nothing more than extracting a few archives and applying a few specific settings. So in your situation you'd do a manual partitioning using the shell, then you set up your ZFS structure in /mnt, empty the main locations (the -x parameter in rm(1) is quite useful for this, or you simply destroy and recreate the main datasets where possible) and then you can perform the installation.

This might be an interesting read: https://forums.freebsd.org/threads/installing-freebsd-manually-no-installer.63201/

It shows how you can install a FreeBSD system without using the installer itself. And that is also applicable (more or less) with a reinstallation.
 
You can also install into an existing pool by creating (and deleting if necessary) the datasets manually or even better install into a new boot environment (see bectl(8)). This way you can keep your existing pool (and e.g. home- or other datasets) and don't have to zfs send|recv them around.
Boot environments are perfect for upgrades and they can be mounted/run in a jail to perform the upgrade while still running. After the upgrades finish within the jail, activate the new BE, reboot the machine and run freebsd-update install again to finish the upgrade. If anything breaks, just enable the previous BE and you're back where you started.

You could also just "clone" a pool by adding and then detaching mirror devices. This is also a viable solution to backup a pool e.g. before applying major changes or as in your case if you want to reinstall the OS completely from scratch (for whatever reason... it's not that we need to do that on a regular basis like on windows boxes).
 
Simple: manual partitioning / setup.

Don't forget that the installation process is basically nothing more than extracting a few archives and applying a few specific settings. So in your situation you'd do a manual partitioning using the shell, then you set up your ZFS structure in /mnt, empty the main locations (the -x parameter in rm(1) is quite useful for this, or you simply destroy and recreate the main datasets where possible) and then you can perform the installation.

This might be an interesting read: https://forums.freebsd.org/threads/installing-freebsd-manually-no-installer.63201/

It shows how you can install a FreeBSD system without using the installer itself. And that is also applicable (more or less) with a reinstallation.
The Tutorial looks great. I will definitely try it. Thanks a lot :)
 
You can also install into an existing pool by creating (and deleting if necessary) the datasets manually or even better install into a new boot environment (see bectl(8)). This way you can keep your existing pool (and e.g. home- or other datasets) and don't have to zfs send|recv them around.
Boot environments are perfect for upgrades and they can be mounted/run in a jail to perform the upgrade while still running. After the upgrades finish within the jail, activate the new BE, reboot the machine and run freebsd-update install again to finish the upgrade. If anything breaks, just enable the previous BE and you're back where you started.

You could also just "clone" a pool by adding and then detaching mirror devices. This is also a viable solution to backup a pool e.g. before applying major changes or as in your case if you want to reinstall the OS completely from scratch (for whatever reason... it's not that we need to do that on a regular basis like on windows boxes).
Can you share any link of Tutorial about this, so I can practice it? Thanks
 
offtopic:
Snapshot works very well with UFS.
For smallsized storage like your 700GB - UFS and geom* might be a better choice for most cases.
I use ZFS for a 120G SSD on my laptop. I do not trust UFS. UFS is only for low RAM VPS.
Why advertise for UFS when ZFS is FreeBSD's selling point? :)
 
Back
Top