-.\" $OpenBSD: fdisk.8,v 1.76 2014/03/06 17:39:23 jmc Exp $
+.\" $OpenBSD: fdisk.8,v 1.77 2015/01/03 15:50:50 jsing Exp $
.\"
.\" Copyright (c) 1997 Tobias Weingartner
.\" All rights reserved.
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: March 6 2014 $
+.Dd $Mdocdate: January 3 2015 $
.Dt FDISK 8
.Os
.Sh NAME
.Nd MBR partition maintenance program
.Sh SYNOPSIS
.Nm fdisk
-.Op Fl eiuy
+.Op Fl egiuy
.Oo
.Fl c Ar cylinders
.Fl h Ar heads
Specifies an alternate MBR template file.
The default file is
.Pa /usr/mdec/mbr .
+.It Fl g
+A protective MBR for GPT will be written to disk, instead of an MBR with an
+.Ox
+MBR partition.
+Only valid with
+.Fl i .
.It Fl i
Requests that the MBR partition data be re-initialized.
In this mode,
MBR partition spanning the entire disk, except for a zone left at the start
for booting.
This mode is designed to initialize the MBR the very first time.
+If the
+.Fl g
+flag is also specified, a protective MBR for GPT will be created.
.It Fl l Ar blocks
Specify the number of blocks in the disk, and force the MBR to be in LBA
mode only.
-/* $OpenBSD: fdisk.c,v 1.63 2014/03/20 13:18:21 krw Exp $ */
+/* $OpenBSD: fdisk.c,v 1.64 2015/01/03 15:50:50 jsing Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
#include "mbrcode.h"
};
+int g_flag;
int y_flag;
static void
extern char * __progname;
fprintf(stderr, "usage: %s "
- "[-eiuy] [-c cylinders -h heads -s sectors] [-f mbrfile] [-l blocks] disk\n"
+ "[-egiuy] [-c cylinders -h heads -s sectors] [-f mbrfile] "
+ "[-l blocks] disk\n"
"\t-i: initialize disk with virgin MBR\n"
"\t-u: update MBR code, preserve partition table\n"
"\t-e: edit MBRs on disk interactively\n"
"\t-chs: specify disk geometry\n"
"\t-l: specify LBA block count\n"
"\t-y: do not ask questions\n"
+ "\t-g: initialize disk with EFI/GPT partition, requires -i\n"
"`disk' may be of the forms: sd0 or /dev/rsd0c.\n",
__progname);
exit(1);
struct mbr mbr;
struct dos_mbr dos_mbr;
- while ((ch = getopt(argc, argv, "ieuf:c:h:s:l:y")) != -1) {
+ while ((ch = getopt(argc, argv, "ieguf:c:h:s:l:y")) != -1) {
const char *errstr;
switch(ch) {
if (errstr)
errx(1, "Sector argument %s [1..63].", errstr);
break;
+ case 'g':
+ g_flag = 1;
+ break;
case 'l':
l_arg = strtonum(optarg, 64, UINT32_MAX, &errstr);
if (errstr)
else
disk.name = argv[0];
+ if (g_flag != 0 && i_flag == 0) {
+ warnx("-g specified without -i");
+ usage();
+ }
+
/* Start with the disklabel geometry and get the sector size. */
DISK_getlabelgeometry(&disk);
-/* $OpenBSD: mbr.c,v 1.40 2014/05/21 15:55:19 krw Exp $ */
+/* $OpenBSD: mbr.c,v 1.41 2015/01/03 15:50:50 jsing Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
#include "misc.h"
#include "mbr.h"
+void
+MBR_init_GPT(struct disk *disk, struct mbr *mbr)
+{
+ /* Initialize a protective MBR for GPT. */
+ bzero(&mbr->part, sizeof(mbr->part));
+
+ /* Use whole disk, starting after MBR. */
+ mbr->part[0].id = DOSPTYP_EFI;
+ mbr->part[0].bs = 1;
+ mbr->part[0].ns = disk->size - 1;
+
+ /* Fix up start/length fields. */
+ PRT_fix_CHS(disk, &mbr->part[0]);
+}
+
void
MBR_init(struct disk *disk, struct mbr *mbr)
{
- daddr_t i;
+ extern int g_flag;
u_int64_t adj;
+ daddr_t i;
+
+ if (g_flag) {
+ MBR_init_GPT(disk, mbr);
+ return;
+ }
/* Fix up given mbr for this disk */
mbr->part[0].flag = 0;