diff --git a/sbin/gpt/biosboot.c b/sbin/gpt/biosboot.c index cab9d1f80c73..12d96bc33368 100644 --- a/sbin/gpt/biosboot.c +++ b/sbin/gpt/biosboot.c @@ -1,4 +1,4 @@ -/* $NetBSD: biosboot.c,v 1.24 2015/12/29 16:45:04 christos Exp $ */ +/* $NetBSD: biosboot.c,v 1.25 2016/06/09 15:12:54 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include #ifdef __RCSID -__RCSID("$NetBSD: biosboot.c,v 1.24 2015/12/29 16:45:04 christos Exp $"); +__RCSID("$NetBSD: biosboot.c,v 1.25 2016/06/09 15:12:54 christos Exp $"); #endif #include @@ -68,7 +68,7 @@ __RCSID("$NetBSD: biosboot.c,v 1.24 2015/12/29 16:45:04 christos Exp $"); static int cmd_biosboot(gpt_t, int, char *[]); static const char *biosboothelp[] = { - "[-c bootcode] [-i index] [-L label]", + "[-a] [-c bootcode] [-i index] [-L label]", #if notyet "[-a alignment] [-b blocknr] [-i index] [-l label]", "[-s size] [-t type]", @@ -164,7 +164,7 @@ set_bootable(gpt_t gpt, map_t map, map_t tbl, unsigned int i) static int biosboot(gpt_t gpt, daddr_t start, uint64_t size, u_int entry, uint8_t *label, - const char *bootpath) + const char *bootpath, int active) { map_t mbrmap, m; struct mbr *mbr, *bootcode; @@ -197,6 +197,10 @@ biosboot(gpt_t gpt, daddr_t start, uint64_t size, u_int entry, uint8_t *label, sizeof(mbr->mbr_code)); free(bootcode); + for (i = 0; i < __arraycount(mbr->mbr_part); i++) + if (mbr->mbr_part[i].part_typ == MBR_PTYPE_PMBR) + mbr->mbr_part[i].part_flag = active ? 0x80 : 0; + /* * Walk through the GPT and see where we can boot from */ @@ -255,12 +259,16 @@ cmd_biosboot(gpt_t gpt, int argc, char *argv[]) gpt_t ngpt = gpt; daddr_t start = 0; uint64_t size = 0; + int active = 0; unsigned int entry = 0; uint8_t *label = NULL; char *bootpath = NULL; - while ((ch = getopt(argc, argv, "c:i:L:")) != -1) { + while ((ch = getopt(argc, argv, "ac:i:L:")) != -1) { switch(ch) { + case 'a': + active = 1; + break; case 'c': if (gpt_name_get(gpt, &bootpath) == -1) goto usage; @@ -295,7 +303,7 @@ cmd_biosboot(gpt_t gpt, int argc, char *argv[]) goto cleanup; } #endif - if (biosboot(ngpt, start, size, entry, label, bootpath) == -1) + if (biosboot(ngpt, start, size, entry, label, bootpath, active) == -1) goto cleanup; if (ngpt != gpt) gpt_close(ngpt); diff --git a/sbin/gpt/create.c b/sbin/gpt/create.c index df28db6d1275..15308d12658a 100644 --- a/sbin/gpt/create.c +++ b/sbin/gpt/create.c @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: create.c,v 1.20 2015/12/29 16:45:04 christos Exp $"); +__RCSID("$NetBSD: create.c,v 1.21 2016/06/09 15:12:54 christos Exp $"); #endif #include @@ -55,7 +55,7 @@ __RCSID("$NetBSD: create.c,v 1.20 2015/12/29 16:45:04 christos Exp $"); static int cmd_create(gpt_t, int, char *[]); static const char *createhelp[] = { - "[-fP] [-p partitions]", + "[-afP] [-p partitions]", }; struct gpt_cmd c_create = { @@ -69,7 +69,7 @@ struct gpt_cmd c_create = { static int -create(gpt_t gpt, u_int parts, int force, int primary_only) +create(gpt_t gpt, u_int parts, int force, int primary_only, int active) { off_t last = gpt_last(gpt); map_t map; @@ -100,7 +100,7 @@ create(gpt_t gpt, u_int parts, int force, int primary_only) } memset(mbr, 0, sizeof(*mbr)); mbr->mbr_sig = htole16(MBR_SIG); - gpt_create_pmbr_part(mbr->mbr_part, last); + gpt_create_pmbr_part(mbr->mbr_part, last, active); map = map_add(gpt, 0LL, 1LL, MAP_TYPE_PMBR, mbr, 1); if (gpt_write(gpt, map) == -1) { @@ -125,12 +125,16 @@ static int cmd_create(gpt_t gpt, int argc, char *argv[]) { int ch; + int active = 0; int force = 0; int primary_only = 0; u_int parts = 128; - while ((ch = getopt(argc, argv, "fPp:")) != -1) { + while ((ch = getopt(argc, argv, "afPp:")) != -1) { switch(ch) { + case 'a': + active = 1; + break; case 'f': force = 1; break; @@ -149,5 +153,5 @@ cmd_create(gpt_t gpt, int argc, char *argv[]) if (argc != optind) return usage(); - return create(gpt, parts, force, primary_only); + return create(gpt, parts, force, primary_only, active); } diff --git a/sbin/gpt/gpt.8 b/sbin/gpt/gpt.8 index 26c1b9e745ab..ee8d8dfcf7f3 100644 --- a/sbin/gpt/gpt.8 +++ b/sbin/gpt/gpt.8 @@ -1,4 +1,4 @@ -.\" $NetBSD: gpt.8,v 1.45 2015/12/25 12:16:03 wiz Exp $ +.\" $NetBSD: gpt.8,v 1.46 2016/06/09 15:12:54 christos Exp $ .\" .\" Copyright (c) 2002 Marcel Moolenaar .\" All rights reserved. @@ -26,7 +26,7 @@ .\" .\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $ .\" -.Dd December 25, 2015 +.Dd June 9, 2016 .Dt GPT 8 .Os .Sh NAME @@ -211,7 +211,7 @@ command. The format is a plist. It should not be modified. .\" ==== biosboot ==== -.It Nm Ic biosboot Oo Fl c Ar bootcode Oc Oo Fl i Ar index Oc \ +.It Nm Ic biosboot Oo Fl ac Ar bootcode Oc Oo Fl i Ar index Oc \ Oo Fl L Ar label Oc The .Ic biosboot @@ -220,6 +220,10 @@ primary bootstrap program, used during .Xr boot 8 . .Pp The +.Fl a +options sets the PMBR partition active. +.Pp +The .Fl c option allows the user to specify the filename that .Nm @@ -238,7 +242,7 @@ option selects the partition by label. If there are multiple partitions with the same label, it will use the first one found. .\" ==== create ==== -.It Nm Ic create Oo Fl fP Oc Oo Fl p Ar partitions Oc +.It Nm Ic create Oo Fl afP Oc Oo Fl p Ar partitions Oc The .Ic create command allows the user to create a new (empty) GPT. @@ -252,6 +256,10 @@ option is specified, an existing MBR is destroyed and any partitions described by the MBR are lost. .Pp The +.Fl a +options sets the PMBR partition active. +.Pp +The .Fl P option tells .Nm @@ -343,7 +351,7 @@ The option is used to specify the label in the command line. The label is assumed to be encoded in UTF-8. .\" ==== migrate ==== -.It Nm Ic migrate Oo Fl fs Oc Oo Fl p Ar partitions Oc +.It Nm Ic migrate Oo Fl afs Oc Oo Fl p Ar partitions Oc The .Ic migrate command allows the user to migrate an MBR-based disk partitioning into a @@ -359,6 +367,10 @@ option will cause unknown partitions to be ignored and any data in it to be lost. .Pp The +.Fl a +options sets the PMBR partition active. +.Pp +The .Fl s option prevents migrating .Bx diff --git a/sbin/gpt/gpt.c b/sbin/gpt/gpt.c index 2ac5be04c36b..15205f388380 100644 --- a/sbin/gpt/gpt.c +++ b/sbin/gpt/gpt.c @@ -35,7 +35,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: gpt.c,v 1.67 2016/01/08 18:59:01 joerg Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.68 2016/06/09 15:12:54 christos Exp $"); #endif #include @@ -336,7 +336,8 @@ gpt_mbr(gpt_t gpt, off_t lba) /* start is relative to the offset of the MBR itself. */ start += lba; if (gpt->verbose > 2) - gpt_msg(gpt, "MBR part: type=%d, start=%ju, size=%ju", + gpt_msg(gpt, "MBR part: flag=%#x type=%d, start=%ju, " + "size=%ju", mbr->mbr_part[i].part_flag, mbr->mbr_part[i].part_typ, (uintmax_t)start, (uintmax_t)size); if (mbr->mbr_part[i].part_typ != MBR_PTYPE_EXT_LBA) { @@ -705,8 +706,9 @@ gpt_write_backup(gpt_t gpt) } void -gpt_create_pmbr_part(struct mbr_part *part, off_t last) +gpt_create_pmbr_part(struct mbr_part *part, off_t last, int active) { + part->part_flag = active ? 0x80 : 0; part->part_shd = 0x00; part->part_ssect = 0x02; part->part_scyl = 0x00; diff --git a/sbin/gpt/gpt.h b/sbin/gpt/gpt.h index c5abc07d1485..df7d5747cf9f 100644 --- a/sbin/gpt/gpt.h +++ b/sbin/gpt/gpt.h @@ -92,7 +92,7 @@ struct gpt_hdr *gpt_hdr(gpt_t); void gpt_msg(gpt_t, const char *, ...) __printflike(2, 3); void gpt_warn(gpt_t, const char *, ...) __printflike(2, 3); void gpt_warnx(gpt_t, const char *, ...) __printflike(2, 3); -void gpt_create_pmbr_part(struct mbr_part *, off_t); +void gpt_create_pmbr_part(struct mbr_part *, off_t, int); struct gpt_ent *gpt_ent(map_t, map_t, unsigned int); struct gpt_ent *gpt_ent_primary(gpt_t, unsigned int); struct gpt_ent *gpt_ent_backup(gpt_t, unsigned int); diff --git a/sbin/gpt/migrate.c b/sbin/gpt/migrate.c index 9434e4aaf5ea..f5125e5f1048 100644 --- a/sbin/gpt/migrate.c +++ b/sbin/gpt/migrate.c @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/migrate.c,v 1.16 2005/09/01 02:42:52 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: migrate.c,v 1.30 2015/12/29 16:45:04 christos Exp $"); +__RCSID("$NetBSD: migrate.c,v 1.31 2016/06/09 15:12:54 christos Exp $"); #endif #include @@ -81,7 +81,7 @@ __RCSID("$NetBSD: migrate.c,v 1.30 2015/12/29 16:45:04 christos Exp $"); static int cmd_migrate(gpt_t, int, char *[]); static const char *migratehelp[] = { - "[-fs] [-p partitions]", + "[-afs] [-p partitions]", }; struct gpt_cmd c_migrate = { @@ -233,7 +233,7 @@ migrate_disklabel(gpt_t gpt, off_t start, struct gpt_ent *ent, } static int -migrate(gpt_t gpt, u_int parts, int force, int slice) +migrate(gpt_t gpt, u_int parts, int force, int slice, int active) { off_t last = gpt_last(gpt); map_t map; @@ -314,7 +314,7 @@ migrate(gpt_t gpt, u_int parts, int force, int slice) * Turn the MBR into a Protective MBR. */ memset(mbr->mbr_part, 0, sizeof(mbr->mbr_part)); - gpt_create_pmbr_part(mbr->mbr_part, last); + gpt_create_pmbr_part(mbr->mbr_part, last, active); if (gpt_write(gpt, map) == -1) { gpt_warn(gpt, "Cant write PMBR"); return -1; @@ -328,11 +328,15 @@ cmd_migrate(gpt_t gpt, int argc, char *argv[]) int ch; int force = 0; int slice = 0; + int active = 0; u_int parts = 128; /* Get the migrate options */ - while ((ch = getopt(argc, argv, "fp:s")) != -1) { + while ((ch = getopt(argc, argv, "afp:s")) != -1) { switch(ch) { + case 'a': + active = 1; + break; case 'f': force = 1; break; @@ -351,5 +355,5 @@ cmd_migrate(gpt_t gpt, int argc, char *argv[]) if (argc != optind) return usage(); - return migrate(gpt, parts, force, slice); + return migrate(gpt, parts, force, slice, active); } diff --git a/sbin/gpt/show.c b/sbin/gpt/show.c index 7d0014294447..10be1c47158b 100644 --- a/sbin/gpt/show.c +++ b/sbin/gpt/show.c @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.36 2016/05/31 02:29:54 dholland Exp $"); +__RCSID("$NetBSD: show.c,v 1.37 2016/06/09 15:12:54 christos Exp $"); #endif #include @@ -118,7 +118,9 @@ print_part_type(int map_type, int flags, void *map_data, off_t map_start) /* wasn't there */ printf("[partition not found?]"); } else { - printf("%d", mbr->mbr_part[i].part_typ); + printf("%d%s", mbr->mbr_part[i].part_typ, + mbr->mbr_part[i].part_flag == 0x80 ? + " (active)" : ""); } break; case MAP_TYPE_GPT_PART: