From owner-freebsd-hackers@FreeBSD.ORG Sat Sep 15 13:23:29 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E1A4B106564A for ; Sat, 15 Sep 2012 13:23:29 +0000 (UTC) (envelope-from jhs@berklix.com) Received: from tower.berklix.org (tower.berklix.org [83.236.223.114]) by mx1.freebsd.org (Postfix) with ESMTP id 52C328FC08 for ; Sat, 15 Sep 2012 13:23:28 +0000 (UTC) Received: from mart.js.berklix.net (pD9FBFE3C.dip.t-dialin.net [217.251.254.60]) (authenticated bits=0) by tower.berklix.org (8.14.2/8.14.2) with ESMTP id q8FDNQcR022783; Sat, 15 Sep 2012 13:23:27 GMT (envelope-from jhs@berklix.com) Received: from fire.js.berklix.net (fire.js.berklix.net [192.168.91.41]) by mart.js.berklix.net (8.14.3/8.14.3) with ESMTP id q8FDNEP6016878; Sat, 15 Sep 2012 15:23:14 +0200 (CEST) (envelope-from jhs@berklix.com) Received: from fire.js.berklix.net (localhost [127.0.0.1]) by fire.js.berklix.net (8.14.4/8.14.4) with ESMTP id q8FDMobF058992; Sat, 15 Sep 2012 15:22:56 +0200 (CEST) (envelope-from jhs@fire.js.berklix.net) Message-Id: <201209151322.q8FDMobF058992@fire.js.berklix.net> To: Garrett Cooper From: "Julian H. Stacey" Organization: http://berklix.com BSD Unix Linux Consultancy, Munich Germany User-agent: EXMH on FreeBSD http://berklix.com/free/ X-URL: http://www.berklix.com In-reply-to: Your message "Fri, 14 Sep 2012 17:29:22 PDT." Date: Sat, 15 Sep 2012 15:22:50 +0200 Sender: jhs@berklix.com Cc: Yuri , freebsd-hackers@freebsd.org Subject: Re: Why fdisk can't open root disk with MBR for writing? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Sep 2012 13:23:30 -0000 Hi Yuri & hackers, Garrett Cooper wrote: > On Fri, Sep 14, 2012 at 5:19 PM, Yuri wrote: > > I am trying to change the active partition in MBR. > > This should be a matter of changing only two bits (clearing one in one byte > > and setting another one in another byte). > > > > However, fdisk complains: > > fdisk: Failed to write MBR. Try to use gpart(8). > > > > truss reveals that fdisk failed to open the root disk for writing: > > open("/dev/ad4",O_RDWR,00) ERR#1 'Operation not > > permitted' > > open("/dev/ad4",O_RDONLY,00) = 3 (0x3) > > ... > > ... > > pwrite(0x3,0x34048200,0x200,0x0,0x0,0x0) ERR#9 'Bad file descriptor' > > Failed to write MBR. Try to use gpart(8) > > > > The question is: why the disk can't be open RW under root? > > The secondary issue is the bug in fdisk: once -a option is supplied and it > > can't open it RW it should just say so, and not suggest using gpart because > > gpart will probably have the same issue. > > 1. What version of FreeBSD? > 2. What do you have set for kern.geom.debug_flags? > 3. Is /dev/ad4 (or any partitions / slices under it) currently in use? > > Thanks! > -Garrett I have been applying this diff to my man fdisk: http://berklix.com/~jhs/src/bsd/fixes/FreeBSD/src/gen/sbin/fdisk/ *** 8.0-RELEASE/src/sbin/fdisk/fdisk.8 Sat Mar 14 22:32:16 2009 --- new-generic/src/sbin/fdisk/fdisk.8 Sat Mar 14 22:35:10 2009 *************** *** 462,464 **** --- 462,468 ---- The .Xr bsdlabel 8 command must be used for this. + .Pp + When running multi user, you cannot write unless you first run this: + .br + sysctl kern.geom.debugflags=16 I never submitted it as a send-pr, anyone think I should submit it to help save people ? Cheers, Julian -- Julian Stacey, BSD Unix Linux C Sys Eng Consultant, Munich http://berklix.com Reply below not above, like a play script. Indent old text with "> ". Send plain text. Not: HTML, multipart/alternative, base64, quoted-printable.