Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 31 May 2000 23:17:36 +0100 (BST)
From:      iedowse@maths.tcd.ie
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   i386/18923: boot0cfg(8) cannot select default boot slice
Message-ID:  <200005312317.aa66969@walton.maths.tcd.ie>

next in thread | raw e-mail | index | archive | help


>Number:         18923
>Category:       i386
>Synopsis:       boot0cfg(8) cannot select default boot slice
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 31 15:20:02 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Ian Dowse
>Release:        FreeBSD 3.4-STABLE i386
>Organization:
		School of Mathematics
		Trinity College, Dublin
>Environment:

	FreeBSD 3.x, 4.x or 5.0-current

>Description:

	boot0cfg(8) currently has no way to select the default boot
	slice. Having such a mechanism is useful when boot0 is used
	with the `noupdate' option. Since turning on `noupdate'
	for the first time requires booting FreeBSD (which makes
	FreeBSD the default), there is no direct way to make some
	non-FreeBSD partition the permanent default.

	[Indirect ways to achieve this which do work include booting
	FreeBSD from a floppy or CDROM (so as not to disturb the current
	default slice) and then running boot0cfg, or manually editing
	the byte at offset 0x1b9 in the MBR.]

	The patch included below adds a new `-s' option to boot0cfg
	that allows the default boot slice to be configured.

>How-To-Repeat:

	- Take a disk with two slices:

		F1 Dos
		F2 FreeBSD

	- Attempt to make "F1 Dos" the permanent default, so it will
	always be the default regardless of the last selection made.

	- Discover that in order to run "boot0cfg -o noupdate", one must
	first boot FreeBSD. Running "boot0cfg -o noupdate" then makes
	"F2 FreeBSD" the permanent default.

>Fix:

Apply the following patch in src/usr.sbin/boot0cfg.

Index: boot0cfg.8
===================================================================
RCS file: /FreeBSD/FreeBSD-CVS/src/usr.sbin/boot0cfg/boot0cfg.8,v
retrieving revision 1.5
diff -u -r1.5 boot0cfg.8
--- boot0cfg.8	1999/08/28 01:15:38	1.5
+++ boot0cfg.8	2000/05/31 21:37:19
@@ -38,6 +38,7 @@
 .Op Fl f Ar file
 .Op Fl m Ar mask
 .Op Fl o Ar options
+.Op Fl s Ar slice
 .Op Fl t Ar ticks
 .Ar disk
 .Sh DESCRIPTION
@@ -118,6 +119,14 @@
 .Sq noupdate
 option causes the MBR to be treated as read-only.
 .El
+.It Fl s Ar slice
+Set the default boot selection to
+.Ar slice .
+Values between 1 and 4 refer to slices; a value of 5 refers to the
+option of booting from a second disk. This would normally be used in
+conjunction with the
+.Sq noupdate
+option.
 .It Fl t Ar ticks
 Set the timeout value to
 .Ar ticks .
Index: boot0cfg.c
===================================================================
RCS file: /FreeBSD/FreeBSD-CVS/src/usr.sbin/boot0cfg/boot0cfg.c,v
retrieving revision 1.7
diff -u -r1.7 boot0cfg.c
--- boot0cfg.c	1999/08/28 01:15:38	1.7
+++ boot0cfg.c	2000/05/31 21:45:08
@@ -44,6 +44,7 @@
 
 #define MBRSIZE         512     /* master boot record size */
 
+#define OFF_OPT         0x1b9   /* offset: default boot option */
 #define OFF_DRIVE	0x1ba	/* offset: setdrv drive */
 #define OFF_FLAGS       0x1bb   /* offset: option flags */
 #define OFF_TICKS       0x1bc   /* offset: clock ticks */
@@ -89,17 +90,17 @@
     const char *bpath, *fpath, *disk;
     ssize_t n;
     int B_flag, v_flag, o_flag;
-    int d_arg, m_arg, t_arg;
+    int d_arg, m_arg, s_arg, t_arg;
     int o_and, o_or;
     int fd, fd1, up, c, i;
 
     bpath = "/boot/boot0";
     fpath = NULL;
     B_flag = v_flag = o_flag = 0;
-    d_arg = m_arg = t_arg = -1;
+    d_arg = m_arg = s_arg = t_arg = -1;
     o_and = 0xff;
     o_or = 0;
-    while ((c = getopt(argc, argv, "Bvb:d:f:m:o:t:")) != -1)
+    while ((c = getopt(argc, argv, "Bvb:d:f:m:o:s:t:")) != -1)
         switch (c) {
         case 'B':
             B_flag = 1;
@@ -123,6 +124,9 @@
             stropt(optarg, &o_and, &o_or);
             o_flag = 1;
             break;
+        case 's':
+            s_arg = argtoi(optarg, 1, 5, 's');
+            break;
         case 't':
             t_arg = argtoi(optarg, 1, 0xffff, 't');
             break;
@@ -134,7 +138,8 @@
     if (argc != 1)
         usage();
     disk = mkrdev(*argv);
-    up = B_flag || d_arg != -1 || m_arg != -1 || o_flag || t_arg != -1;
+    up = B_flag || d_arg != -1 || m_arg != -1 || o_flag || s_arg != -1 ||
+	   t_arg != -1;
     if ((fd = open(disk, up ? O_RDWR : O_RDONLY)) == -1)
         err(1, "%s", disk);
     if ((n = read(fd, buf, MBRSIZE)) == -1)
@@ -174,6 +179,8 @@
         buf[OFF_FLAGS] &= o_and;
         buf[OFF_FLAGS] |= o_or;
     }
+    if (s_arg != -1)
+        buf[OFF_OPT] = s_arg - 1;
     if (t_arg != -1)
         mk2(buf + OFF_TICKS, t_arg);
     if (up) {
@@ -211,6 +218,12 @@
             printf("%s", opttbl[i].tok);
         }
         printf("  ticks=%u\n", cv2(buf + OFF_TICKS));
+	printf("default_selection=F%d (", buf[OFF_OPT] + 1);
+	if (buf[OFF_OPT] < 4)
+	    printf("Slice %d", buf[OFF_OPT] + 1);
+	else
+	    printf("Drive 1");
+	printf(")\n");
     }
     return 0;
 }
@@ -316,6 +329,6 @@
 {
     fprintf(stderr, "%s\n%s\n",
     "usage: boot0cfg [-Bv] [-b boot0] [-d drive] [-f file] [-m mask]",
-    "                [-o options] [-t ticks] disk");
+    "                [-o options] [-s slice] [-t ticks] disk");
     exit(1);
 }


	


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200005312317.aa66969>