From owner-freebsd-hackers@FreeBSD.ORG Sat Sep 15 02:23:53 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 919C1106566B for ; Sat, 15 Sep 2012 02:23:53 +0000 (UTC) (envelope-from wblock@wonkity.com) Received: from wonkity.com (wonkity.com [67.158.26.137]) by mx1.freebsd.org (Postfix) with ESMTP id 4E4AA8FC08 for ; Sat, 15 Sep 2012 02:23:53 +0000 (UTC) Received: from wonkity.com (localhost [127.0.0.1]) by wonkity.com (8.14.5/8.14.5) with ESMTP id q8F2NqfI036670; Fri, 14 Sep 2012 20:23:52 -0600 (MDT) (envelope-from wblock@wonkity.com) Received: from localhost (wblock@localhost) by wonkity.com (8.14.5/8.14.5/Submit) with ESMTP id q8F2NpIG036667; Fri, 14 Sep 2012 20:23:52 -0600 (MDT) (envelope-from wblock@wonkity.com) Date: Fri, 14 Sep 2012 20:23:51 -0600 (MDT) From: Warren Block To: Yuri In-Reply-To: <5053C9A1.3030605@rawbw.com> Message-ID: References: <5053C9A1.3030605@rawbw.com> User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.7 (wonkity.com [127.0.0.1]); Fri, 14 Sep 2012 20:23:52 -0600 (MDT) Cc: 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 02:23:53 -0000 On Fri, 14 Sep 2012, 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. Did you actually try gpart? GEOM prevents writes to providers that are in use, but gpart should handle it correctly if the problem is just that fdisk doesn't understand GEOM. # gpart set -a active -i 1 ada0 If that fails, the provider is in use, usually mounted. The safety can be disabled, but it's better to figure out what has it in use.