Bug 213549

Summary: /etc/rc remounts root readonly if /firstboot exists
Product: Base System Reporter: Adam McDougall <ebay>
Component: confAssignee: Warner Losh <imp>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: ---    
Version: 11.0-STABLE   
Hardware: Any   
OS: Any   

Description Adam McDougall 2016-10-16 23:41:20 UTC
I have some custom system setup scripts that leverage "firstboot" support but I discovered problems when trying them on FreeBSD 11 -stable and -release. The short version is /etc/rc attempts to remount the / partition as readonly (ro) at the end after it deletes /firstboot. I think this issue originated with:
https://svnweb.freebsd.org/base?view=revision&revision=293115

Abbreviated code:
if [ -e ${firstboot_sentinel} ]; then
        [ ${root_rw_mount} = "yes" ] || mount -uw /
        chflags -R 0 ${firstboot_sentinel}
        rm -rf ${firstboot_sentinel}
        [ ${root_rw_mount} = "yes" ] || mount -ur /
fi

On a stock FreeBSD 11 install, if you touch /firstboot and reboot, here are the results:
UFS: prints "mount: /dev/vtbd0s1a: Device busy" late during boot but no apparent harm
ZFS: succeeds in remounting / as ro even if it was rw to start with

Depending on your system configuration you might notice the issue immediately on the console, for example programs which need to write to / will start complaining. You can login and run mount -v to verify. Other random things fail such as recording your login in 'w' output. I do not use ${firstboot_sentinel}-reboot which might be why this was not discovered, as a reboot makes the problem go away but I do not want to reboot.

Quick hack of a fix for me: comment out the last line containing "mount -ur /" but this is not a proper fix.
Comment 1 commit-hook freebsd_committer freebsd_triage 2016-10-17 04:07:53 UTC
A commit references this bug:

Author: imp
Date: Mon Oct 17 04:07:14 UTC 2016
New revision: 307469
URL: https://svnweb.freebsd.org/changeset/base/307469

Log:
  Allow root_rw_mount to be both lower and upper case. Before, if it was
  upper case, you'd wind up with a read-only filesystem when you should
  sometimes.

  PR: 213549

Changes:
  head/etc/rc
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2016-10-17 06:14:01 UTC
Over to committer for possible MFC.
Comment 3 commit-hook freebsd_committer freebsd_triage 2017-05-22 16:08:11 UTC
A commit references this bug:

Author: gjb
Date: Mon May 22 16:07:17 UTC 2017
New revision: 318652
URL: https://svnweb.freebsd.org/changeset/base/318652

Log:
  MFC r307469 (imp):
   Allow root_rw_mount to be both lower and upper case. Before, if it was
   upper case, you'd wind up with a read-only filesystem when you should
   sometimes.

  PR: 213549
  Sponsored by:	The FreeBSD Foundation

Changes:
_U  stable/11/
  stable/11/etc/rc
Comment 4 Adam McDougall 2017-05-30 03:26:07 UTC
Sorry, the fix does not seem to work for ZFS. I verified root_rw_mount seems to be set to YES but the root filesystem still gets mounted as r/o. I tested with ZFS on r318855 and ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/ISO-IMAGES/11.1/FreeBSD-11.1-PRERELEASE-amd64-20170519-r318507-disc1.iso.xz. UFS appears to work though.
Comment 5 Adam McDougall 2018-05-06 02:09:48 UTC
r332037 on 4/4 may have fixed it in 11, I can no longer reproduce the symptoms on a build from 4/20 or 5/4. I did not test 10. Marking closed, thanks for whatever fixed it.