Sat Mar 10 18:42:19 2012 UTC ()
Some FAT16 filesystems don't have 'hidden sectors' correctly set to
the offset of the filesystem on the disk.
Let '-b s1blk' be used to fix the value.


(dsl)
diff -r1.84 -r1.85 src/usr.sbin/installboot/installboot.8
diff -r1.37 -r1.38 src/usr.sbin/installboot/arch/i386.c

cvs diff -r1.84 -r1.85 src/usr.sbin/installboot/installboot.8 (expand / switch to unified diff)

--- src/usr.sbin/installboot/installboot.8 2012/02/11 07:27:25 1.84
+++ src/usr.sbin/installboot/installboot.8 2012/03/10 18:42:18 1.85
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: installboot.8,v 1.84 2012/02/11 07:27:25 ast Exp $ 1.\" $NetBSD: installboot.8,v 1.85 2012/03/10 18:42:18 dsl Exp $
2.\" 2.\"
3.\" Copyright (c) 2002-2012 The NetBSD Foundation, Inc. 3.\" Copyright (c) 2002-2012 The NetBSD Foundation, Inc.
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation 6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Luke Mewburn of Wasabi Systems. 7.\" by Luke Mewburn of Wasabi Systems.
8.\" 8.\"
9.\" Redistribution and use in source and binary forms, with or without 9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions 10.\" modification, are permitted provided that the following conditions
11.\" are met: 11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright 12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer. 13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" 2. Redistributions in binary form must reproduce the above copyright
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17.\" 17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE. 28.\" POSSIBILITY OF SUCH DAMAGE.
29.\" 29.\"
30.Dd February 11, 2012 30.Dd March 10, 2012
31.Dt INSTALLBOOT 8 31.Dt INSTALLBOOT 8
32.Os 32.Os
33.Sh NAME 33.Sh NAME
34.Nm installboot 34.Nm installboot
35.Nd install disk bootstrap software 35.Nd install disk bootstrap software
36. 36.
37.Sh SYNOPSIS 37.Sh SYNOPSIS
38.Nm 38.Nm
39.Op Fl fnv 39.Op Fl fnv
40.Op Fl B Ar s2bno 40.Op Fl B Ar s2bno
41.Op Fl b Ar s1bno 41.Op Fl b Ar s1bno
42.Op Fl m Ar machine 42.Op Fl m Ar machine
43.Op Fl o Ar options 43.Op Fl o Ar options
@@ -155,26 +155,27 @@ If this option is supplied, @@ -155,26 +155,27 @@ If this option is supplied,
155.Ar secondary 155.Ar secondary
156should refer to an actual secondary bootstrap (rather than the 156should refer to an actual secondary bootstrap (rather than the
157file name of the one present in 157file name of the one present in
158.Ar filesystem ) 158.Ar filesystem )
159so that its size can be determined. 159so that its size can be determined.
160. 160.
161.It Fl b Ar s1bno 161.It Fl b Ar s1bno
162Install 162Install
163.Ar primary 163.Ar primary
164at block number 164at block number
165.Ar s1bno 165.Ar s1bno
166instead of the default location for the machine and file system type. 166instead of the default location for the machine and file system type.
167.Sy [ alpha , 167.Sy [ alpha ,
 168.Sy i386/amd64 (bootxx_fat16 only) ,
168.Sy pmax , 169.Sy pmax ,
169.Sy vax ] 170.Sy vax ]
170. 171.
171.It Fl c 172.It Fl c
172Clear (remove) any existing bootstrap instead of installing one. 173Clear (remove) any existing bootstrap instead of installing one.
173. 174.
174.It Fl e 175.It Fl e
175Edit the options of an existing bootstrap. 176Edit the options of an existing bootstrap.
176This can be use to change the options in bootxx_xxxfs files, 177This can be use to change the options in bootxx_xxxfs files,
177raw disk partitions, and the 178raw disk partitions, and the
178.Pa pxeboot_ia32.bin 179.Pa pxeboot_ia32.bin
179file. 180file.
180With 181With
@@ -443,26 +444,32 @@ Installed into the bootstrap area of the @@ -443,26 +444,32 @@ Installed into the bootstrap area of the
443.It Pa /usr/mdec/bootxx_fat16 444.It Pa /usr/mdec/bootxx_fat16
444Primary bootstrap for 445Primary bootstrap for
445.Tn MS-DOS 446.Tn MS-DOS
446.Sy FAT16 447.Sy FAT16
447file systems. 448file systems.
448This differs from 449This differs from
449.Nm bootxx_msdos 450.Nm bootxx_msdos
450in that it doesn't require the filesystem to have been initialised with 451in that it doesn't require the filesystem to have been initialised with
451any 452any
452.Ql reserved sectors . 453.Ql reserved sectors .
453It also uses the information in the 454It also uses the information in the
454.Ql Boot Parameter Block 455.Ql Boot Parameter Block
455to get the media and filesytem properties. 456to get the media and filesytem properties.
 457The
 458.Ql hidden sectors
 459field of the BPB must the offset of the partition in the disk.
 460This can be set using the
 461.Fl b Ar s1bno
 462option.
456. 463.
457.It Pa /usr/mdec/bootxx_ffsv1 464.It Pa /usr/mdec/bootxx_ffsv1
458Primary bootstrap for 465Primary bootstrap for
459.Sy FFSv1 466.Sy FFSv1
460file systems 467file systems
461(the 468(the
462.Ql traditional 469.Ql traditional
463file system prior to 470file system prior to
464.Nx 6.0 ) . 471.Nx 6.0 ) .
465Use 472Use
466.Xr dumpfs 8 473.Xr dumpfs 8
467to confirm the file system format is 474to confirm the file system format is
468.Sy FFSv1 . 475.Sy FFSv1 .

cvs diff -r1.37 -r1.38 src/usr.sbin/installboot/arch/i386.c (expand / switch to unified diff)

--- src/usr.sbin/installboot/arch/i386.c 2011/08/14 17:50:17 1.37
+++ src/usr.sbin/installboot/arch/i386.c 2012/03/10 18:42:18 1.38
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: i386.c,v 1.37 2011/08/14 17:50:17 christos Exp $ */ 1/* $NetBSD: i386.c,v 1.38 2012/03/10 18:42:18 dsl Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by David Laight. 8 * by David Laight.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#if HAVE_NBTOOL_CONFIG_H 32#if HAVE_NBTOOL_CONFIG_H
33#include "nbtool_config.h" 33#include "nbtool_config.h"
34#endif 34#endif
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37#if !defined(__lint) 37#if !defined(__lint)
38__RCSID("$NetBSD: i386.c,v 1.37 2011/08/14 17:50:17 christos Exp $"); 38__RCSID("$NetBSD: i386.c,v 1.38 2012/03/10 18:42:18 dsl Exp $");
39#endif /* !__lint */ 39#endif /* !__lint */
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#ifndef HAVE_NBTOOL_CONFIG_H 42#ifndef HAVE_NBTOOL_CONFIG_H
43#include <sys/ioctl.h> 43#include <sys/ioctl.h>
44#include <sys/dkio.h> 44#include <sys/dkio.h>
45#endif 45#endif
46 46
47#include <assert.h> 47#include <assert.h>
48#include <errno.h> 48#include <errno.h>
49#include <err.h> 49#include <err.h>
50#include <md5.h> 50#include <md5.h>
51#include <stddef.h> 51#include <stddef.h>
@@ -69,33 +69,35 @@ static const struct console_name { @@ -69,33 +69,35 @@ static const struct console_name {
69 { "com1kbd", 6 /* CONSDEV_COM1KBD */ }, 69 { "com1kbd", 6 /* CONSDEV_COM1KBD */ },
70 { "com2kbd", 7 /* CONSDEV_COM2KBD */ }, 70 { "com2kbd", 7 /* CONSDEV_COM2KBD */ },
71 { "com3kbd", 8 /* CONSDEV_COM3KBD */ }, 71 { "com3kbd", 8 /* CONSDEV_COM3KBD */ },
72 { "auto", -1 /* CONSDEV_AUTO */ }, 72 { "auto", -1 /* CONSDEV_AUTO */ },
73}; 73};
74 74
75static int i386_setboot(ib_params *); 75static int i386_setboot(ib_params *);
76static int i386_editboot(ib_params *); 76static int i386_editboot(ib_params *);
77 77
78struct ib_mach ib_mach_i386 = 78struct ib_mach ib_mach_i386 =
79 { "i386", i386_setboot, no_clearboot, i386_editboot, 79 { "i386", i386_setboot, no_clearboot, i386_editboot,
80 IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR | 80 IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR |
81 IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT | 81 IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT |
82 IB_MODULES | IB_BOOTCONF }; 82 IB_MODULES | IB_BOOTCONF |
 83 IB_STAGE1START };
