Bug 197326 - boot0cfg -s does not work unless kern.geom.debugflags=0x10
Summary: boot0cfg -s does not work unless kern.geom.debugflags=0x10
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 9.2-STABLE
Hardware: amd64 Any
: --- Affects Many People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-04 17:54 UTC by Marc Branchaud
Modified: 2015-02-04 18:00 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Branchaud 2015-02-04 17:54:52 UTC
I've found a bit of back-and-forth on this online, and indeed r227553 says that boot0cfg should not require the debugflags hack.  However, I can confirm that it does (this on a recent STABLE 9 build):

/root # boot0cfg -v da0
#   flag     start chs   type       end chs       offset         size
1   0x80      0:  2: 1   0xa5     20:254:63          126       337239
2   0x00     21:173: 1   0xa5     42:254:63       348264       342531
3   0x00     43: 89: 1   0xa5     64:254:63       696402       347823

version=2.0  drive=0x80  mask=0xf  ticks=182  bell=# (0x23)
options=packet,update,nosetdrv
volume serial ID 9090-9090
default_selection=F1 (Slice 1)
/root # boot0cfg -s 2 da0
/root # boot0cfg -v da0
#   flag     start chs   type       end chs       offset         size
1   0x80      0:  2: 1   0xa5     20:254:63          126       337239
2   0x00     21:173: 1   0xa5     42:254:63       348264       342531
3   0x00     43: 89: 1   0xa5     64:254:63       696402       347823

version=2.0  drive=0x80  mask=0xf  ticks=182  bell=# (0x23)
options=packet,update,nosetdrv
volume serial ID 9090-9090
default_selection=F2 (Slice 2)
/root #

Note that flag 0x80 is still on partition 1.  Even though the default menu selection is partition 2, rebooting at this point will boot partition 1.

However, with kern.geom.debugflags=0x10 the active flag moves to partition 2:

/root # sysctl kern.geom.debugflags=0x10
kern.geom.debugflags: 0 -> 16
/root # boot0cfg -s 2 da0
/root # boot0cfg -v da0
#   flag     start chs   type       end chs       offset         size
1   0x00      0:  2: 1   0xa5     20:254:63          126       337239
2   0x80     21:173: 1   0xa5     42:254:63       348264       342531
3   0x00     43: 89: 1   0xa5     64:254:63       696402       347823

version=2.0  drive=0x80  mask=0xf  ticks=182  bell=# (0x23)
options=packet,update,nosetdrv
volume serial ID 9090-9090
default_selection=F2 (Slice 2)
/root #

Some debugging shows that inside boot0cfg's write_mbr() function, the open(O_WRONLY) call returns -1 unless kern.geom.debugflags=0x10.

At the very least, boot0cfg should report an error when it fails to update the mbr.  Also, r227553 was wrong.

IMHO, boot0cfg should be able to update the mbr regardless of the kern.geom.debugflags setting.  I understand that others feel differently.  Perhaps a compile-time option could be added to let boot0cfg tweak the kern.geom.debugflags automatically?
Comment 1 Marc Branchaud 2015-02-04 18:00:16 UTC
Oops, r227553 is STABLE 9's MFC of r227298.