FreeBSD 12.x with ZFS: Read-write access in single-user mode

avatar
(Edited)

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

After issuing the first command, the system replied that the readonly variable can now only be expressed in terms of on or off, as so:

# zfs set readonly=off zroot
# zfs mount -a

With that I was able to comment out the offending line in my /etc/hosts file, and then reboot and login as usual. From there I tried booting CDE from my .xinitrc file (with /usr/local/dt/bin/dtsession), and from there was able to ascertain the buggy /etc/hosts file as the cause of my dtlogin problems. From there I was able to take corrective action, and was soon sailing the seas of outdated desktop bliss.

20200511.jpg

Crazy about the girl: this post being edited in vi within CDE.

And so, by going into excruciating detail about a problem that came down to a pair of ZFS commands, my aim here is to demonstrate an approach to UNIX problem solving, albeit from the perspective of a casual user, and not an IT professional.

The main takeaways here are:

  • Don't give up too quickly and reinstall a system (which I myself have done an embarrassing number of times). Instead, it is better to stop, take a breathe, and ask yourself if you are taking all factors into consideration.
  • Regarding online solution hunting, consider what question really needs to be asked (or how exactly it should be posed). Put another way, don't immediately assume that any answer you find online is incorrect in and of itself is wrong, but rather consider the possibility that you aren't framing your question correctly or specifically enough.
  • Where newly-installed desktop environments are concerned, try booting the desktop independently of any graphical login (such as with startx at the command line, in combination with your $HOME/.xinitrc file). That way, if it refuses to cooperate you can easily back out and troubleshoot without going the the silliness described above.


0
0
0.000
0 comments