From owner-freebsd-bugs@freebsd.org Fri Nov 13 10:01:23 2015 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5A06AA2DA0D for ; Fri, 13 Nov 2015 10:01:23 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 461F31ADA for ; Fri, 13 Nov 2015 10:01:23 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id tADA1MuN075323 for ; Fri, 13 Nov 2015 10:01:22 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 159222] [boot0] unusual behavior writing boot0 from single user mode Date: Fri, 13 Nov 2015 10:01:23 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: longwitz@incore.de X-Bugzilla-Status: In Progress X-Bugzilla-Priority: Normal X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Nov 2015 10:01:23 -0000 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 ffs.label/disks2a 5 r1w0e0 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.