FreeBSD 12.x with ZFS: Read-write access in single-user mode
It has been about two years since I last locked myself out of my UNIX system, so I figured it was high time to amuse the masses with another round of slapstick.
Before I go any further, I should say that both of these screw-ups occurred in the course of either installing or optimizing CDE. If that isn’t a sign of devotion to an antiquated desktop environment, then what is? (Needless to say, I’m crazy about the girl.)
This time around, I had installed CDE on my FreeBSD 12.1 box, but do an error in the /etc/hosts file (a superfluous and inaccurate hostname line that should have been commented out), CDE’s graphical login program (dtlogin) would keep looping back to itself once the username and password were entered, rather than proceed to the desktop. Even selecting “command line login” from the options menu would produce the same result.
While I had no idea (yet) what was causing this error, I decided that my first task would be to get at the /etc/rc.login file to comment out the line that triggers dtlogin at boot (“/usr/local/dt/bin/dtlogin”), and then try to fix CDE once I had normal access to my system. (With there being a certain amount of important data that hadn’t yet been backed up, simply throwing in the towel and reinstalling the system from scratch was an absolute non-starter.)
The catch, however, was that it would mean booting the machine into single-user mode (to bypass /etc/rc.login), which by default mounts the root filesystem as ‘read-only’.
I spent close to an hour futzing around with all sorts of combinations of mount and its options (including -a, -u, -f, -rw, etc.), but to no avail. It took me a while to figure it out, but the information I was finding online, and in my aging 2008 edition Michael Lucas’ indispensable Absolute FreeBSD, pertained either to non-ZFS installations of FreeBSD, or perhaps to procedures that no longer pertain to ZFS. (My Google searches while using an OpenIndiana live CD consisted of FreeBSD single user read write.)
At some point I started to have an inkling that I needed to word my query in such a way that front-loaded the fact I’m running FreeBSD with ZFS, so I went with FreeBSD zfs single user read write. Right off the bat, I found a forum message that recommended the following pair of commands:
# zfs set readonly=false zroot
# zfs mount -a