Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Nov 2015 10:01:23 +0000
From:      bugzilla-noreply@freebsd.org
To:        freebsd-bugs@FreeBSD.org
Subject:   [Bug 159222] [boot0] unusual behavior writing boot0 from single user mode
Message-ID:  <bug-159222-8-THj13IJlyw@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-159222-8@https.bugs.freebsd.org/bugzilla/>
References:  <bug-159222-8@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=159222

longwitz@incore.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |longwitz@incore.de

--- Comment #5 from longwitz@incore.de ---
Writing to the first block of the disk in FreeBSD 8 with mounted readonly root
partition always results in "Device not configured", when the root partition
was never mounted for write before. This is normal behaviour of GEOM in FreeBSD
8. Also this is well known to Soekris users, because nanobsd.sh does not mount
the root partition for write (root_rw_mount="NO") and therefore boot0cfg called
in updatepX fails with "Device not configured".

After boot of FreeBSD 8 the root partition is initially mounted readonly
and sysctl -b  kern.geom.confxml gives

  <geom id="0xc5fa8480">
      <class ref="0xc0a72380"/>
      <name>ffs.label/disks2a</name>
      <rank>5</rank>
        <consumer id="0xc5f8dcc0">
          <geom ref="0xc5fa8480"/>
          <provider ref="0xc5f6f880"/>
          <mode>r1w0e0</mode>
        </consumer>
    </geom>

After "mount -uw /; mount -ur" the mode changes to r1w0e1 and the root
partition will not disappear any longer, when a program tries to write to the
first block of the disk. This magic in FreeBSD 8 comes from the source
ffs_vfsops.c:

mount rootfs readonly:
       /*
         * If we are a root mount, drop the E flag so fsck can do its magic.
         * We will pick it up again when we remount R/W.
         */
        if (error == 0 && ronly && (mp->mnt_flag & MNT_ROOTFS))
                error = g_access(cp, 0, 0, -1);

mount -uw / (called from /etc/rc.d/root):
       /*
         * If we're the root device, we may not have an E count
         * yet, get it now.
         */
        if (ump->um_cp->ace == 0)
                error = g_access(ump->um_cp, 0, 1, 1);
        else
                error = g_access(ump->um_cp, 0, 1, 0);

On my Soekris boxes I prefer to leave the rootfs readonly all the time and
use the following patch for boot0cfg to avoid any trouble with "Device not
configured":

--- boot0cfg.c.orig     2015-03-25 15:40:49.000000000 +0100
+++ boot0cfg.c  2015-06-09 20:32:53.000000000 +0200
@@ -352,21 +352,22 @@
     char *pname;
     struct gctl_req *grq;

-    fd = open(fname, O_WRONLY | flags, 0666);
-    if (fd != -1) {
-       n = write(fd, mbr, mbr_size);
-       close(fd);
-       if (n != mbr_size)
-          errx(1, "%s: short write", fname);
-       return;
-    }
-
     /*
      * If we're called to write to a backup file, don't try to
      * write through GEOM. It only generates additional errors.
+     * Otherwise if we're called to write to disk, don't try to
+     * open the disk for writing.
      */
-    if (flags != 0)
+    if (flags != 0) {
+       fd = open(fname, O_WRONLY | flags, 0666);
+       if (fd != -1) {
+          n = write(fd, mbr, mbr_size);
+          close(fd);
+          if (n != mbr_size)
+             errx(1, "%s: short write", fname);
+       }
        return;
+    }

     /* Try open it read only. */
     fd = open(fname, O_RDONLY);

-- 
You are receiving this mail because:
You are the assignee for the bug.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-159222-8-THj13IJlyw>