Add a new flag to mkimg (-a num) to specify the active partition for

those partitioning schemes that have this concept. Implement it as an
override for mbr's setting 0x80 in the flags for the first partition
when we have boot code.

Differential Revision: https://reviews.freebsd.org/D4403
This commit is contained in:
Warner Losh 2016-10-18 05:43:12 +00:00
parent f007d6f6f0
commit c30dcf40ba
4 changed files with 37 additions and 3 deletions

View File

@ -92,7 +92,12 @@ mbr_write(lba_t imgsz __unused, void *bootcode)
TAILQ_FOREACH(part, &partlist, link) {
size = round_track(part->size);
dp = dpbase + part->index;
dp->dp_flag = (part->index == 0 && bootcode != NULL) ? 0x80 : 0;
if (active_partition != 0)
dp->dp_flag =
(part->index + 1 == active_partition) ? 0x80 : 0;
else
dp->dp_flag =
(part->index == 0 && bootcode != NULL) ? 0x80 : 0;
mbr_chs(&dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect,
part->block);
dp->dp_typ = ALIAS_TYPE2INT(part->type);

View File

@ -40,6 +40,7 @@
.Op Fl c Ar capacity
.Op Fl f Ar format
.Op Fl o Ar outfile
.Op Fl a Ar active
.Op Fl v
.Op Fl y
.Op Fl s Ar scheme Op Fl p Ar partition ...
@ -119,7 +120,7 @@ An empty partition table can be written to the disk when specifying a
partitioning scheme with the
.Fl s
option, but without specifying any partitions.
When the size required to for all the partitions is larger than the
When the size required for all the partitions is larger than the
given capacity, then the disk image will be larger than the capacity
given.
.Pp
@ -139,6 +140,26 @@ utility will generate predictable values for Universally Unique Identifiers
.Nm
utility will create images that are identical.
.Pp
The
.Ar active
option marks a partition as active, if the partitioning
scheme supports it.
Currently, only the
.Ar mbr
scheme supports this concept.
By default,
.Nm
will only mark the first partition as active when boot code is
specified.
Use the
.Ar active
option to override the active partition.
The number specified corresponds to the number after the 's' in the
partition's
.Xr geom 8
name.
No partitions are marked active when the value is 0.
.Pp
A set of long options exist to query about the
.Nm
utility itself.

View File

@ -70,6 +70,7 @@ u_int nheads = 1;
u_int nsecs = 1;
u_int secsz = 512;
u_int blksz = 0;
uint32_t active_partition = 0;
static void
print_formats(int usage)
@ -145,6 +146,7 @@ usage(const char *why)
fprintf(stderr, "\t--schemes\t- list partition schemes\n");
fprintf(stderr, "\t--version\t- show version information\n");
fputc('\n', stderr);
fprintf(stderr, "\t-a <num>\t- mark num'th partion as active\n");
fprintf(stderr, "\t-b <file>\t- file containing boot code\n");
fprintf(stderr, "\t-c <num>\t- capacity (in bytes) of the disk\n");
fprintf(stderr, "\t-f <format>\n");
@ -468,9 +470,14 @@ main(int argc, char *argv[])
bcfd = -1;
outfd = 1; /* Write to stdout by default */
while ((c = getopt_long(argc, argv, "b:c:f:o:p:s:vyH:P:S:T:",
while ((c = getopt_long(argc, argv, "a:b:c:f:o:p:s:vyH:P:S:T:",
longopts, NULL)) != -1) {
switch (c) {
case 'a': /* ACTIVE PARTITION, if supported */
error = parse_uint32(&active_partition, 1, 100, optarg);
if (error)
errc(EX_DATAERR, error, "Partition ordinal");
break;
case 'b': /* BOOT CODE */
if (bcfd != -1)
usage("multiple bootcode given");

View File

@ -59,6 +59,7 @@ extern u_int nheads;
extern u_int nsecs;
extern u_int secsz; /* Logical block size. */
extern u_int blksz; /* Physical block size. */
extern uint32_t active_partition;
static inline lba_t
round_block(lba_t n)