83 84
84struct ib_mach ib_mach_amd64 = 85struct ib_mach ib_mach_amd64 =
85 { "amd64", i386_setboot, no_clearboot, i386_editboot, 86 { "amd64", i386_setboot, no_clearboot, i386_editboot,
86 IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR | 87 IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR |
87 IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT | 88 IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT |
88 IB_MODULES | IB_BOOTCONF }; 89 IB_MODULES | IB_BOOTCONF |
 90 IB_STAGE1START };
89 91
90/* 92/*
91 * Attempting to write the 'labelsector' (or a sector near it - within 8k?) 93 * Attempting to write the 'labelsector' (or a sector near it - within 8k?)
92 * using the non-raw disk device fails silently. This can be detected (today) 94 * using the non-raw disk device fails silently. This can be detected (today)
93 * by doing a fsync() and a read back. 95 * by doing a fsync() and a read back.
94 * This is very likely to affect installboot, indeed the code may need to 96 * This is very likely to affect installboot, indeed the code may need to
95 * be written into the 'labelsector' itself - especially on non-512 byte media. 97 * be written into the 'labelsector' itself - especially on non-512 byte media.
96 * We do all writes with a read verify. 98 * We do all writes with a read verify.
97 * If EROFS is returned we also try to enable writes to the label sector. 99 * If EROFS is returned we also try to enable writes to the label sector.
98 * (Maybe these functions should be in the generic part of installboot.) 100 * (Maybe these functions should be in the generic part of installboot.)
99 */ 101 */
100static int 102static int
101pwrite_validate(int fd, const void *buf, size_t n_bytes, off_t offset) 103pwrite_validate(int fd, const void *buf, size_t n_bytes, off_t offset)
@@ -430,26 +432,29 @@ i386_setboot(ib_params *params) @@ -430,26 +432,29 @@ i386_setboot(ib_params *params)
430 /* Check we have enough space for the old bpb */ 432 /* Check we have enough space for the old bpb */
431 if (disk_buf.b[1] > bootstrap.b[1]) { 433 if (disk_buf.b[1] > bootstrap.b[1]) {
432 /* old BPB is larger, allow if extra zeros */ 434 /* old BPB is larger, allow if extra zeros */
433 if (!is_zero(disk_buf.b + 2 + bootstrap.b[1], 435 if (!is_zero(disk_buf.b + 2 + bootstrap.b[1],
434 disk_buf.b[1] - bootstrap.b[1])) { 436 disk_buf.b[1] - bootstrap.b[1])) {
435 warnx("Old BPB too big" USE_F); 437 warnx("Old BPB too big" USE_F);
436 return 0; 438 return 0;
437 } 439 }
438 u = bootstrap.b[1]; 440 u = bootstrap.b[1];
439 } else { 441 } else {
440 /* Old BPB is shorter, leave zero filled */ 442 /* Old BPB is shorter, leave zero filled */
441 u = disk_buf.b[1]; 443 u = disk_buf.b[1];
442 } 444 }
 445 if (params->s1start != 0)
 446 /* Fixup physical offset of filesytem */
 447 bpb->bpbHiddenSecs = htole32(params->s1start);
443 memcpy(bootstrap.b + 2, disk_buf.b + 2, u); 448 memcpy(bootstrap.b + 2, disk_buf.b + 2, u);
444 } 449 }
445 #undef USE_F 450 #undef USE_F
446 } 451 }
447 452
448 /* 453 /*
449 * Fill in any user-specified options into the 454 * Fill in any user-specified options into the
450 * struct x86_boot_params 455 * struct x86_boot_params
451 * that follows the magic number. 456 * that follows the magic number.
452 * See sys/arch/i386/stand/bootxx/bootxx.S for more information. 457 * See sys/arch/i386/stand/bootxx/bootxx.S for more information.
453 */ 458 */
454 if (update_i386_boot_params(params, (void *)(magic + 1))) 459 if (update_i386_boot_params(params, (void *)(magic + 1)))
455 return 0; 460 return 0;