Bug 231881 - boot0cfg can not configure "version 1.0" boot0 due to bug in gpart_mbr bootcode
Summary: boot0cfg can not configure "version 1.0" boot0 due to bug in gpart_mbr bootcode
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Dag-Erling Smørgrav
URL: https://reviews.freebsd.org/D17386
Keywords: regression
Depends on:
Blocks:
 
Reported: 2018-10-02 16:39 UTC by Lev A. Serebryakov
Modified: 2023-01-13 13:52 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lev A. Serebryakov freebsd_committer freebsd_triage 2018-10-02 16:39:23 UTC
boot0/boot0sio have disk serial number compiled-in by default. It is named "version 2" boot block by boot0cfg(8) and this format places 4 byte Disk Serial Number where "version 1" boot block contains options.

Support for disk serial number in boot0/boot0sio is optional, and could be turned off to save some bytes, needed for other options.

boot0cfg(8) properly supports old placement of boot block options, properly detect boot block without disk serial number support and properly prepare options for it.

Problem is, boot0cfg(8) uses "gpart bootcode" command to wriet boot block with new options back to disk.

And gmart_mbr always try to save disk serial number, which kills options if boot block is "version 1":

static int
g_part_mbr_bootcode(struct g_part_table *basetable, struct g_part_parms *gpp)
{
	struct g_part_mbr_table *table;
	uint32_t dsn;

	if (gpp->gpp_codesize != MBRSIZE)
		return (ENODEV);

	table = (struct g_part_mbr_table *)basetable;
	dsn = *(uint32_t *)(table->mbr + DOSDSNOFF);
	bcopy(gpp->gpp_codeptr, table->mbr, DOSPARTOFF);
	if (dsn != 0)
		*(uint32_t *)(table->mbr + DOSDSNOFF) = dsn;
	return (0);
}

Sometimes, it leads to complete bogus options written which kill boot0/boot0sio (it have invalid slice mask, for example, and is unable to boot at all) and sometimes it simply didn't give user ability to change boot0/boot0sio options.
Comment 1 Lev A. Serebryakov freebsd_committer freebsd_triage 2018-10-02 22:14:10 UTC
https://reviews.freebsd.org/D17386
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2020-08-15 03:38:17 UTC
Committed via rS341067 Nov 27 2018.
Comment 3 Kubilay Kocak freebsd_committer freebsd_triage 2020-08-17 03:55:53 UTC
^Triage:

 - Assign to committer that resolved
 - Correct resolution (FIXED, by way of change/commit)

Re-open:

 - base r341067 was tagged for MFC, but i couldnt not find corresponding merges to either stable/12 or stable/11. Did this end up being merged? Apologies if I missed it.
Comment 4 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2023-01-13 13:52:29 UTC
I have no recollection of this.  I don't think it was merged and I'm not sure there's much point in doing so now since there will not be another 11.x or 12.x release.