Page MenuHomeFreeBSD

D57310.diff
No OneTemporary

D57310.diff

diff --git a/usr.sbin/boot0cfg/boot0cfg.8 b/usr.sbin/boot0cfg/boot0cfg.8
--- 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 May 28, 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 @@
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 @@
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,13 @@
.Pp
.Dl "boot0cfg -m 0x5 ada0"
.Pp
+To enable just slices 1 and 3 in the menu, but using a file:
+.Dl "boot0cfg -m 0x5 /boot/boot0"
+.Pp
+Then embedding the bootcode file using
+.Xr gpart 8 :
+.Dl "gpart bootcode -b /boot/boot0 ada0"
+.Pp
To go back to non-interactive booting, use
.Xr gpart 8
to install the default MBR:
@@ -199,4 +214,5 @@
.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
--- a/usr.sbin/boot0cfg/boot0cfg.c
+++ b/usr.sbin/boot0cfg/boot0cfg.c
@@ -115,6 +115,7 @@
int
main(int argc, char *argv[])
{
+ struct stat sb;
u_int8_t *mbr, *boot0;
int boot0_size, mbr_size;
const char *bpath, *fpath;
@@ -183,9 +184,15 @@
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;
@@ -375,6 +382,7 @@
struct gctl_req *grq;
const char *errmsg;
char *pname;
+ struct stat sb;
ssize_t n;
int fd;
@@ -394,20 +402,39 @@
if (flags != 0)
err(1, "can't open file %s to write backup", fname);
- /* Try open it read only. */
+ /*
+ * Try 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;
}
+ /*
+ * Re-open it in write-only mode and flash 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");
@@ -594,6 +621,6 @@
{
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);
}

File Metadata

Mime Type
text/plain
Expires
Wed, Jul 22, 1:20 PM (6 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35365272
Default Alt Text
D57310.diff (4 KB)

Event Timeline