Why fdisk can't open root disk with MBR for writing?

Julian H. Stacey jhs at berklix.com
Sat Sep 15 13:23:30 UTC 2012


Hi Yuri & hackers,

Garrett Cooper wrote:
> On Fri, Sep 14, 2012 at 5:19 PM, Yuri <yuri at rawbw.com> 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.


More information about the freebsd-hackers mailing list