From nobody Wed Aug 5 00:27:01 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hFB795G0Vz6ngxc for ; Wed, 05 Aug 2026 00:27:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hFB793BMkz46M3 for ; Wed, 05 Aug 2026 00:27:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785889621; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tvkesUoc2Hv/v0Tg0CHlL1LczwMGplhyN9UlDl/VuR0=; b=DQ29gX31JVPAxYcZQmTiCsuu4cJdZo5uomU0MRYOuhFJvy3jhDopePc/gmp+znMc1SjJUz cN8IzyrlPGYsUM+XA+P+7TNv0BpjcIxdwtymS7KJCcjZrImdu1xP9B3/8Blro2d80fSe7d I7aJEaSd1v/7fsalJxMRzauzhXV9qRz2nhsutSjxuvY2cvZH24zec29lPy7N7a08zuMfE6 HpFFW/zZhzetXUU6xzuN/AmIbjYG33ilWayXjC1Of/9wCaE+jPA1rFo0fUjCoUroG0GnOm DiQSbmhg00hVWYxBBkeRR9ndSLT2YMy6XOO0BVa0P9MES+DTw5dSuu0xZq/4HA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785889621; a=rsa-sha256; cv=none; b=wHnfTHZaXr6GaSTXzDud8RpAP/OEP/icIBe+56EOeAtQ4ZafVE5Z/IPfxsFQSY3NW7jNZz J5koYrQb0XSvFK5RyKQeC8bGxEQ7IxfD2U5FzDPU6x2WGxR5KWpayNPhA+x+HcZUONuVWc qXKzcNdGR7f9QaBn5IZZBN+N70dqM6+YvIM9liHlQPN7uk4rsQImuidRd8c7mx/hsuDfKv du6/NJCyJUz9dRO2VZyg9XyRbj6mR1N4+IGG+FL0sOgj5CLOdUjSYEUQ0sV3p+dHiBFNNn uQbKosG7nypRDQiB3jY7UcONJ+OxEvCVv1kzP4kuzVKIEhol5brwg1OHF+a8eg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785889621; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tvkesUoc2Hv/v0Tg0CHlL1LczwMGplhyN9UlDl/VuR0=; b=KNBX8HceW3+zK1ARsanW6VVTFT7dOstAhwIedQfWsvNHaRZEeJ04NrUqds8UgMz03eSvYB MGC0PaA2XrdLcnnOogE6PXl/oo/C5LP486tuBgjmTBAZa6juADCK3CIl7mM6SSHW3ps21r 8XgsUc2NZ2uVpKg/NzY3Dt6fP9vjljh43vXU4ZsnTG4qA2eUTXOxXwyIjSKw2bMKMrck/8 /UgWuhksrErT50D6CxWnkNw3zFoTaWfKjw81RBSDAAW4RnuBKNvNJBEIjQlIXazEVSFufu NVIWR/6dj6oIBlgvFsTCcaUr2/fRGtdRGSixY23s5nQpQ/gr1anBkMZdg2r51Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hFB791K9yz19H7 for ; Wed, 05 Aug 2026 00:27:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 26e58 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 05 Aug 2026 00:27:01 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jose Luis Duran Subject: git: 8c15c141db92 - stable/14 - boot0cfg: Also allow a file as a trailing argument List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jlduran X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 8c15c141db928c42314f2d6d972c022de20df757 Auto-Submitted: auto-generated Date: Wed, 05 Aug 2026 00:27:01 +0000 Message-Id: <6a728355.26e58.557f1b15@gitrepo.freebsd.org> The branch stable/14 has been updated by jlduran: URL: https://cgit.FreeBSD.org/src/commit/?id=8c15c141db928c42314f2d6d972c022de20df757 commit 8c15c141db928c42314f2d6d972c022de20df757 Author: Jose Luis Duran AuthorDate: 2026-07-29 16:11:53 +0000 Commit: Jose Luis Duran CommitDate: 2026-08-05 00:26:04 +0000 boot0cfg: Also allow a file as a trailing argument Modify the disk check to allow arbitrary files as the trailing argument instead of requiring a live GEOM disk provider. This enables modifying a boot0 binary file in-place before flashing it to a disk via gpart bootcode, or using it directly as an argument to mkimg's partition specification, as these tools cannot directly adjust the parameters of the boot0 boot manager. Reviewed by: imp, jhb MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D57310 (cherry picked from commit 4007d914e7973bca8ac488ab50aca56964eed90f) --- usr.sbin/boot0cfg/boot0cfg.8 | 32 ++++++++++++++++++++++++++------ usr.sbin/boot0cfg/boot0cfg.c | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/usr.sbin/boot0cfg/boot0cfg.8 b/usr.sbin/boot0cfg/boot0cfg.8 index d2e01ada3552..6688d97c65fb 100644 --- a/usr.sbin/boot0cfg/boot0cfg.8 +++ b/usr.sbin/boot0cfg/boot0cfg.8 @@ -22,7 +22,7 @@ .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 1, 2013 +.Dd July 29, 2026 .Dt BOOT0CFG 8 .Os .Sh NAME @@ -40,7 +40,7 @@ .Op Fl o Ar options .Op Fl s Ar slice .Op Fl t Ar ticks -.Ar disk +.Ar disk | file .Sh DESCRIPTION The .Fx @@ -62,9 +62,15 @@ The utility optionally installs the .Sq boot0 boot manager on the specified -.Ar disk ; +.Ar disk +or +.Ar file ; and allows various operational parameters to be configured. .Pp +If a file is specified as the target argument, all operations are +performed entirely in-place. +This allows for offline payload preparation. +.Pp On PCs, a boot manager typically occupies sector 0 of a disk, which is known as the Master Boot Record (MBR). The MBR contains both code (to which control is passed by the PC BIOS) @@ -104,8 +110,10 @@ Specify that a backup copy of the preexisting MBR should be written to This file is created if it does not exist, and replaced if it does. .It Fl i Ar volume-id Specifies a volume-id (in the form XXXX-XXXX) to be saved at location -0x1b8 in the MBR. This information is sometimes used by NT, XP and Vista -to identify the disk drive. The option is only compatible with version 2.00 +0x1b8 in the MBR. +This information is sometimes used by NT, XP and Vista to identify the +disk drive. +The option is only compatible with version 2.00 of the 512-byte boot block. .It Fl m Ar mask Specify slices to be enabled/disabled, where @@ -177,6 +185,17 @@ To enable just slices 1 and 3 in the menu: .Pp .Dl "boot0cfg -m 0x5 ada0" .Pp +Create a copy of +.Sq boot0 +with only slices 1 and 3 enabled in the menu and install that onto a disk using +.Xr gpart 8 : +.Pp +.Bd -literal -offset indent -compact +cp /boot/boot0 /boot/boot0.custom +boot0cfg -m 0x5 /boot/boot0.custom +gpart bootcode -b /boot/boot0.custom ada0 +.Ed +.Pp To go back to non-interactive booting, use .Xr gpart 8 to install the default MBR: @@ -199,4 +218,5 @@ Use of the .Sq setdrv option with an incorrect -d operand may cause the boot0 code to write the MBR to the wrong disk, thus trashing its previous -content. Be careful. +content. +Be careful. diff --git a/usr.sbin/boot0cfg/boot0cfg.c b/usr.sbin/boot0cfg/boot0cfg.c index 8c00329f53d9..8e7a3dbf9cad 100644 --- a/usr.sbin/boot0cfg/boot0cfg.c +++ b/usr.sbin/boot0cfg/boot0cfg.c @@ -116,6 +116,7 @@ static int v_flag; int main(int argc, char *argv[]) { + struct stat sb; u_int8_t *mbr, *boot0; int boot0_size, mbr_size; const char *bpath, *fpath; @@ -184,9 +185,15 @@ main(int argc, char *argv[]) argv += optind; if (argc != 1) usage(); - disk = g_device_path(*argv); - if (disk == NULL) - errx(1, "Unable to get providername for %s\n", *argv); + if (stat(*argv, &sb) == 0 && S_ISREG(sb.st_mode)) { + disk = strdup(*argv); + if (disk == NULL) + err(1, "strdup"); + } else { + disk = g_device_path(*argv); + if (disk == NULL) + errx(1, "Unable to get providername for %s\n", *argv); + } up = B_flag || d_arg != -1 || m_arg != -1 || o_flag || s_arg != -1 || t_arg != -1; @@ -374,6 +381,7 @@ write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size, int disable_dsn) { struct gctl_req *grq; + struct stat sb; const char *errmsg; char *pname; ssize_t n; @@ -395,20 +403,40 @@ write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size, if (flags != 0) err(1, "can't open file %s to write backup", fname); - /* Try open it read only. */ + /* + * Try to open it read only to pass to GEOM, + * or inspect if it's a regular file. + */ fd = open(fname, O_RDONLY); if (fd == -1) { warn("error opening %s", fname); return; } + /* + * If name is a regular file, re-open it in write-only mode + * and write the MBR straight to it. + */ + if (fstat(fd, &sb) == 0 && S_ISREG(sb.st_mode)) { + close(fd); + fd = open(fname, O_WRONLY); + if (fd == -1) + err(1, "can't open %s for writing", fname); + n = write(fd, mbr, mbr_size); + close(fd); + if (n != mbr_size) + errx(1, "%s: short write", fname); + return; + } + pname = g_providername(fd); + close(fd); if (pname == NULL) { warn("error getting providername for %s", fname); return; } - /* First check that GEOM_PART is available */ + /* Check that GEOM_PART is available */ if (geom_class_available("PART") != 0) { grq = gctl_get_handle(); gctl_ro_param(grq, "class", -1, "PART"); @@ -595,6 +623,6 @@ usage(void) { fprintf(stderr, "%s\n%s\n", "usage: boot0cfg [-Bv] [-b boot0] [-d drive] [-f file] [-m mask]", - " [-o options] [-s slice] [-t ticks] disk"); + " [-o options] [-s slice] [-t ticks] disk | file"); exit(1); }