HOWTO: ZFS Madness (BEADM on FreeBSD)
0. This is SPARTA!
Some time ago I found a good, reliable way of using and installing FreeBSD and described it in my Modern FreeBSD Install   HOWTO. Now, more then a year later I come back with my experiences about that setup and a proposal of newer and probably better way of doing it.
Same as year ago, I assume that You would want to create fresh installation of FreeBSD using one or more hard disks, but also with (laptops) and without GELI based full disk encryption.
This guide was written when FreeBSD 9.0 and 8.3 were available and definitely works for 9.0, but I did not try all this on the older 8.3, if You find some issues on 8.3, let me know I will try to address them in this guide.
Earlier, I was not that confident about booting from the ZFS pool, but there is some very neat feature that made me think ZFS boot is now mandatory. If You just smiled, You know that I am thinking about Boot Environments feature from Illumos/Solaris systems.
In case You are not familiar with the Boot Environments feature, check the Managing Boot Environments with Solaris 11 Express PDF white paper . Illumos/Solaris has the beadm(1M)  utility and while Philipp Wuensche wrote the manageBE script as replacement , it uses older style used at times when OpenSolaris (and SUN) were still having a great time.
I last couple of days writing an up-to-date replacement for FreeBSD compatible beadm utility, and with some tweaks from today I just made it available at SourceForge  if You wish to test it. Currently its about 200 lines long, so it should be pretty simple to take a look at it. I tried to make it as compatible as possible with the 'upstream' version, along with some small improvements, it currently supports basic functions like list, create, destroy and activate.
My implementation is also style compatible with current Illumos/Solaris beadm(1M) which is like the example below.
2. Now You're Thinking with Portals
The main purpose of the Boot Environments concept is to make all risky tasks harmless, to provide an easy way back from possible troubles. Think about upgrading the system to newer version, an update of 30+ installed packages to latest versions, testing software or various solutions before taking the final decision, and much more. All these tasks are now harmless thanks to the Boot Environments, but this is just the tip of the iceberg.
You can now move desired boot environment to other machine, physical or virtual and check how it will behave there, check hardware support on the other hardware for example or make a painless hardware upgrade. You may also clone Your desired boot environment and ... start it as a Jail for some more experiments or move Your old physical server install into FreeBSD Jail because its not that heavily used anymore but it still have to be available.
Other good example may be just created server on Your laptop inside VirtualBox virtual machine. After you finish the creation process and tests, You may move this boot environment to the real server and put it into production. Or even move it into VMware ESX/vSphere virtual machine and use it there.
As You see the possibilities with Boot Environments are unlimited.
3. The Install Process
I created 3 possible schemes which should cover most demands, choose one and continue to the next step.
3.1. Server with Two Disks
I assume that this server has 2 disks and we will create ZFS mirror across them, so if any of them will be gone the system will still work as usual. I also assume that these disks are ada0 and ada1. If You have SCSI/SAS drives there, they may be named da0 and da1 accordingly. The procedures below will wipe all data on these disks, You have been warned.
If Your server configuration has only one disk, lets assume its ada0, then You need different points 5. and 7. to make, use these instead of the ones above.
3.3. Road Warrior Laptop
The procedure is quite different for Laptop because we will use the full disk encryption mechanism provided by GELI and then setup the ZFS pool. Its not currently possible to boot off from the ZFS pool on top of encrypted GELI provider, so we will use setup similar to the Server with ... one but with additional local pool for /home and /root partitions. It will be password based and You will be asked to type-in that password at every boot. The install process is generally the same with new instructions added for the GELI encrypted local pool, I put them with different color to make the difference more visible.
1. Login as root with empty password.
2. Create initial snapshot after install.
# zfs snapshot -r sys/ROOT/default@install
3. Set new root password.
4. Set machine's hostname.
# echo hostname=hostname.domain.com >> /etc/rc.conf
5. Set proper timezone.
6. Add some swap space.
If You used the Server with ... type, then use this to add swap.
After You configured Your fresh FreeBSD system, added needed packages and services, create snapshot called configured or production so if You mess something, You can always go back in time to bring working configuration back. mess something.
# zfs snapshot -r sys/ROOT/default@configured
5. Enable Boot Environments
Here are some simple instructions on how to download and enable the beadm command line utility for easy Boot Environments administration.
Now we have a working ZFS only FreeBSD system, I will put some example here about what You now can do with this type of installation and of course the Boot Environments feature.
6.1. Create New Boot Environment Before Upgrade
1. Create new environment from the current one.
# beadm create upgrade
2. Activate it.
# beadm activate upgrade
3. Reboot into it.
# shutdown -r now
4. Mess with it.
You are now free to do anything You like fo or the upgrade process, but even if You break everything, You still have a working default working environment.
6.2. Perform Upgrade within a Jail
This concept is about creating new boot environment from the desired one, lets call it jailed, then start that new environment inside a FreeBSD Jail and perform upgrade there. After You have finished all tasks related to this upgrade and You are satisfied with the achieved results, shutdown that Jail, set the boot environment into that just upgraded Jail called jailed and reboot into just upgraded system without any risks.
1. Create new boot environment called jailed.
# beadm create -e default jailed
2. Create /usr/jails directory.
# mkdir /usr/jails
3. Set mount point of new boot environment to /usr/jails/jailed dir.
# zfs set mountpoint=/usr/jails/jailed sys/ROOT/jailed
3.1. Make new Jail dataset mountable.
# zfs set canmount=noauto sys/ROOT/jailed
3.2. Mount new Jail dataset.
# zfs mount sys/ROOT/jailed
4. Enable FreeBSD Jails mechanism and the jailed Jail in /etc/rc.conf file.
# cat << EOF >> /etc/rc.conf
5. Start the Jails mechanism.
# /etc/rc.d/jail start
Starting jails: jailed.
6. Check if the jailed Jail started.
# jexec 1 tcsh
8. PERFORM ACTUAL UPGRADE.
9. Stop the jailed Jail.
# /etc/rc.d/jail stop
Stopping jails: jailed.
10. Disable Jails mechanism in /etc/rc.conf file.
# sed -i '' -E s/"^jail_enable.*$"/"jail_enable=NO"/g /etc/rc.conf
11. Activate just upgraded jailed boot environment.
# beadm activate jailed
12. Reboot into upgraded system.
6.3. Import Boot Environment from Other Machine
Lets assume, that You need to upgrade or do some major modification to some of Your servers, You will then create new boot environment from the default one, move it to other 'free' machine, perform these tasks there and after everything is done, move the modified boot environment to the production without any risks. You may as well transport that environment into You laptop/workstation and upgrade it in a Jail like in step 6.2 of this guide.
1. Create new environment on the production server.
# beadm create upgrade
2. Send the upgrade environment to test server.
# zfs send sys/ROOT/upgrade | ssh TEST zfs recv -u sys/ROOT/upgrade
3. Activate the upgrade environment on the test server.
# beadm activate upgrade
4. Reboot into the upgrade environment on the test server.
# shutdown -r now
5. PERFORM ACTUAL UPGRADE AFTER REBOOT.
6. Sent the upgraded upgrade environment onto production server.
# zfs send sys/ROOT/upgrade | ssh PRODUCTION zfs recv -u sys/ROOT/upgrade
7. Activate upgraded upgrade environment on the production server.
# beadm activate upgrade
8. Reboot into the upgrade environment on the production server.
# shutdown -r nowCourier New
The last part of the HOWTO remains the same as Year ago ...
You can now add your users, services and packages as usual on any FreeBSD system, have fun ;)
Thanks for sharing :)
That is awesome. Thank you! :)
Little ERRATA, thanks to srivo:
Updates to the beadm utility:
- minor fixes and clean
- added -F switch for destroy option - does not need confirmation upon destroy
- implemented umount option with -f switch for umount -f (force)
- implemented mount option with several variants of usage, examples:
The beadm 0.8 has just been commited to the Ports tree:
|All times are GMT -5. The time now is 07:40 AM.|