From 1bb42b113809b6e1d328cfcd6c4630db571e5d1f Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Wed, 27 Jun 2018 09:47:49 +0200
Subject: [PATCH 4/5] quick mkimg port

---
 sys/sys/disk/apm.h                            |  69 ++
 sys/sys/disk/bsd.h                            | 191 +++++
 sys/sys/disk/gpt.h                            | 239 ++++++
 sys/sys/disk/mbr.h                            |  85 ++
 sys/sys/disk/vtoc.h                           | 108 +++
 sys/sys/queue.h                               |   5 +
 usr.bin/Makefile                              |   1 +
 usr.bin/mkimg/Makefile                        |  38 +
 usr.bin/mkimg/apm.c                           | 117 +++
 usr.bin/mkimg/bsd.c                           | 136 ++++
 usr.bin/mkimg/ebr.c                           | 131 +++
 usr.bin/mkimg/endian.h                        | 106 +++
 usr.bin/mkimg/format.c                        | 100 +++
 usr.bin/mkimg/format.h                        |  52 ++
 usr.bin/mkimg/gpt.c                           | 289 +++++++
 usr.bin/mkimg/image.c                         | 755 ++++++++++++++++++
 usr.bin/mkimg/image.h                         |  45 ++
 usr.bin/mkimg/mbr.c                           | 125 +++
 usr.bin/mkimg/mkimg.1                         | 366 +++++++++
 usr.bin/mkimg/mkimg.c                         | 734 +++++++++++++++++
 usr.bin/mkimg/mkimg.h                         | 113 +++
 usr.bin/mkimg/qcow.c                          | 369 +++++++++
 usr.bin/mkimg/raw.c                           |  61 ++
 usr.bin/mkimg/scheme.c                        | 202 +++++
 usr.bin/mkimg/scheme.h                        |  96 +++
 usr.bin/mkimg/tests/Makefile                  |  23 +
 usr.bin/mkimg/tests/Makefile.depend           |  11 +
 .../mkimg/tests/img-1x1-4096-apm.qcow.gz.uu   | 127 +++
 .../mkimg/tests/img-1x1-4096-apm.qcow2.gz.uu  |  22 +
 .../mkimg/tests/img-1x1-4096-apm.raw.gz.uu    |  12 +
 .../mkimg/tests/img-1x1-4096-apm.vhd.gz.uu    |  19 +
 .../mkimg/tests/img-1x1-4096-apm.vhdf.gz.uu   |  15 +
 .../mkimg/tests/img-1x1-4096-apm.vmdk.gz.uu   |  82 ++
 .../mkimg/tests/img-1x1-4096-bsd.qcow.gz.uu   | 125 +++
 .../mkimg/tests/img-1x1-4096-bsd.qcow2.gz.uu  |  21 +
 .../mkimg/tests/img-1x1-4096-bsd.raw.gz.uu    |  10 +
 .../mkimg/tests/img-1x1-4096-bsd.vhd.gz.uu    |  17 +
 .../mkimg/tests/img-1x1-4096-bsd.vhdf.gz.uu   |  13 +
 .../mkimg/tests/img-1x1-4096-bsd.vmdk.gz.uu   |  81 ++
 .../mkimg/tests/img-1x1-4096-ebr.qcow.gz.uu   | 127 +++
 .../mkimg/tests/img-1x1-4096-ebr.qcow2.gz.uu  |  22 +
 .../mkimg/tests/img-1x1-4096-ebr.raw.gz.uu    |  11 +
 .../mkimg/tests/img-1x1-4096-ebr.vhd.gz.uu    |  18 +
 .../mkimg/tests/img-1x1-4096-ebr.vhdf.gz.uu   |  14 +
 .../mkimg/tests/img-1x1-4096-ebr.vmdk.gz.uu   |  82 ++
 .../mkimg/tests/img-1x1-4096-gpt.qcow.gz.uu   | 132 +++
 .../mkimg/tests/img-1x1-4096-gpt.qcow2.gz.uu  |  26 +
 .../mkimg/tests/img-1x1-4096-gpt.raw.gz.uu    |  15 +
 .../mkimg/tests/img-1x1-4096-gpt.vhd.gz.uu    |  22 +
 .../mkimg/tests/img-1x1-4096-gpt.vhdf.gz.uu   |  19 +
 .../mkimg/tests/img-1x1-4096-gpt.vmdk.gz.uu   |  87 ++
 .../mkimg/tests/img-1x1-4096-mbr.qcow.gz.uu   | 127 +++
 .../mkimg/tests/img-1x1-4096-mbr.qcow2.gz.uu  |  22 +
 .../mkimg/tests/img-1x1-4096-mbr.raw.gz.uu    |  11 +
 .../mkimg/tests/img-1x1-4096-mbr.vhd.gz.uu    |  18 +
 .../mkimg/tests/img-1x1-4096-mbr.vhdf.gz.uu   |  15 +
 .../mkimg/tests/img-1x1-4096-mbr.vmdk.gz.uu   |  82 ++
 .../mkimg/tests/img-1x1-4096-vtoc8.qcow.gz.uu | 125 +++
 .../tests/img-1x1-4096-vtoc8.qcow2.gz.uu      |  21 +
 .../mkimg/tests/img-1x1-4096-vtoc8.raw.gz.uu  |  10 +
 .../mkimg/tests/img-1x1-4096-vtoc8.vhd.gz.uu  |  17 +
 .../mkimg/tests/img-1x1-4096-vtoc8.vhdf.gz.uu |  14 +
 .../mkimg/tests/img-1x1-4096-vtoc8.vmdk.gz.uu |  81 ++
 .../mkimg/tests/img-1x1-512-apm.qcow.gz.uu    | 127 +++
 .../mkimg/tests/img-1x1-512-apm.qcow2.gz.uu   |  22 +
 usr.bin/mkimg/tests/img-1x1-512-apm.raw.gz.uu |  12 +
 usr.bin/mkimg/tests/img-1x1-512-apm.vhd.gz.uu |  19 +
 .../mkimg/tests/img-1x1-512-apm.vhdf.gz.uu    |  15 +
 .../mkimg/tests/img-1x1-512-apm.vmdk.gz.uu    |  82 ++
 .../mkimg/tests/img-1x1-512-bsd.qcow.gz.uu    | 125 +++
 .../mkimg/tests/img-1x1-512-bsd.qcow2.gz.uu   |  21 +
 usr.bin/mkimg/tests/img-1x1-512-bsd.raw.gz.uu |  10 +
 usr.bin/mkimg/tests/img-1x1-512-bsd.vhd.gz.uu |  17 +
 .../mkimg/tests/img-1x1-512-bsd.vhdf.gz.uu    |  13 +
 .../mkimg/tests/img-1x1-512-bsd.vmdk.gz.uu    |  81 ++
 .../mkimg/tests/img-1x1-512-ebr.qcow.gz.uu    | 127 +++
 .../mkimg/tests/img-1x1-512-ebr.qcow2.gz.uu   |  22 +
 usr.bin/mkimg/tests/img-1x1-512-ebr.raw.gz.uu |  11 +
 usr.bin/mkimg/tests/img-1x1-512-ebr.vhd.gz.uu |  18 +
 .../mkimg/tests/img-1x1-512-ebr.vhdf.gz.uu    |  14 +
 .../mkimg/tests/img-1x1-512-ebr.vmdk.gz.uu    |  82 ++
 .../mkimg/tests/img-1x1-512-gpt.qcow.gz.uu    | 132 +++
 .../mkimg/tests/img-1x1-512-gpt.qcow2.gz.uu   |  26 +
 usr.bin/mkimg/tests/img-1x1-512-gpt.raw.gz.uu |  15 +
 usr.bin/mkimg/tests/img-1x1-512-gpt.vhd.gz.uu |  22 +
 .../mkimg/tests/img-1x1-512-gpt.vhdf.gz.uu    |  19 +
 .../mkimg/tests/img-1x1-512-gpt.vmdk.gz.uu    |  87 ++
 .../mkimg/tests/img-1x1-512-mbr.qcow.gz.uu    | 127 +++
 .../mkimg/tests/img-1x1-512-mbr.qcow2.gz.uu   |  22 +
 usr.bin/mkimg/tests/img-1x1-512-mbr.raw.gz.uu |  11 +
 usr.bin/mkimg/tests/img-1x1-512-mbr.vhd.gz.uu |  18 +
 .../mkimg/tests/img-1x1-512-mbr.vhdf.gz.uu    |  15 +
 .../mkimg/tests/img-1x1-512-mbr.vmdk.gz.uu    |  82 ++
 .../mkimg/tests/img-1x1-512-vtoc8.qcow.gz.uu  | 125 +++
 .../mkimg/tests/img-1x1-512-vtoc8.qcow2.gz.uu |  21 +
 .../mkimg/tests/img-1x1-512-vtoc8.raw.gz.uu   |  10 +
 .../mkimg/tests/img-1x1-512-vtoc8.vhd.gz.uu   |  17 +
 .../mkimg/tests/img-1x1-512-vtoc8.vhdf.gz.uu  |  14 +
 .../mkimg/tests/img-1x1-512-vtoc8.vmdk.gz.uu  |  81 ++
 .../tests/img-63x255-4096-apm.qcow.gz.uu      | 127 +++
 .../tests/img-63x255-4096-apm.qcow2.gz.uu     |  22 +
 .../mkimg/tests/img-63x255-4096-apm.raw.gz.uu |  12 +
 .../mkimg/tests/img-63x255-4096-apm.vhd.gz.uu |  18 +
 .../tests/img-63x255-4096-apm.vhdf.gz.uu      |  15 +
 .../tests/img-63x255-4096-apm.vmdk.gz.uu      |  83 ++
 .../tests/img-63x255-4096-bsd.qcow.gz.uu      | 126 +++
 .../tests/img-63x255-4096-bsd.qcow2.gz.uu     |  21 +
 .../mkimg/tests/img-63x255-4096-bsd.raw.gz.uu |  11 +
 .../mkimg/tests/img-63x255-4096-bsd.vhd.gz.uu |  17 +
 .../tests/img-63x255-4096-bsd.vhdf.gz.uu      |  14 +
 .../tests/img-63x255-4096-bsd.vmdk.gz.uu      |  81 ++
 .../tests/img-63x255-4096-ebr.qcow.gz.uu      | 128 +++
 .../tests/img-63x255-4096-ebr.qcow2.gz.uu     |  22 +
 .../mkimg/tests/img-63x255-4096-ebr.raw.gz.uu |  12 +
 .../mkimg/tests/img-63x255-4096-ebr.vhd.gz.uu |  18 +
 .../tests/img-63x255-4096-ebr.vhdf.gz.uu      |  15 +
 .../tests/img-63x255-4096-ebr.vmdk.gz.uu      |  84 ++
 .../tests/img-63x255-4096-gpt.qcow.gz.uu      | 132 +++
 .../tests/img-63x255-4096-gpt.qcow2.gz.uu     |  26 +
 .../mkimg/tests/img-63x255-4096-gpt.raw.gz.uu |  15 +
 .../mkimg/tests/img-63x255-4096-gpt.vhd.gz.uu |  22 +
 .../tests/img-63x255-4096-gpt.vhdf.gz.uu      |  19 +
 .../tests/img-63x255-4096-gpt.vmdk.gz.uu      |  88 ++
 .../tests/img-63x255-4096-mbr.qcow.gz.uu      | 128 +++
 .../tests/img-63x255-4096-mbr.qcow2.gz.uu     |  22 +
 .../mkimg/tests/img-63x255-4096-mbr.raw.gz.uu |  12 +
 .../mkimg/tests/img-63x255-4096-mbr.vhd.gz.uu |  19 +
 .../tests/img-63x255-4096-mbr.vhdf.gz.uu      |  15 +
 .../tests/img-63x255-4096-mbr.vmdk.gz.uu      |  84 ++
 .../tests/img-63x255-4096-vtoc8.qcow.gz.uu    | 127 +++
 .../tests/img-63x255-4096-vtoc8.qcow2.gz.uu   |  21 +
 .../tests/img-63x255-4096-vtoc8.raw.gz.uu     |  11 +
 .../tests/img-63x255-4096-vtoc8.vhd.gz.uu     |  18 +
 .../tests/img-63x255-4096-vtoc8.vhdf.gz.uu    |  14 +
 .../tests/img-63x255-4096-vtoc8.vmdk.gz.uu    |  83 ++
 .../mkimg/tests/img-63x255-512-apm.qcow.gz.uu | 127 +++
 .../tests/img-63x255-512-apm.qcow2.gz.uu      |  22 +
 .../mkimg/tests/img-63x255-512-apm.raw.gz.uu  |  12 +
 .../mkimg/tests/img-63x255-512-apm.vhd.gz.uu  |  18 +
 .../mkimg/tests/img-63x255-512-apm.vhdf.gz.uu |  15 +
 .../mkimg/tests/img-63x255-512-apm.vmdk.gz.uu |  83 ++
 .../mkimg/tests/img-63x255-512-bsd.qcow.gz.uu | 126 +++
 .../tests/img-63x255-512-bsd.qcow2.gz.uu      |  21 +
 .../mkimg/tests/img-63x255-512-bsd.raw.gz.uu  |  11 +
 .../mkimg/tests/img-63x255-512-bsd.vhd.gz.uu  |  17 +
 .../mkimg/tests/img-63x255-512-bsd.vhdf.gz.uu |  14 +
 .../mkimg/tests/img-63x255-512-bsd.vmdk.gz.uu |  81 ++
 .../mkimg/tests/img-63x255-512-ebr.qcow.gz.uu | 128 +++
 .../tests/img-63x255-512-ebr.qcow2.gz.uu      |  22 +
 .../mkimg/tests/img-63x255-512-ebr.raw.gz.uu  |  12 +
 .../mkimg/tests/img-63x255-512-ebr.vhd.gz.uu  |  18 +
 .../mkimg/tests/img-63x255-512-ebr.vhdf.gz.uu |  15 +
 .../mkimg/tests/img-63x255-512-ebr.vmdk.gz.uu |  84 ++
 .../mkimg/tests/img-63x255-512-gpt.qcow.gz.uu | 132 +++
 .../tests/img-63x255-512-gpt.qcow2.gz.uu      |  26 +
 .../mkimg/tests/img-63x255-512-gpt.raw.gz.uu  |  15 +
 .../mkimg/tests/img-63x255-512-gpt.vhd.gz.uu  |  23 +
 .../mkimg/tests/img-63x255-512-gpt.vhdf.gz.uu |  19 +
 .../mkimg/tests/img-63x255-512-gpt.vmdk.gz.uu |  88 ++
 .../mkimg/tests/img-63x255-512-mbr.qcow.gz.uu | 128 +++
 .../tests/img-63x255-512-mbr.qcow2.gz.uu      |  22 +
 .../mkimg/tests/img-63x255-512-mbr.raw.gz.uu  |  12 +
 .../mkimg/tests/img-63x255-512-mbr.vhd.gz.uu  |  19 +
 .../mkimg/tests/img-63x255-512-mbr.vhdf.gz.uu |  15 +
 .../mkimg/tests/img-63x255-512-mbr.vmdk.gz.uu |  84 ++
 .../tests/img-63x255-512-vtoc8.qcow.gz.uu     | 127 +++
 .../tests/img-63x255-512-vtoc8.qcow2.gz.uu    |  21 +
 .../tests/img-63x255-512-vtoc8.raw.gz.uu      |  11 +
 .../tests/img-63x255-512-vtoc8.vhd.gz.uu      |  18 +
 .../tests/img-63x255-512-vtoc8.vhdf.gz.uu     |  14 +
 .../tests/img-63x255-512-vtoc8.vmdk.gz.uu     |  83 ++
 usr.bin/mkimg/tests/mkimg_test.sh             | 164 ++++
 usr.bin/mkimg/uuid.c                          | 125 +++
 usr.bin/mkimg/vhd.c                           | 416 ++++++++++
 usr.bin/mkimg/vmdk.c                          | 260 ++++++
 usr.bin/mkimg/vtoc8.c                         | 115 +++
 176 files changed, 12336 insertions(+)
 create mode 100644 sys/sys/disk/apm.h
 create mode 100644 sys/sys/disk/bsd.h
 create mode 100644 sys/sys/disk/gpt.h
 create mode 100644 sys/sys/disk/mbr.h
 create mode 100644 sys/sys/disk/vtoc.h
 create mode 100644 usr.bin/mkimg/Makefile
 create mode 100644 usr.bin/mkimg/apm.c
 create mode 100644 usr.bin/mkimg/bsd.c
 create mode 100644 usr.bin/mkimg/ebr.c
 create mode 100644 usr.bin/mkimg/endian.h
 create mode 100644 usr.bin/mkimg/format.c
 create mode 100644 usr.bin/mkimg/format.h
 create mode 100644 usr.bin/mkimg/gpt.c
 create mode 100644 usr.bin/mkimg/image.c
 create mode 100644 usr.bin/mkimg/image.h
 create mode 100644 usr.bin/mkimg/mbr.c
 create mode 100644 usr.bin/mkimg/mkimg.1
 create mode 100644 usr.bin/mkimg/mkimg.c
 create mode 100644 usr.bin/mkimg/mkimg.h
 create mode 100644 usr.bin/mkimg/qcow.c
 create mode 100644 usr.bin/mkimg/raw.c
 create mode 100644 usr.bin/mkimg/scheme.c
 create mode 100644 usr.bin/mkimg/scheme.h
 create mode 100644 usr.bin/mkimg/tests/Makefile
 create mode 100644 usr.bin/mkimg/tests/Makefile.depend
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-apm.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-apm.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-apm.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-apm.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-apm.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-apm.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-bsd.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-bsd.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-bsd.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-bsd.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-bsd.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-bsd.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-ebr.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-ebr.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-ebr.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-ebr.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-ebr.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-ebr.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-gpt.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-gpt.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-gpt.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-gpt.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-mbr.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-mbr.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-mbr.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-mbr.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-mbr.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-mbr.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-vtoc8.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-vtoc8.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-vtoc8.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-apm.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-apm.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-apm.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-apm.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-apm.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-apm.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-bsd.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-bsd.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-bsd.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-bsd.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-bsd.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-bsd.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-ebr.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-ebr.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-ebr.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-ebr.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-ebr.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-ebr.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-gpt.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-gpt.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-gpt.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-gpt.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-gpt.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-gpt.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-mbr.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-mbr.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-mbr.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-mbr.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-mbr.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-mbr.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-vtoc8.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-vtoc8.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-vtoc8.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-vtoc8.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-vtoc8.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-1x1-512-vtoc8.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-apm.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-apm.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-apm.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-apm.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-apm.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-apm.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-bsd.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-bsd.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-bsd.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-bsd.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-bsd.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-bsd.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-ebr.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-ebr.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-ebr.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-ebr.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-ebr.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-ebr.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-gpt.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-gpt.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-gpt.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-gpt.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-gpt.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-gpt.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-mbr.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-mbr.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-mbr.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-mbr.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-mbr.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-mbr.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-vtoc8.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-vtoc8.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-vtoc8.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-apm.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-apm.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-apm.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-apm.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-apm.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-apm.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-bsd.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-bsd.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-bsd.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-bsd.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-bsd.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-bsd.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-ebr.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-ebr.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-ebr.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-ebr.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-ebr.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-ebr.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-gpt.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-gpt.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-gpt.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-gpt.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-gpt.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-gpt.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-mbr.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-mbr.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-mbr.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-mbr.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-mbr.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-mbr.vmdk.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-vtoc8.qcow.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-vtoc8.qcow2.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-vtoc8.raw.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-vtoc8.vhd.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-vtoc8.vhdf.gz.uu
 create mode 100644 usr.bin/mkimg/tests/img-63x255-512-vtoc8.vmdk.gz.uu
 create mode 100755 usr.bin/mkimg/tests/mkimg_test.sh
 create mode 100644 usr.bin/mkimg/uuid.c
 create mode 100644 usr.bin/mkimg/vhd.c
 create mode 100644 usr.bin/mkimg/vmdk.c
 create mode 100644 usr.bin/mkimg/vtoc8.c

diff --git a/sys/sys/disk/apm.h b/sys/sys/disk/apm.h
new file mode 100644
index 0000000000..19a6b93417
--- /dev/null
+++ b/sys/sys/disk/apm.h
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (c) 2007 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: head/sys/sys/disk/apm.h 307386 2016-10-16 02:43:51Z marcel $
+ */
+
+#ifndef _SYS_DISK_APM_H_
+#define	_SYS_DISK_APM_H_
+
+/* Driver Descriptor Record. */
+struct apm_ddr {
+	uint16_t	ddr_sig;
+#define	APM_DDR_SIG		0x4552
+	uint16_t	ddr_blksize;
+	uint32_t	ddr_blkcount;
+};
+
+#define	APM_ENT_NAMELEN		32
+#define	APM_ENT_TYPELEN		32
+
+/* Partition Map Entry Record. */
+struct apm_ent {
+	uint16_t	ent_sig;
+#define	APM_ENT_SIG		0x504d
+	uint16_t	_pad_;
+	uint32_t	ent_pmblkcnt;
+	uint32_t	ent_start;
+	uint32_t	ent_size;
+	char		ent_name[APM_ENT_NAMELEN];
+	char		ent_type[APM_ENT_TYPELEN];
+};
+
+#define	APM_ENT_TYPE_SELF		"Apple_partition_map"
+#define	APM_ENT_TYPE_UNUSED		"Apple_Free"
+
+#define	APM_ENT_TYPE_FREEBSD		"FreeBSD"
+#define	APM_ENT_TYPE_FREEBSD_NANDFS	"FreeBSD-nandfs"
+#define	APM_ENT_TYPE_FREEBSD_SWAP	"FreeBSD-swap"
+#define	APM_ENT_TYPE_FREEBSD_UFS	"FreeBSD-UFS"
+#define	APM_ENT_TYPE_FREEBSD_VINUM	"FreeBSD-Vinum"
+#define	APM_ENT_TYPE_FREEBSD_ZFS	"FreeBSD-ZFS"
+
+#define	APM_ENT_TYPE_APPLE_BOOT		"Apple_Bootstrap"
+#define	APM_ENT_TYPE_APPLE_HFS		"Apple_HFS"
+#define	APM_ENT_TYPE_APPLE_UFS		"Apple_UNIX_SVR2"
+
+#endif /* _SYS_DISK_APM_H_ */
diff --git a/sys/sys/disk/bsd.h b/sys/sys/disk/bsd.h
new file mode 100644
index 0000000000..fd47fd2a85
--- /dev/null
+++ b/sys/sys/disk/bsd.h
@@ -0,0 +1,191 @@
+/*-
+ * Copyright (c) 1987, 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)disklabel.h	8.2 (Berkeley) 7/10/94
+ * $FreeBSD: head/sys/sys/disk/bsd.h 314436 2017-02-28 23:42:47Z imp $
+ */
+
+#ifndef _SYS_DISK_BSD_H_
+#define	_SYS_DISK_BSD_H_
+
+/* The disk magic number */
+#define BSD_MAGIC		0x82564557U
+
+#define	BSD_NPARTS_MIN		8
+#define	BSD_NPARTS_MAX		20
+
+/* Size of bootblock area in sector-size neutral bytes */
+#define BSD_BOOTBLOCK_SIZE	8192
+
+/* partition containing whole disk */
+#define	BSD_PART_RAW		2
+
+/* partition normally containing swap */
+#define	BSD_PART_SWAP		1
+
+/* Drive-type specific data size (in number of 32-bit inegrals) */
+#define	BSD_NDRIVEDATA		5
+
+/* Number of spare 32-bit integrals following drive-type data */
+#define	BSD_NSPARE		5
+
+struct disklabel {
+	uint32_t d_magic;		/* the magic number */
+	uint16_t d_type;		/* drive type */
+	uint16_t d_subtype;		/* controller/d_type specific */
+	char	 d_typename[16];	/* type name, e.g. "eagle" */
+
+	char	 d_packname[16];	/* pack identifier */
+
+			/* disk geometry: */
+	uint32_t d_secsize;		/* # of bytes per sector */
+	uint32_t d_nsectors;		/* # of data sectors per track */
+	uint32_t d_ntracks;		/* # of tracks per cylinder */
+	uint32_t d_ncylinders;		/* # of data cylinders per unit */
+	uint32_t d_secpercyl;		/* # of data sectors per cylinder */
+	uint32_t d_secperunit;		/* # of data sectors per unit */
+
+	/*
+	 * Spares (bad sector replacements) below are not counted in
+	 * d_nsectors or d_secpercyl.  Spare sectors are assumed to
+	 * be physical sectors which occupy space at the end of each
+	 * track and/or cylinder.
+	 */
+	uint16_t d_sparespertrack;	/* # of spare sectors per track */
+	uint16_t d_sparespercyl;	/* # of spare sectors per cylinder */
+	/*
+	 * Alternate cylinders include maintenance, replacement, configuration
+	 * description areas, etc.
+	 */
+	uint32_t d_acylinders;		/* # of alt. cylinders per unit */
+
+			/* hardware characteristics: */
+	/*
+	 * d_interleave, d_trackskew and d_cylskew describe perturbations
+	 * in the media format used to compensate for a slow controller.
+	 * Interleave is physical sector interleave, set up by the
+	 * formatter or controller when formatting.  When interleaving is
+	 * in use, logically adjacent sectors are not physically
+	 * contiguous, but instead are separated by some number of
+	 * sectors.  It is specified as the ratio of physical sectors
+	 * traversed per logical sector.  Thus an interleave of 1:1
+	 * implies contiguous layout, while 2:1 implies that logical
+	 * sector 0 is separated by one sector from logical sector 1.
+	 * d_trackskew is the offset of sector 0 on track N relative to
+	 * sector 0 on track N-1 on the same cylinder.  Finally, d_cylskew
+	 * is the offset of sector 0 on cylinder N relative to sector 0
+	 * on cylinder N-1.
+	 */
+	uint16_t d_rpm;			/* rotational speed */
+	uint16_t d_interleave;		/* hardware sector interleave */
+	uint16_t d_trackskew;		/* sector 0 skew, per track */
+	uint16_t d_cylskew;		/* sector 0 skew, per cylinder */
+	uint32_t d_headswitch;		/* head switch time, usec */
+	uint32_t d_trkseek;		/* track-to-track seek, usec */
+	uint32_t d_flags;		/* generic flags */
+	uint32_t d_drivedata[BSD_NDRIVEDATA];	/* drive-type specific data */
+	uint32_t d_spare[BSD_NSPARE];	/* reserved for future use */
+	uint32_t d_magic2;		/* the magic number (again) */
+	uint16_t d_checksum;		/* xor of data incl. partitions */
+
+			/* filesystem and partition information: */
+	uint16_t d_npartitions;	/* number of partitions in following */
+	uint32_t d_bbsize;		/* size of boot area at sn0, bytes */
+	uint32_t d_sbsize;		/* max size of fs superblock, bytes */
+	struct partition {		/* the partition table */
+		uint32_t p_size;	/* number of sectors in partition */
+		uint32_t p_offset;	/* starting sector */
+		uint32_t p_fsize;	/* filesystem basic fragment size */
+		uint8_t  p_fstype;	/* filesystem type, see below */
+		uint8_t  p_frag;	/* filesystem fragments per block */
+		uint16_t p_cpg;		/* filesystem cylinders per group */
+	} d_partitions[BSD_NPARTS_MIN];	/* actually may be more */
+};
+#ifdef CTASSERT
+CTASSERT(sizeof(struct disklabel) == 148 + BSD_NPARTS_MIN * 16);
+#endif
+
+/* d_type values: */
+#define	DTYPE_SMD		1		/* SMD, XSMD; VAX hp/up */
+#define	DTYPE_MSCP		2		/* MSCP */
+#define	DTYPE_DEC		3		/* other DEC (rk, rl) */
+#define	DTYPE_SCSI		4		/* SCSI */
+#define	DTYPE_ESDI		5		/* ESDI interface */
+#define	DTYPE_ST506		6		/* ST506 etc. */
+#define	DTYPE_HPIB		7		/* CS/80 on HP-IB */
+#define	DTYPE_HPFL		8		/* HP Fiber-link */
+#define	DTYPE_FLOPPY		10		/* floppy */
+#define	DTYPE_CCD		11		/* concatenated disk */
+#define	DTYPE_VINUM		12		/* vinum volume */
+#define	DTYPE_DOC2K		13		/* Msys DiskOnChip */
+#define	DTYPE_RAID		14		/* CMU RAIDFrame */
+#define	DTYPE_JFS2		16		/* IBM JFS 2 */
+
+/*
+ * Filesystem type and version.
+ * Used to interpret other filesystem-specific
+ * per-partition information.
+ */
+#define	FS_UNUSED	0		/* unused */
+#define	FS_SWAP		1		/* swap */
+#define	FS_V6		2		/* Sixth Edition */
+#define	FS_V7		3		/* Seventh Edition */
+#define	FS_SYSV		4		/* System V */
+#define	FS_V71K		5		/* V7 with 1K blocks (4.1, 2.9) */
+#define	FS_V8		6		/* Eighth Edition, 4K blocks */
+#define	FS_BSDFFS	7		/* 4.2BSD fast filesystem */
+#define	FS_MSDOS	8		/* MSDOS filesystem */
+#define	FS_BSDLFS	9		/* 4.4BSD log-structured filesystem */
+#define	FS_OTHER	10		/* in use, but unknown/unsupported */
+#define	FS_HPFS		11		/* OS/2 high-performance filesystem */
+#define	FS_ISO9660	12		/* ISO 9660, normally CD-ROM */
+#define	FS_BOOT		13		/* partition contains bootstrap */
+#define	FS_VINUM	14		/* Vinum drive */
+#define	FS_RAID		15		/* RAIDFrame drive */
+#define	FS_FILECORE	16		/* Acorn Filecore Filing System */
+#define	FS_EXT2FS	17		/* ext2fs */
+#define	FS_NTFS		18		/* Windows/NT file system */
+#define	FS_CCD		20		/* concatenated disk component */
+#define	FS_JFS2		21		/* IBM JFS2 */
+#define	FS_HAMMER	22		/* DragonFlyBSD Hammer FS */
+#define	FS_HAMMER2	23		/* DragonFlyBSD Hammer2 FS */
+#define	FS_UDF		24		/* UDF */
+#define	FS_EFS		26		/* SGI's Extent File system */
+#define	FS_ZFS		27		/* Sun's ZFS */
+#define	FS_NANDFS	30		/* FreeBSD nandfs (NiLFS derived) */
+
+/*
+ * flags shared by various drives:
+ */
+#define	D_REMOVABLE	0x01		/* removable media */
+#define	D_ECC		0x02		/* supports ECC */
+#define	D_BADSECT	0x04		/* supports bad sector forw. */
+#define	D_RAMDISK	0x08		/* disk emulator */
+#define	D_CHAIN		0x10		/* can do back-back transfers */
+
+#endif /* !_SYS_DISK_BSD_H_ */
diff --git a/sys/sys/disk/gpt.h b/sys/sys/disk/gpt.h
new file mode 100644
index 0000000000..e095918cbd
--- /dev/null
+++ b/sys/sys/disk/gpt.h
@@ -0,0 +1,239 @@
+/*-
+ * Copyright (c) 2002 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: head/sys/sys/disk/gpt.h 329119 2018-02-11 06:57:20Z cem $
+ */
+
+#ifndef _SYS_DISK_GPT_H_
+#define	_SYS_DISK_GPT_H_
+
+/*
+ * Applications can define GPT_UUID_TYPE if they want the GPT structures
+ * to use a particular type definition for UUIDs/GUIDs.  This header uses
+ * a generic (DCE 1.1 compatible) definition otherwise.
+ */
+#ifndef GPT_UUID_TYPE
+struct gpt_uuid {
+	uint32_t	time_low;
+	uint16_t	time_mid;
+	uint16_t	time_hi_and_version;
+	uint8_t		clock_seq_hi_and_reserved;
+	uint8_t		clock_seq_low;
+	uint8_t		node[6];
+};
+#define	GPT_UUID_TYPE	struct gpt_uuid
+#endif /* !GPT_UUID_TYPE */
+
+typedef GPT_UUID_TYPE gpt_uuid_t;
+
+#ifdef CTASSERT
+CTASSERT(sizeof(gpt_uuid_t) == 16);
+#endif
+
+struct gpt_hdr {
+	char		hdr_sig[8];
+#define	GPT_HDR_SIG		"EFI PART"
+	uint32_t	hdr_revision;
+#define	GPT_HDR_REVISION	0x00010000
+	uint32_t	hdr_size;
+	uint32_t	hdr_crc_self;
+	uint32_t	__reserved;
+	uint64_t	hdr_lba_self;
+	uint64_t	hdr_lba_alt;
+	uint64_t	hdr_lba_start;
+	uint64_t	hdr_lba_end;
+	gpt_uuid_t	hdr_uuid;
+	uint64_t	hdr_lba_table;
+	uint32_t	hdr_entries;
+	uint32_t	hdr_entsz;
+	uint32_t	hdr_crc_table;
+	/*
+	 * The header as defined in the EFI spec is not a multiple of 8 bytes
+	 * and given that the alignment requirement is on an 8 byte boundary,
+	 * padding will happen. We make the padding explicit so that we can
+	 * correct the value returned by sizeof() when we put the size of the
+	 * header in field hdr_size, or otherwise use offsetof().
+	 */
+	uint32_t	padding;
+};
+#ifdef CTASSERT
+CTASSERT(offsetof(struct gpt_hdr, padding) == 92);
+#endif
+
+struct gpt_ent {
+	gpt_uuid_t	ent_type;
+	gpt_uuid_t	ent_uuid;
+	uint64_t	ent_lba_start;
+	uint64_t	ent_lba_end;
+	uint64_t	ent_attr;
+#define	GPT_ENT_ATTR_PLATFORM		(1ULL << 0)
+#define	GPT_ENT_ATTR_BOOTME		(1ULL << 59)
+#define	GPT_ENT_ATTR_BOOTONCE		(1ULL << 58)
+#define	GPT_ENT_ATTR_BOOTFAILED		(1ULL << 57)
+	uint16_t	ent_name[36];		/* UTF-16. */
+};
+#ifdef CTASSERT
+CTASSERT(sizeof(struct gpt_ent) == 128);
+#endif /* CTASSERT */
+
+#define	GPT_ENT_TYPE_UNUSED		\
+	{0x00000000,0x0000,0x0000,0x00,0x00,{0x00,0x00,0x00,0x00,0x00,0x00}}
+#define	GPT_ENT_TYPE_EFI		\
+	{0xc12a7328,0xf81f,0x11d2,0xba,0x4b,{0x00,0xa0,0xc9,0x3e,0xc9,0x3b}}
+#define	GPT_ENT_TYPE_MBR		\
+	{0x024dee41,0x33e7,0x11d3,0x9d,0x69,{0x00,0x08,0xc7,0x81,0xf3,0x9f}}
+#define	GPT_ENT_TYPE_FREEBSD		\
+	{0x516e7cb4,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
+#define	GPT_ENT_TYPE_FREEBSD_BOOT	\
+	{0x83bd6b9d,0x7f41,0x11dc,0xbe,0x0b,{0x00,0x15,0x60,0xb8,0x4f,0x0f}}
+#define	GPT_ENT_TYPE_FREEBSD_NANDFS	\
+	{0x74ba7dd9,0xa689,0x11e1,0xbd,0x04,{0x00,0xe0,0x81,0x28,0x6a,0xcf}}
+#define	GPT_ENT_TYPE_FREEBSD_SWAP	\
+	{0x516e7cb5,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
+#define	GPT_ENT_TYPE_FREEBSD_UFS	\
+	{0x516e7cb6,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
+#define	GPT_ENT_TYPE_FREEBSD_VINUM	\
+	{0x516e7cb8,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
+#define	GPT_ENT_TYPE_FREEBSD_ZFS	\
+	{0x516e7cba,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
+#define	GPT_ENT_TYPE_PREP_BOOT		\
+	{0x9e1a2d38,0xc612,0x4316,0xaa,0x26,{0x8b,0x49,0x52,0x1e,0x5a,0x8b}}
+
+/*
+ * The following are unused but documented here to avoid reuse.
+ *
+ * GPT_ENT_TYPE_FREEBSD_UFS2	\
+ *	{0x516e7cb7,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
+ */
+
+/*
+ * Foreign partition types that we're likely to encounter. Note that Linux
+ * apparently choose to share data partitions with MS. I don't what the
+ * advantage might be. I can see how sharing swap partitions is advantageous
+ * though.
+ */
+#define	GPT_ENT_TYPE_MS_BASIC_DATA	\
+	{0xebd0a0a2,0xb9e5,0x4433,0x87,0xc0,{0x68,0xb6,0xb7,0x26,0x99,0xc7}}
+#define	GPT_ENT_TYPE_MS_LDM_DATA	\
+	{0xaf9b60a0,0x1431,0x4f62,0xbc,0x68,{0x33,0x11,0x71,0x4a,0x69,0xad}}
+#define	GPT_ENT_TYPE_MS_LDM_METADATA	\
+	{0x5808c8aa,0x7e8f,0x42e0,0x85,0xd2,{0xe1,0xe9,0x04,0x34,0xcf,0xb3}}
+#define	GPT_ENT_TYPE_MS_RECOVERY	\
+	{0xde94bba4,0x06d1,0x4d40,0xa1,0x6a,{0xbf,0xd5,0x01,0x79,0xd6,0xac}}
+#define	GPT_ENT_TYPE_MS_RESERVED	\
+	{0xe3c9e316,0x0b5c,0x4db8,0x81,0x7d,{0xf9,0x2d,0xf0,0x02,0x15,0xae}}
+#define	GPT_ENT_TYPE_MS_SPACES	\
+	{0xe75caf8f,0xf680,0x4cee,0xaf,0xa3,{0xb0,0x01,0xe5,0x6e,0xfc,0x2d}}
+
+#define	GPT_ENT_TYPE_LINUX_DATA		\
+	{0x0fc63daf,0x8483,0x4772,0x8e,0x79,{0x3d,0x69,0xd8,0x47,0x7d,0xe4}}
+#define	GPT_ENT_TYPE_LINUX_RAID		\
+	{0xa19d880f,0x05fc,0x4d3b,0xa0,0x06,{0x74,0x3f,0x0f,0x84,0x91,0x1e}}
+#define	GPT_ENT_TYPE_LINUX_SWAP		\
+	{0x0657fd6d,0xa4ab,0x43c4,0x84,0xe5,{0x09,0x33,0xc8,0x4b,0x4f,0x4f}}
+#define	GPT_ENT_TYPE_LINUX_LVM		\
+	{0xe6d6d379,0xf507,0x44c2,0xa2,0x3c,{0x23,0x8f,0x2a,0x3d,0xf9,0x28}}
+
+#define	GPT_ENT_TYPE_VMFS		\
+	{0xaa31e02a,0x400f,0x11db,0x95,0x90,{0x00,0x0c,0x29,0x11,0xd1,0xb8}}
+#define	GPT_ENT_TYPE_VMKDIAG		\
+	{0x9d275380,0x40ad,0x11db,0xbf,0x97,{0x00,0x0c,0x29,0x11,0xd1,0xb8}}
+#define	GPT_ENT_TYPE_VMRESERVED		\
+	{0x9198effc,0x31c0,0x11db,0x8f,0x78,{0x00,0x0c,0x29,0x11,0xd1,0xb8}}
+#define	GPT_ENT_TYPE_VMVSANHDR		\
+	{0x381cfccc,0x7288,0x11e0,0x92,0xee,{0x00,0x0c,0x29,0x11,0xd0,0xb2}}
+
+#define	GPT_ENT_TYPE_APPLE_BOOT		\
+	{0x426F6F74,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
+#define	GPT_ENT_TYPE_APPLE_HFS		\
+	{0x48465300,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
+#define	GPT_ENT_TYPE_APPLE_UFS		\
+	{0x55465300,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
+#define	GPT_ENT_TYPE_APPLE_ZFS		\
+	{0x6a898cc3,0x1dd2,0x11b2,0x99,0xa6,{0x08,0x00,0x20,0x73,0x66,0x31}}
+#define	GPT_ENT_TYPE_APPLE_RAID		\
+	{0x52414944,0x0000,0x11aa,0xaa,0x22,{0x00,0x30,0x65,0x43,0xec,0xac}}
+#define	GPT_ENT_TYPE_APPLE_RAID_OFFLINE	\
+	{0x52414944,0x5f4f,0x11aa,0xaa,0x22,{0x00,0x30,0x65,0x43,0xec,0xac}}
+#define GPT_ENT_TYPE_APPLE_LABEL	\
+    	{0x4C616265,0x6c00,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
+#define	GPT_ENT_TYPE_APPLE_TV_RECOVERY	\
+    	{0x5265636f,0x7665,0x11AA,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
+#define	GPT_ENT_TYPE_APPLE_CORE_STORAGE	\
+	{0x53746f72,0x6167,0x11AA,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
+#define	GPT_ENT_TYPE_APPLE_APFS	\
+	{0x7c3457ef,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
+
+#define	GPT_ENT_TYPE_NETBSD_FFS		\
+	{0x49f48d5a,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
+#define	GPT_ENT_TYPE_NETBSD_LFS		\
+	{0x49f48d82,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
+#define	GPT_ENT_TYPE_NETBSD_SWAP	\
+	{0x49f48d32,0xb10e,0x11dc,0xB9,0x9B,{0x00,0x19,0xd1,0x87,0x96,0x48}}
+#define	GPT_ENT_TYPE_NETBSD_RAID	\
+	{0x49f48daa,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
+#define	GPT_ENT_TYPE_NETBSD_CCD		\
+	{0x2db519c4,0xb10f,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
+#define	GPT_ENT_TYPE_NETBSD_CGD		\
+	{0x2db519ec,0xb10f,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
+
+#define GPT_ENT_TYPE_DRAGONFLY_LABEL32	\
+	{0x9d087404,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
+#define GPT_ENT_TYPE_DRAGONFLY_SWAP	\
+	{0x9d58fdbd,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
+#define GPT_ENT_TYPE_DRAGONFLY_UFS1	\
+	{0x9d94ce7c,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
+#define GPT_ENT_TYPE_DRAGONFLY_VINUM	\
+	{0x9dd4478f,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
+#define GPT_ENT_TYPE_DRAGONFLY_CCD	\
+	{0xdbd5211b,0x1ca5,0x11dc,0x88,0x17,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
+#define GPT_ENT_TYPE_DRAGONFLY_LABEL64	\
+	{0x3d48ce54,0x1d16,0x11dc,0x86,0x96,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
+#define GPT_ENT_TYPE_DRAGONFLY_LEGACY	\
+	{0xbd215ab2,0x1d16,0x11dc,0x86,0x96,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
+#define GPT_ENT_TYPE_DRAGONFLY_HAMMER	\
+	{0x61dc63ac,0x6e38,0x11dc,0x85,0x13,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
+#define GPT_ENT_TYPE_DRAGONFLY_HAMMER2	\
+	{0x5cbb9ad1,0x862d,0x11dc,0xa9,0x4d,{0x01,0x30,0x1b,0xb8,0xa9,0xf5}}
+
+#define GPT_ENT_TYPE_CHROMEOS_FIRMWARE	\
+	{0xcab6e88e,0xabf3,0x4102,0xa0,0x7a,{0xd4,0xbb,0x9b,0xe3,0xc1,0xd3}}
+#define GPT_ENT_TYPE_CHROMEOS_KERNEL	\
+	{0xfe3a2a5d,0x4f32,0x41a7,0xb7,0x25,{0xac,0xcc,0x32,0x85,0xa3,0x09}}
+#define GPT_ENT_TYPE_CHROMEOS_RESERVED	\
+	{0x2e0a753d,0x9e48,0x43b0,0x83,0x37,{0xb1,0x51,0x92,0xcb,0x1b,0x5e}}
+#define GPT_ENT_TYPE_CHROMEOS_ROOT	\
+	{0x3cb8e202,0x3b7e,0x47dd,0x8a,0x3c,{0x7f,0xf2,0xa1,0x3c,0xfc,0xec}}
+
+#define GPT_ENT_TYPE_OPENBSD_DATA	\
+	{0x824cc7a0,0x36a8,0x11e3,0x89,0x0a,{0x95,0x25,0x19,0xad,0x3f,0x61}}
+
+/*
+ * Boot partition used by GRUB 2.
+ */
+#define	GPT_ENT_TYPE_BIOS_BOOT		\
+	{0x21686148,0x6449,0x6e6f,0x74,0x4e,{0x65,0x65,0x64,0x45,0x46,0x49}}
+
+#endif /* _SYS_DISK_GPT_H_ */
diff --git a/sys/sys/disk/mbr.h b/sys/sys/disk/mbr.h
new file mode 100644
index 0000000000..584d104391
--- /dev/null
+++ b/sys/sys/disk/mbr.h
@@ -0,0 +1,85 @@
+/*-
+ * Copyright (c) 1987, 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)disklabel.h	8.2 (Berkeley) 7/10/94
+ * $FreeBSD: head/sys/sys/disk/mbr.h 333233 2018-05-04 00:34:27Z emaste $
+ */
+
+#ifndef _SYS_DISK_MBR_H_
+#define	_SYS_DISK_MBR_H_
+
+#define	DOSBBSECTOR	0	/* DOS boot block relative sector number */
+#define	DOSDSNOFF	440	/* WinNT/2K/XP Drive Serial Number offset */
+#define	DOSPARTOFF	446
+#define	DOSPARTSIZE	16
+#define	NDOSPART	4
+#define	NEXTDOSPART	32
+#define	DOSMAGICOFFSET	510
+#define	DOSMAGIC	0xAA55
+
+#define	DOSPTYP_EXT	0x05	/* DOS extended partition */
+#define	DOSPTYP_FAT16	0x06	/* FAT16 partition */
+#define	DOSPTYP_NTFS	0x07	/* NTFS partition */
+#define	DOSPTYP_FAT32	0x0b	/* FAT32 partition */
+#define	DOSPTYP_FAT32LBA	0x0c	/* FAT32 with LBA partition */
+#define	DOSPTYP_EXTLBA	0x0f	/* DOS extended partition */
+#define	DOSPTYP_PPCBOOT	0x41	/* PReP/CHRP boot partition */
+#define	DOSPTYP_LDM	0x42	/* Win2k dynamic extended partition */
+#define	DOSPTYP_LINSWP	0x82	/* Linux swap partition */
+#define	DOSPTYP_LINUX	0x83	/* Linux partition */
+#define	DOSPTYP_LINLVM	0x8e	/* Linux LVM partition */
+#define	DOSPTYP_386BSD	0xa5	/* 386BSD partition type */
+#define	DOSPTYP_APPLE_UFS	0xa8	/* Apple Mac OS X boot */
+#define	DOSPTYP_APPLE_BOOT	0xab	/* Apple Mac OS X UFS */
+#define	DOSPTYP_HFS	0xaf	/* HFS/HFS+ partition type */
+#define	DOSPTYP_PMBR	0xee	/* GPT Protective MBR */
+#define	DOSPTYP_EFI	0xef	/* EFI FAT parition */
+#define	DOSPTYP_VMFS	0xfb	/* VMware VMFS partition */
+#define	DOSPTYP_VMKDIAG	0xfc	/* VMware vmkDiagnostic partition */
+#define	DOSPTYP_LINRAID	0xfd	/* Linux raid partition */
+
+struct dos_partition {
+	unsigned char	dp_flag;	/* bootstrap flags */
+	unsigned char	dp_shd;		/* starting head */
+	unsigned char	dp_ssect;	/* starting sector */
+	unsigned char	dp_scyl;	/* starting cylinder */
+	unsigned char	dp_typ;		/* partition type */
+	unsigned char	dp_ehd;		/* end head */
+	unsigned char	dp_esect;	/* end sector */
+	unsigned char	dp_ecyl;	/* end cylinder */
+	uint32_t	dp_start;	/* absolute starting sector number */
+	uint32_t	dp_size;	/* partition size in sectors */
+};
+#ifdef CTASSERT
+CTASSERT(sizeof (struct dos_partition) == DOSPARTSIZE);
+#endif
+
+#define	DPSECT(s) ((s) & 0x3f)		/* isolate relevant bits of sector */
+#define	DPCYL(c, s) ((c) + (((s) & 0xc0)<<2)) /* and those that are cylinder */
+
+#endif /* !_SYS_DISK_MBR_H_ */
diff --git a/sys/sys/disk/vtoc.h b/sys/sys/disk/vtoc.h
new file mode 100644
index 0000000000..e635ff198e
--- /dev/null
+++ b/sys/sys/disk/vtoc.h
@@ -0,0 +1,108 @@
+/*-
+ * Copyright (c) 2008 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: head/sys/sys/disk/vtoc.h 307386 2016-10-16 02:43:51Z marcel $
+ */
+
+#ifndef _SYS_DISK_VTOC_H_
+#define	_SYS_DISK_VTOC_H_
+
+#define	VTOC_TAG_UNASSIGNED	0x00
+#define	VTOC_TAG_BOOT		0x01
+#define	VTOC_TAG_ROOT		0x02
+#define	VTOC_TAG_SWAP		0x03
+#define	VTOC_TAG_USR		0x04
+#define	VTOC_TAG_BACKUP		0x05	/* "c" partition */
+#define	VTOC_TAG_STAND		0x06
+#define	VTOC_TAG_VAR		0x07
+#define	VTOC_TAG_HOME		0x08
+#define	VTOC_TAG_ALTSCTR	0x09	/* alternate sector partition */
+#define	VTOC_TAG_CACHE		0x0a	/* Solaris cachefs partition */
+#define	VTOC_TAG_VXVM_PUB	0x0e	/* VxVM public region */
+#define	VTOC_TAG_VXVM_PRIV	0x0f	/* VxVM private region */
+
+/* NetBSD/mips defines this */
+#define	VTOC_TAG_NETBSD_FFS	0xff
+
+/* FreeBSD tags: the high byte equals ELFOSABI_FREEBSD */
+#define	VTOC_TAG_FREEBSD_SWAP	0x0901
+#define	VTOC_TAG_FREEBSD_UFS	0x0902
+#define	VTOC_TAG_FREEBSD_VINUM	0x0903
+#define	VTOC_TAG_FREEBSD_ZFS	0x0904
+#define	VTOC_TAG_FREEBSD_NANDFS	0x0905
+
+#define	VTOC_FLAG_UNMNT		0x01	/* unmountable partition */
+#define	VTOC_FLAG_RDONLY	0x10    /* partition is read/only */
+
+#define	VTOC_ASCII_LEN	128
+#define	VTOC_BOOTSIZE	8192		/* 16 sectors */
+#define	VTOC_MAGIC	0xdabe
+#define	VTOC_RAW_PART	2
+#define	VTOC_SANITY	0x600ddeee
+#define	VTOC_VERSION	1
+#define	VTOC_VOLUME_LEN	8
+
+#define	VTOC8_NPARTS	8
+
+struct vtoc8 {
+	char		ascii[VTOC_ASCII_LEN];
+	uint32_t	version;
+	char		volume[VTOC_VOLUME_LEN];
+	uint16_t	nparts;
+	struct {
+		uint16_t	tag;
+		uint16_t	flag;
+	} part[VTOC8_NPARTS];
+	uint16_t	__alignment;
+	uint32_t	bootinfo[3];
+	uint32_t	sanity;
+	uint32_t	reserved[10];
+	uint32_t	timestamp[VTOC8_NPARTS];
+	uint16_t	wskip;
+	uint16_t	rskip;
+	char		padding[152];
+	uint16_t	rpm;
+	uint16_t	physcyls;
+	uint16_t	sparesecs;
+	uint16_t	spare1[2];
+	uint16_t	interleave;
+	uint16_t	ncyls;
+	uint16_t	altcyls;
+	uint16_t	nheads;
+	uint16_t	nsecs;
+	uint16_t	spare2[2];
+	struct {
+		uint32_t	cyl;
+		uint32_t	nblks;
+	} map[VTOC8_NPARTS];
+	uint16_t	magic;
+	uint16_t	cksum;
+};
+
+#ifdef CTASSERT
+CTASSERT(sizeof(struct vtoc8) == 512);
+#endif
+
+#endif /* _SYS_DISK_VTOC_H_ */
diff --git a/sys/sys/queue.h b/sys/sys/queue.h
index d13f26028f..99a80b10bb 100644
--- a/sys/sys/queue.h
+++ b/sys/sys/queue.h
@@ -526,6 +526,11 @@ struct {								\
 	    (var);							\
 	    (var) = TAILQ_NEXT((var), field))
 
+#define	TAILQ_FOREACH_FROM(var, head, field)				\
+	for ((var) = ((var) ? (var) : TAILQ_FIRST((head)));		\
+	    (var);							\
+	    (var) = TAILQ_NEXT((var), field))
+
 #define	TAILQ_FOREACH_MUTABLE(var, head, field, tvar)			\
 	for ((var) = TAILQ_FIRST((head));				\
 	    (var) && ((tvar) = TAILQ_NEXT((var), field), 1);		\
diff --git a/usr.bin/Makefile b/usr.bin/Makefile
index 4284db5c74..fabc91581e 100644
--- a/usr.bin/Makefile
+++ b/usr.bin/Makefile
@@ -122,6 +122,7 @@ SUBDIR=	alias \
 	mkdep \
 	mkesdb \
 	mkfifo \
+	mkimg \
 	mkstr \
 	mktemp \
 	monitor \
diff --git a/usr.bin/mkimg/Makefile b/usr.bin/mkimg/Makefile
new file mode 100644
index 0000000000..e49548d9ad
--- /dev/null
+++ b/usr.bin/mkimg/Makefile
@@ -0,0 +1,38 @@
+# $FreeBSD: head/usr.bin/mkimg/Makefile 322515 2017-08-14 19:21:37Z ngie $
+
+PROG=	mkimg
+SRCS+=	format.c image.c mkimg.c scheme.c uuid.c
+MAN=	mkimg.1
+
+MKIMG_VERSION=20161016
+mkimg.o: Makefile
+
+CFLAGS+=-DMKIMG_VERSION=${MKIMG_VERSION}
+CFLAGS+=-DSPARSE_WRITE
+CFLAGS+=-I${.CURDIR}/../../sys/sys/disk
+
+# List of formats to support
+SRCS+= \
+	qcow.c \
+	raw.c \
+	vhd.c \
+	vmdk.c
+
+# List of schemes to support
+SRCS+=	\
+	apm.c \
+	bsd.c \
+	ebr.c \
+	gpt.c \
+	mbr.c \
+	vtoc8.c
+
+BINDIR?=/usr/bin
+
+LDADD=	-lutil
+DPADD=	${LIBUTIL}
+
+HAS_TESTS=
+SUBDIR.${MK_TESTS}+= tests
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/mkimg/apm.c b/usr.bin/mkimg/apm.c
new file mode 100644
index 0000000000..5d85401691
--- /dev/null
+++ b/usr.bin/mkimg/apm.c
@@ -0,0 +1,117 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/apm.c 307544 2016-10-18 01:55:07Z marcel $");
+
+#include <sys/errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <apm.h>
+
+#include "endian.h"
+#include "image.h"
+#include "mkimg.h"
+#include "scheme.h"
+
+static struct mkimg_alias apm_aliases[] = {
+    {	ALIAS_FREEBSD, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD) },
+    {	ALIAS_FREEBSD_BOOT, ALIAS_PTR2TYPE(APM_ENT_TYPE_APPLE_BOOT) },
+    {	ALIAS_FREEBSD_NANDFS, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_NANDFS) },
+    {	ALIAS_FREEBSD_SWAP, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_SWAP) },
+    {	ALIAS_FREEBSD_UFS, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_UFS) },
+    {	ALIAS_FREEBSD_VINUM, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_VINUM) },
+    {	ALIAS_FREEBSD_ZFS, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_ZFS) },
+    {	ALIAS_NONE, 0 }
+};
+
+static lba_t
+apm_metadata(u_int where, lba_t blk)
+{
+
+	blk += (where == SCHEME_META_IMG_START) ? nparts + 2 : 0;
+	return (round_block(blk));
+}
+
+static int
+apm_write(lba_t imgsz, void *bootcode __unused)
+{
+	u_char *buf;
+	struct apm_ddr *ddr;
+	struct apm_ent *ent;
+	struct part *part;
+	int error;
+
+	buf = calloc(nparts + 2, secsz);
+	if (buf == NULL)
+		return (ENOMEM);
+	ddr = (void *)buf;
+	be16enc(&ddr->ddr_sig, APM_DDR_SIG);
+	be16enc(&ddr->ddr_blksize, secsz);
+	be32enc(&ddr->ddr_blkcount, imgsz);
+
+	/* partition entry for the partition table itself. */
+	ent = (void *)(buf + secsz);
+	be16enc(&ent->ent_sig, APM_ENT_SIG);
+	be32enc(&ent->ent_pmblkcnt, nparts + 1);
+	be32enc(&ent->ent_start, 1);
+	be32enc(&ent->ent_size, nparts + 1);
+	strncpy(ent->ent_type, APM_ENT_TYPE_SELF, sizeof(ent->ent_type));
+	strncpy(ent->ent_name, "Apple", sizeof(ent->ent_name));
+
+	TAILQ_FOREACH(part, &partlist, link) {
+		ent = (void *)(buf + (part->index + 2) * secsz);
+		be16enc(&ent->ent_sig, APM_ENT_SIG);
+		be32enc(&ent->ent_pmblkcnt, nparts + 1);
+		be32enc(&ent->ent_start, part->block);
+		be32enc(&ent->ent_size, part->size);
+		strncpy(ent->ent_type, ALIAS_TYPE2PTR(part->type),
+		    sizeof(ent->ent_type));
+		if (part->label != NULL)
+			strncpy(ent->ent_name, part->label,
+			    sizeof(ent->ent_name));
+	}
+
+	error = image_write(0, buf, nparts + 2);
+	free(buf);
+	return (error);
+}
+
+static struct mkimg_scheme apm_scheme = {
+	.name = "apm",
+	.description = "Apple Partition Map",
+	.aliases = apm_aliases,
+	.metadata = apm_metadata,
+	.write = apm_write,
+	.nparts = 4096,
+	.labellen = APM_ENT_NAMELEN - 1,
+	.maxsecsz = 4096
+};
+
+SCHEME_DEFINE(apm_scheme);
diff --git a/usr.bin/mkimg/bsd.c b/usr.bin/mkimg/bsd.c
new file mode 100644
index 0000000000..0d5747ec44
--- /dev/null
+++ b/usr.bin/mkimg/bsd.c
@@ -0,0 +1,136 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/bsd.c 307544 2016-10-18 01:55:07Z marcel $");
+
+#include <sys/errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <bsd.h>
+
+#include "endian.h"
+#include "image.h"
+#include "mkimg.h"
+#include "scheme.h"
+
+static struct mkimg_alias bsd_aliases[] = {
+    {	ALIAS_FREEBSD_NANDFS, ALIAS_INT2TYPE(FS_NANDFS) },
+    {	ALIAS_FREEBSD_SWAP, ALIAS_INT2TYPE(FS_SWAP) },
+    {	ALIAS_FREEBSD_UFS, ALIAS_INT2TYPE(FS_BSDFFS) },
+    {	ALIAS_FREEBSD_VINUM, ALIAS_INT2TYPE(FS_VINUM) },
+    {	ALIAS_FREEBSD_ZFS, ALIAS_INT2TYPE(FS_ZFS) },
+    {	ALIAS_NONE, 0 }
+};
+
+static lba_t
+bsd_metadata(u_int where, lba_t blk)
+{
+
+	if (where == SCHEME_META_IMG_START)
+		blk += BSD_BOOTBLOCK_SIZE / secsz;
+	else if (where == SCHEME_META_IMG_END)
+		blk = round_cylinder(blk);
+	else
+		blk = round_block(blk);
+	return (blk);
+}
+
+static int
+bsd_write(lba_t imgsz, void *bootcode)
+{
+	u_char *buf, *p;
+	struct disklabel *d;
+	struct partition *dp;
+	struct part *part;
+	int bsdparts, error, n;
+	uint16_t checksum;
+
+	buf = malloc(BSD_BOOTBLOCK_SIZE);
+	if (buf == NULL)
+		return (ENOMEM);
+	if (bootcode != NULL) {
+		memcpy(buf, bootcode, BSD_BOOTBLOCK_SIZE);
+		memset(buf + secsz, 0, sizeof(struct disklabel));
+	} else
+		memset(buf, 0, BSD_BOOTBLOCK_SIZE);
+
+	bsdparts = nparts + 1;	/* Account for c partition */
+	if (bsdparts < BSD_NPARTS_MIN)
+		bsdparts = BSD_NPARTS_MIN;
+
+	d = (void *)(buf + secsz);
+	le32enc(&d->d_magic, BSD_MAGIC);
+	le32enc(&d->d_secsize, secsz);
+	le32enc(&d->d_nsectors, nsecs);
+	le32enc(&d->d_ntracks, nheads);
+	le32enc(&d->d_ncylinders, ncyls);
+	le32enc(&d->d_secpercyl, nsecs * nheads);
+	le32enc(&d->d_secperunit, imgsz);
+	le16enc(&d->d_rpm, 3600);
+	le32enc(&d->d_magic2, BSD_MAGIC);
+	le16enc(&d->d_npartitions, bsdparts);
+	le32enc(&d->d_bbsize, BSD_BOOTBLOCK_SIZE);
+
+	dp = &d->d_partitions[BSD_PART_RAW];
+	le32enc(&dp->p_size, imgsz);
+	TAILQ_FOREACH(part, &partlist, link) {
+		n = part->index + ((part->index >= BSD_PART_RAW) ? 1 : 0);
+		dp = &d->d_partitions[n];
+		le32enc(&dp->p_size, part->size);
+		le32enc(&dp->p_offset, part->block);
+		le32enc(&dp->p_fsize, 0);
+		dp->p_fstype = ALIAS_TYPE2INT(part->type);
+		dp->p_frag = 0;
+		le16enc(&dp->p_cpg, 0);
+	}
+
+	dp = &d->d_partitions[bsdparts];
+	checksum = 0;
+	for (p = (void *)d; p < (u_char *)dp; p += 2)
+		checksum ^= le16dec(p);
+	le16enc(&d->d_checksum, checksum);
+
+	error = image_write(0, buf, BSD_BOOTBLOCK_SIZE / secsz);
+	free(buf);
+	return (error);
+}
+
+static struct mkimg_scheme bsd_scheme = {
+	.name = "bsd",
+	.description = "BSD disk label",
+	.aliases = bsd_aliases,
+	.metadata = bsd_metadata,
+	.write = bsd_write,
+	.nparts = BSD_NPARTS_MAX - 1,
+	.bootcode = BSD_BOOTBLOCK_SIZE,
+	.maxsecsz = 512
+};
+
+SCHEME_DEFINE(bsd_scheme);
diff --git a/usr.bin/mkimg/ebr.c b/usr.bin/mkimg/ebr.c
new file mode 100644
index 0000000000..f2562f05a5
--- /dev/null
+++ b/usr.bin/mkimg/ebr.c
@@ -0,0 +1,131 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/ebr.c 307544 2016-10-18 01:55:07Z marcel $");
+
+#include <sys/errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <mbr.h>
+
+#include "endian.h"
+#include "image.h"
+#include "mkimg.h"
+#include "scheme.h"
+
+static struct mkimg_alias ebr_aliases[] = {
+    {	ALIAS_FAT16B, ALIAS_INT2TYPE(DOSPTYP_FAT16) },
+    {	ALIAS_FAT32, ALIAS_INT2TYPE(DOSPTYP_FAT32) },
+    {	ALIAS_FREEBSD, ALIAS_INT2TYPE(DOSPTYP_386BSD) },
+    {	ALIAS_NONE, 0 }
+};
+
+static lba_t
+ebr_metadata(u_int where, lba_t blk)
+{
+
+	blk += (where == SCHEME_META_PART_BEFORE) ? 1 : 0;
+	return (round_track(blk));
+}
+
+static void
+ebr_chs(u_char *cylp, u_char *hdp, u_char *secp, lba_t lba)
+{
+	u_int cyl, hd, sec;
+
+	mkimg_chs(lba, 1023, &cyl, &hd, &sec);
+	*cylp = cyl;
+	*hdp = hd;
+	*secp = (sec & 0x3f) | ((cyl >> 2) & 0xc0);
+}
+
+static int
+ebr_write(lba_t imgsz __unused, void *bootcode __unused)
+{
+	u_char *ebr;
+	struct dos_partition *dp;
+	struct part *part, *next;
+	lba_t block, size;
+	int error;
+
+	ebr = malloc(secsz);
+	if (ebr == NULL)
+		return (ENOMEM);
+	memset(ebr, 0, secsz);
+	le16enc(ebr + DOSMAGICOFFSET, DOSMAGIC);
+
+	error = 0;
+	TAILQ_FOREACH(part, &partlist, link) {
+		block = part->block - nsecs;
+		size = round_track(part->size);
+		dp = (void *)(ebr + DOSPARTOFF);
+		ebr_chs(&dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect, nsecs);
+		dp->dp_typ = ALIAS_TYPE2INT(part->type);
+		ebr_chs(&dp->dp_ecyl, &dp->dp_ehd, &dp->dp_esect,
+		    part->block + size - 1);
+		le32enc(&dp->dp_start, nsecs);
+		le32enc(&dp->dp_size, size);
+
+		/* Add link entry */
+		next = TAILQ_NEXT(part, link);
+		if (next != NULL) {
+			size = round_track(next->size);
+			dp++;
+			ebr_chs(&dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect,
+			    next->block - nsecs);
+			dp->dp_typ = DOSPTYP_EXT;
+			ebr_chs(&dp->dp_ecyl, &dp->dp_ehd, &dp->dp_esect,
+			    next->block + size - 1);
+			le32enc(&dp->dp_start, next->block - nsecs);
+			le32enc(&dp->dp_size, size + nsecs);
+		}
+
+		error = image_write(block, ebr, 1);
+		if (error)
+			break;
+
+		memset(ebr + DOSPARTOFF, 0, 2 * DOSPARTSIZE);
+	}
+
+	free(ebr);
+	return (error);
+}
+
+static struct mkimg_scheme ebr_scheme = {
+	.name = "ebr",
+	.description = "Extended Boot Record",
+	.aliases = ebr_aliases,
+	.metadata = ebr_metadata,
+	.write = ebr_write,
+	.nparts = 4096,
+	.maxsecsz = 4096
+};
+
+SCHEME_DEFINE(ebr_scheme);
diff --git a/usr.bin/mkimg/endian.h b/usr.bin/mkimg/endian.h
new file mode 100644
index 0000000000..0310b95570
--- /dev/null
+++ b/usr.bin/mkimg/endian.h
@@ -0,0 +1,106 @@
+/*-
+ * Copyright (c) 2002 Thomas Moestl <tmm@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: head/usr.bin/mkimg/endian.h 306330 2016-09-26 01:06:32Z marcel $
+ */
+
+#ifndef _MKIMG_ENDIAN_H_
+#define _MKIMG_ENDIAN_H_
+
+static __inline uint16_t
+be16dec(const void *pp)
+{
+	uint8_t const *p = (uint8_t const *)pp;
+
+	return ((p[0] << 8) | p[1]);
+}
+
+static __inline void
+be16enc(void *pp, uint16_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	p[0] = (u >> 8) & 0xff;
+	p[1] = u & 0xff;
+}
+
+static __inline void
+be32enc(void *pp, uint32_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	p[0] = (u >> 24) & 0xff;
+	p[1] = (u >> 16) & 0xff;
+	p[2] = (u >> 8) & 0xff;
+	p[3] = u & 0xff;
+}
+
+static __inline void
+be64enc(void *pp, uint64_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	be32enc(p, (uint32_t)(u >> 32));
+	be32enc(p + 4, (uint32_t)(u & 0xffffffffU));
+}
+
+static __inline uint16_t
+le16dec(const void *pp)
+{
+	uint8_t const *p = (uint8_t const *)pp;
+
+	return ((p[1] << 8) | p[0]);
+}
+
+static __inline void
+le16enc(void *pp, uint16_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	p[0] = u & 0xff;
+	p[1] = (u >> 8) & 0xff;
+}
+
+static __inline void
+le32enc(void *pp, uint32_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	p[0] = u & 0xff;
+	p[1] = (u >> 8) & 0xff;
+	p[2] = (u >> 16) & 0xff;
+	p[3] = (u >> 24) & 0xff;
+}
+
+static __inline void
+le64enc(void *pp, uint64_t u)
+{
+	uint8_t *p = (uint8_t *)pp;
+
+	le32enc(p, (uint32_t)(u & 0xffffffffU));
+	le32enc(p + 4, (uint32_t)(u >> 32));
+}
+
+#endif /* _MKIMG_ENDIAN_H_ */
diff --git a/usr.bin/mkimg/format.c b/usr.bin/mkimg/format.c
new file mode 100644
index 0000000000..1cc7c0d5a6
--- /dev/null
+++ b/usr.bin/mkimg/format.c
@@ -0,0 +1,100 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/format.c 306621 2016-10-03 02:37:28Z marcel $");
+
+#include <sys/stat.h>
+#include <err.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "image.h"
+#include "format.h"
+#include "mkimg.h"
+
+static struct mkimg_format *first;
+static struct mkimg_format *format;
+
+struct mkimg_format *
+format_iterate(struct mkimg_format *f)
+{
+
+	return ((f == NULL) ? first : f->next);
+}
+
+void
+format_register(struct mkimg_format *f)
+{
+
+	f->next = first;
+	first = f;
+}
+
+int
+format_resize(lba_t end)
+{
+
+	if (format == NULL)
+		return (ENOSYS);
+	return (format->resize(end));
+}
+
+int
+format_select(const char *spec)
+{
+	struct mkimg_format *f;
+
+	f = NULL;
+	while ((f = format_iterate(f)) != NULL) {
+		if (strcasecmp(spec, f->name) == 0) {
+			format = f;
+			return (0);
+		}
+	}
+	return (EINVAL);
+}
+
+struct mkimg_format *
+format_selected(void)
+{
+
+	return (format);
+}
+
+int
+format_write(int fd)
+{
+	int error;
+
+	if (format == NULL)
+		return (ENOSYS);
+	error = format->write(fd);
+	return (error);
+}
diff --git a/usr.bin/mkimg/format.h b/usr.bin/mkimg/format.h
new file mode 100644
index 0000000000..f9ac33c07e
--- /dev/null
+++ b/usr.bin/mkimg/format.h
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: head/usr.bin/mkimg/format.h 306325 2016-09-25 22:57:59Z marcel $
+ */
+
+#ifndef _MKIMG_FORMAT_H_
+#define	_MKIMG_FORMAT_H_
+
+struct mkimg_format {
+	struct mkimg_format *next;
+	const char	*name;
+	const char	*description;
+	int		(*resize)(lba_t);
+	int		(*write)(int);
+};
+
+#define	FORMAT_DEFINE(nm)						\
+static void format_register_##nm(void) __attribute__((constructor));	\
+static void format_register_##nm(void) { format_register(&nm); }
+
+struct mkimg_format *format_iterate(struct mkimg_format *);
+void	format_register(struct mkimg_format *);
+int	format_select(const char *);
+struct mkimg_format *format_selected(void);
+
+int	format_resize(lba_t);
+int	format_write(int);
+
+#endif /* _MKIMG_FORMAT_H_ */
diff --git a/usr.bin/mkimg/gpt.c b/usr.bin/mkimg/gpt.c
new file mode 100644
index 0000000000..d6a5657e4d
--- /dev/null
+++ b/usr.bin/mkimg/gpt.c
@@ -0,0 +1,289 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/gpt.c 319125 2017-05-29 12:51:02Z manu $");
+
+#include <sys/errno.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <gpt.h>
+#include <mbr.h>
+
+#include "endian.h"
+#include "image.h"
+#include "mkimg.h"
+#include "scheme.h"
+
+static mkimg_uuid_t gpt_uuid_efi = GPT_ENT_TYPE_EFI;
+static mkimg_uuid_t gpt_uuid_freebsd = GPT_ENT_TYPE_FREEBSD;
+static mkimg_uuid_t gpt_uuid_freebsd_boot = GPT_ENT_TYPE_FREEBSD_BOOT;
+static mkimg_uuid_t gpt_uuid_freebsd_nandfs = GPT_ENT_TYPE_FREEBSD_NANDFS;
+static mkimg_uuid_t gpt_uuid_freebsd_swap = GPT_ENT_TYPE_FREEBSD_SWAP;
+static mkimg_uuid_t gpt_uuid_freebsd_ufs = GPT_ENT_TYPE_FREEBSD_UFS;
+static mkimg_uuid_t gpt_uuid_freebsd_vinum = GPT_ENT_TYPE_FREEBSD_VINUM;
+static mkimg_uuid_t gpt_uuid_freebsd_zfs = GPT_ENT_TYPE_FREEBSD_ZFS;
+static mkimg_uuid_t gpt_uuid_mbr = GPT_ENT_TYPE_MBR;
+static mkimg_uuid_t gpt_uuid_ms_basic_data = GPT_ENT_TYPE_MS_BASIC_DATA;
+
+static struct mkimg_alias gpt_aliases[] = {
+    {	ALIAS_EFI, ALIAS_PTR2TYPE(&gpt_uuid_efi) },
+    {	ALIAS_FREEBSD, ALIAS_PTR2TYPE(&gpt_uuid_freebsd) },
+    {	ALIAS_FREEBSD_BOOT, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_boot) },
+    {	ALIAS_FREEBSD_NANDFS, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_nandfs) },
+    {	ALIAS_FREEBSD_SWAP, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_swap) },
+    {	ALIAS_FREEBSD_UFS, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_ufs) },
+    {	ALIAS_FREEBSD_VINUM, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_vinum) },
+    {	ALIAS_FREEBSD_ZFS, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_zfs) },
+    {	ALIAS_MBR, ALIAS_PTR2TYPE(&gpt_uuid_mbr) },
+    {	ALIAS_NTFS, ALIAS_PTR2TYPE(&gpt_uuid_ms_basic_data) },
+    {	ALIAS_NONE, 0 }		/* Keep last! */
+};
+
+/* CRC32 code derived from work by Gary S. Brown. */
+static const uint32_t crc32_tab[] = {
+	0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+	0xe963a535, 0x9e6495a3,	0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+	0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+	0xf3b97148, 0x84be41de,	0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+	0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,	0x14015c4f, 0x63066cd9,
+	0xfa0f3d63, 0x8d080df5,	0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+	0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,	0x35b5a8fa, 0x42b2986c,
+	0xdbbbc9d6, 0xacbcf940,	0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+	0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
+	0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+	0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,	0x76dc4190, 0x01db7106,
+	0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+	0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
+	0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+	0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+	0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+	0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
+	0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+	0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
+	0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+	0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
+	0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+	0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
+	0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+	0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+	0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+	0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
+	0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+	0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
+	0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+	0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
+	0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+	0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
+	0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+	0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+	0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+	0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
+	0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+	0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
+	0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+	0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
+	0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+	0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
+};
+
+static uint32_t
+crc32(const void *buf, size_t sz)
+{
+	const uint8_t *p = (const uint8_t *)buf;
+	uint32_t crc = ~0U;
+
+	while (sz--)
+		crc = crc32_tab[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+	return (crc ^ ~0U);
+}
+
+static u_int
+gpt_tblsz(void)
+{
+	u_int ents;
+
+	ents = secsz / sizeof(struct gpt_ent);
+	return ((nparts + ents - 1) / ents);
+}
+
+static lba_t
+gpt_metadata(u_int where, lba_t blk)
+{
+
+	if (where == SCHEME_META_IMG_START || where == SCHEME_META_IMG_END) {
+		blk += gpt_tblsz();
+		blk += (where == SCHEME_META_IMG_START) ? 2 : 1;
+	}
+	return (round_block(blk));
+}
+
+static int
+gpt_write_pmbr(lba_t blks, void *bootcode)
+{
+	u_char *pmbr;
+	uint32_t secs;
+	int error;
+
+	secs = (blks > UINT32_MAX) ? UINT32_MAX : (uint32_t)blks - 1;
+
+	pmbr = malloc(secsz);
+	if (pmbr == NULL)
+		return (errno);
+	if (bootcode != NULL) {
+		memcpy(pmbr, bootcode, DOSPARTOFF);
+		memset(pmbr + DOSPARTOFF, 0, secsz - DOSPARTOFF);
+	} else
+		memset(pmbr, 0, secsz);
+	pmbr[DOSPARTOFF + 2] = 2;
+	pmbr[DOSPARTOFF + 4] = 0xee;
+	pmbr[DOSPARTOFF + 5] = 0xff;
+	pmbr[DOSPARTOFF + 6] = 0xff;
+	pmbr[DOSPARTOFF + 7] = 0xff;
+	le32enc(pmbr + DOSPARTOFF + 8, 1);
+	le32enc(pmbr + DOSPARTOFF + 12, secs);
+	le16enc(pmbr + DOSMAGICOFFSET, DOSMAGIC);
+	error = image_write(0, pmbr, 1);
+	free(pmbr);
+	return (error);
+}
+
+static struct gpt_ent *
+gpt_mktbl(u_int tblsz)
+{
+	mkimg_uuid_t uuid;
+	struct gpt_ent *tbl, *ent;
+	struct part *part;
+	int c, idx;
+
+	tbl = calloc(tblsz, secsz);
+	if (tbl == NULL)
+		return (NULL);
+
+	TAILQ_FOREACH(part, &partlist, link) {
+		ent = tbl + part->index;
+		mkimg_uuid_enc(&ent->ent_type, ALIAS_TYPE2PTR(part->type));
+		mkimg_uuid(&uuid);
+		mkimg_uuid_enc(&ent->ent_uuid, &uuid);
+		le64enc(&ent->ent_lba_start, part->block);
+		le64enc(&ent->ent_lba_end, part->block + part->size - 1);
+		if (part->label != NULL) {
+			idx = 0;
+			while ((c = part->label[idx]) != '\0') {
+				le16enc(ent->ent_name + idx, c);
+				idx++;
+			}
+		}
+	}
+	return (tbl);
+}
+
+static int
+gpt_write_hdr(struct gpt_hdr *hdr, uint64_t self, uint64_t alt, uint64_t tbl)
+{
+	uint32_t crc;
+
+	le64enc(&hdr->hdr_lba_self, self);
+	le64enc(&hdr->hdr_lba_alt, alt);
+	le64enc(&hdr->hdr_lba_table, tbl);
+	hdr->hdr_crc_self = 0;
+	crc = crc32(hdr, offsetof(struct gpt_hdr, padding));
+	le64enc(&hdr->hdr_crc_self, crc);
+	return (image_write(self, hdr, 1));
+}
+
+static int
+gpt_write(lba_t imgsz, void *bootcode)
+{
+	mkimg_uuid_t uuid;
+	struct gpt_ent *tbl;
+	struct gpt_hdr *hdr;
+	uint32_t crc;
+	u_int tblsz;
+	int error;
+
+	/* PMBR */
+	error = gpt_write_pmbr(imgsz, bootcode);
+	if (error)
+		return (error);
+
+	/* GPT table(s) */
+	tblsz = gpt_tblsz();
+	tbl = gpt_mktbl(tblsz);
+	if (tbl == NULL)
+		return (errno);
+	error = image_write(2, tbl, tblsz);
+	if (error)
+		goto out;
+	error = image_write(imgsz - (tblsz + 1), tbl, tblsz);
+	if (error)
+		goto out;
+
+	/* GPT header(s) */
+	hdr = malloc(secsz);
+	if (hdr == NULL) {
+		error = errno;
+		goto out;
+	}
+	memset(hdr, 0, secsz);
+	memcpy(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig));
+	le32enc(&hdr->hdr_revision, GPT_HDR_REVISION);
+	le32enc(&hdr->hdr_size, offsetof(struct gpt_hdr, padding));
+	le64enc(&hdr->hdr_lba_start, 2 + tblsz);
+	le64enc(&hdr->hdr_lba_end, imgsz - tblsz - 2);
+	mkimg_uuid(&uuid);
+	mkimg_uuid_enc(&hdr->hdr_uuid, &uuid);
+	le32enc(&hdr->hdr_entries, nparts);
+	le32enc(&hdr->hdr_entsz, sizeof(struct gpt_ent));
+	crc = crc32(tbl, nparts * sizeof(struct gpt_ent));
+	le32enc(&hdr->hdr_crc_table, crc);
+	error = gpt_write_hdr(hdr, 1, imgsz - 1, 2);
+	if (!error)
+		error = gpt_write_hdr(hdr, imgsz - 1, 1, imgsz - tblsz - 1);
+	free(hdr);
+
+ out:
+	free(tbl);
+	return (error);
+}
+
+static struct mkimg_scheme gpt_scheme = {
+	.name = "gpt",
+	.description = "GUID Partition Table",
+	.aliases = gpt_aliases,
+	.metadata = gpt_metadata,
+	.write = gpt_write,
+	.nparts = 4096,
+	.labellen = 36,
+	.bootcode = 512,
+	.maxsecsz = 4096
+};
+
+SCHEME_DEFINE(gpt_scheme);
diff --git a/usr.bin/mkimg/image.c b/usr.bin/mkimg/image.c
new file mode 100644
index 0000000000..6296c848eb
--- /dev/null
+++ b/usr.bin/mkimg/image.c
@@ -0,0 +1,755 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/image.c 314577 2017-03-03 01:56:55Z sjg $");
+
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <assert.h>
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "image.h"
+#include "mkimg.h"
+
+#ifndef MAP_NOCORE
+#define	MAP_NOCORE	0
+#endif
+#ifndef MAP_NOSYNC
+#define	MAP_NOSYNC	0
+#endif
+
+#ifndef SEEK_DATA
+#define	SEEK_DATA	-1
+#endif
+#ifndef SEEK_HOLE
+#define	SEEK_HOLE	-1
+#endif
+
+struct chunk {
+	TAILQ_ENTRY(chunk) ch_list;
+	size_t	ch_size;		/* Size of chunk in bytes. */
+	lba_t	ch_block;		/* Block address in image. */
+	union {
+		struct {
+			off_t	ofs;	/* Offset in backing file. */
+			int	fd;	/* FD of backing file. */
+		} file;
+		struct {
+			void	*ptr;	/* Pointer to data in memory */
+		} mem;
+	} ch_u;
+	u_int	ch_type;
+#define	CH_TYPE_ZEROES		0	/* Chunk is a gap (no data). */
+#define	CH_TYPE_FILE		1	/* File-backed chunk. */
+#define	CH_TYPE_MEMORY		2	/* Memory-backed chunk */
+};
+
+static TAILQ_HEAD(chunk_head, chunk) image_chunks;
+static u_int image_nchunks;
+
+static char image_swap_file[PATH_MAX];
+static int image_swap_fd = -1;
+static u_int image_swap_pgsz;
+static off_t image_swap_size;
+
+static lba_t image_size;
+
+static int
+is_empty_sector(void *buf)
+{
+	uint64_t *p = buf;
+	size_t n, max;
+
+	assert(((uintptr_t)p & 3) == 0);
+
+	max = secsz / sizeof(uint64_t);
+	for (n = 0; n < max; n++) {
+		if (p[n] != 0UL)
+			return (0);
+	}
+	return (1);
+}
+
+/*
+ * Swap file handlng.
+ */
+
+static off_t
+image_swap_alloc(size_t size)
+{
+	off_t ofs;
+	size_t unit;
+
+	unit = (secsz > image_swap_pgsz) ? secsz : image_swap_pgsz;
+	assert((unit & (unit - 1)) == 0);
+
+	size = (size + unit - 1) & ~(unit - 1);
+
+	ofs = image_swap_size;
+	image_swap_size += size;
+	if (ftruncate(image_swap_fd, image_swap_size) == -1) {
+		image_swap_size = ofs;
+		ofs = -1LL;
+	}
+	return (ofs);
+}
+
+/*
+ * Image chunk handling.
+ */
+
+static struct chunk *
+image_chunk_find(lba_t blk)
+{
+	static struct chunk *last = NULL;
+	struct chunk *ch;
+
+	ch = (last != NULL && last->ch_block <= blk)
+	    ? last : TAILQ_FIRST(&image_chunks);
+	while (ch != NULL) {
+		if (ch->ch_block <= blk &&
+		    (lba_t)(ch->ch_block + (ch->ch_size / secsz)) > blk) {
+			last = ch;
+			break;
+		}
+		ch = TAILQ_NEXT(ch, ch_list);
+	}
+	return (ch);
+}
+
+static size_t
+image_chunk_grow(struct chunk *ch, size_t sz)
+{
+	size_t dsz, newsz;
+
+	newsz = ch->ch_size + sz;
+	if (newsz > ch->ch_size) {
+		ch->ch_size = newsz;
+		return (0);
+	}
+	/* We would overflow -- create new chunk for remainder. */
+	dsz = SIZE_MAX - ch->ch_size;
+	assert(dsz < sz);
+	ch->ch_size = SIZE_MAX;
+	return (sz - dsz);
+}
+
+static struct chunk *
+image_chunk_memory(struct chunk *ch, lba_t blk)
+{
+	struct chunk *new;
+	void *ptr;
+
+	ptr = calloc(1, secsz);
+	if (ptr == NULL)
+		return (NULL);
+
+	if (ch->ch_block < blk) {
+		new = malloc(sizeof(*new));
+		if (new == NULL) {
+			free(ptr);
+			return (NULL);
+		}
+		memcpy(new, ch, sizeof(*new));
+		ch->ch_size = (blk - ch->ch_block) * secsz;
+		new->ch_block = blk;
+		new->ch_size -= ch->ch_size;
+		TAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list);
+		image_nchunks++;
+		ch = new;
+	}
+
+	if (ch->ch_size > secsz) {
+		new = malloc(sizeof(*new));
+		if (new == NULL) {
+			free(ptr);
+			return (NULL);
+		}
+		memcpy(new, ch, sizeof(*new));
+		ch->ch_size = secsz;
+		new->ch_block++;
+		new->ch_size -= secsz;
+		TAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list);
+		image_nchunks++;
+	}
+
+	ch->ch_type = CH_TYPE_MEMORY;
+	ch->ch_u.mem.ptr = ptr;
+	return (ch);
+}
+
+static int
+image_chunk_skipto(lba_t to)
+{
+	struct chunk *ch;
+	lba_t from;
+	size_t sz;
+
+	ch = TAILQ_LAST(&image_chunks, chunk_head);
+	from = (ch != NULL) ? ch->ch_block + (ch->ch_size / secsz) : 0LL;
+
+	assert(from <= to);
+
+	/* Nothing to do? */
+	if (from == to)
+		return (0);
+	/* Avoid bugs due to overflows. */
+	if ((uintmax_t)(to - from) > (uintmax_t)(SIZE_MAX / secsz))
+		return (EFBIG);
+	sz = (to - from) * secsz;
+	if (ch != NULL && ch->ch_type == CH_TYPE_ZEROES) {
+		sz = image_chunk_grow(ch, sz);
+		if (sz == 0)
+			return (0);
+		from = ch->ch_block + (ch->ch_size / secsz);
+	}
+	ch = malloc(sizeof(*ch));
+	if (ch == NULL)
+		return (ENOMEM);
+	memset(ch, 0, sizeof(*ch));
+	ch->ch_block = from;
+	ch->ch_size = sz;
+	ch->ch_type = CH_TYPE_ZEROES;
+	TAILQ_INSERT_TAIL(&image_chunks, ch, ch_list);
+	image_nchunks++;
+	return (0);
+}
+
+static int
+image_chunk_append(lba_t blk, size_t sz, off_t ofs, int fd)
+{
+	struct chunk *ch;
+
+	ch = TAILQ_LAST(&image_chunks, chunk_head);
+	if (ch != NULL && ch->ch_type == CH_TYPE_FILE) {
+		if (fd == ch->ch_u.file.fd &&
+		    blk == (lba_t)(ch->ch_block + (ch->ch_size / secsz)) &&
+		    ofs == (off_t)(ch->ch_u.file.ofs + ch->ch_size)) {
+			sz = image_chunk_grow(ch, sz);
+			if (sz == 0)
+				return (0);
+			blk = ch->ch_block + (ch->ch_size / secsz);
+			ofs = ch->ch_u.file.ofs + ch->ch_size;
+		}
+	}
+	ch = malloc(sizeof(*ch));
+	if (ch == NULL)
+		return (ENOMEM);
+	memset(ch, 0, sizeof(*ch));
+	ch->ch_block = blk;
+	ch->ch_size = sz;
+	ch->ch_type = CH_TYPE_FILE;
+	ch->ch_u.file.ofs = ofs;
+	ch->ch_u.file.fd = fd;
+	TAILQ_INSERT_TAIL(&image_chunks, ch, ch_list);
+	image_nchunks++;
+	return (0);
+}
+
+static int
+image_chunk_copyin(lba_t blk, void *buf, size_t sz, off_t ofs, int fd)
+{
+	uint8_t *p = buf;
+	int error;
+
+	error = 0;
+	sz = (sz + secsz - 1) & ~(secsz - 1);
+	while (!error && sz > 0) {
+		if (is_empty_sector(p))
+			error = image_chunk_skipto(blk + 1);
+		else
+			error = image_chunk_append(blk, secsz, ofs, fd);
+		blk++;
+		p += secsz;
+		sz -= secsz;
+		ofs += secsz;
+	}
+	return (error);
+}
+
+/*
+ * File mapping support.
+ */
+
+static void *
+image_file_map(int fd, off_t ofs, size_t sz, off_t *iofp)
+{
+	void *ptr;
+	size_t unit;
+	int flags, prot;
+	off_t x;
+
+	/* On Linux anyway ofs must also be page aligned */
+	if ((x = (ofs % image_swap_pgsz)) != 0) {
+	    ofs -= x;
+	    sz += x;
+	    *iofp = x;
+	} else
+	    *iofp = 0;
+	unit = (secsz > image_swap_pgsz) ? secsz : image_swap_pgsz;
+	assert((unit & (unit - 1)) == 0);
+
+	flags = MAP_NOCORE | MAP_NOSYNC | MAP_SHARED;
+	/* Allow writing to our swap file only. */
+	prot = PROT_READ | ((fd == image_swap_fd) ? PROT_WRITE : 0);
+	sz = (sz + unit - 1) & ~(unit - 1);
+	ptr = mmap(NULL, sz, prot, flags, fd, ofs);
+	return ((ptr == MAP_FAILED) ? NULL : ptr);
+}
+
+static int
+image_file_unmap(void *buffer, size_t sz)
+{
+	size_t unit;
+
+	unit = (secsz > image_swap_pgsz) ? secsz : image_swap_pgsz;
+	sz = (sz + unit - 1) & ~(unit - 1);
+	if (madvise(buffer, sz, MADV_DONTNEED) != 0)
+		warn("madvise");
+	munmap(buffer, sz);
+	return (0);
+}
+
+/*
+ * Input/source file handling.
+ */
+
+static int
+image_copyin_stream(lba_t blk, int fd, uint64_t *sizep)
+{
+	char *buffer;
+	uint64_t bytesize;
+	off_t swofs;
+	size_t iosz;
+	ssize_t rdsz;
+	int error;
+	off_t iof;
+
+	/*
+	 * This makes sure we're doing I/O in multiples of the page
+	 * size as well as of the sector size. 2MB is the minimum
+	 * by virtue of secsz at least 512 bytes and the page size
+	 * at least 4K bytes.
+	 */
+	iosz = secsz * image_swap_pgsz;
+
+	bytesize = 0;
+	do {
+		swofs = image_swap_alloc(iosz);
+		if (swofs == -1LL)
+			return (errno);
+		buffer = image_file_map(image_swap_fd, swofs, iosz, &iof);
+		if (buffer == NULL)
+			return (errno);
+		rdsz = read(fd, &buffer[iof], iosz);
+		if (rdsz > 0)
+			error = image_chunk_copyin(blk, &buffer[iof], rdsz, swofs,
+			    image_swap_fd);
+		else if (rdsz < 0)
+			error = errno;
+		else
+			error = 0;
+		image_file_unmap(buffer, iosz);
+		/* XXX should we relinguish unused swap space? */
+		if (error)
+			return (error);
+
+		bytesize += rdsz;
+		blk += (rdsz + secsz - 1) / secsz;
+	} while (rdsz > 0);
+
+	if (sizep != NULL)
+		*sizep = bytesize;
+	return (0);
+}
+
+static int
+image_copyin_mapped(lba_t blk, int fd, uint64_t *sizep)
+{
+	off_t cur, data, end, hole, pos, iof;
+	void *mp;
+	char *buf;
+	uint64_t bytesize;
+	size_t iosz, sz;
+	int error;
+
+	/*
+	 * We'd like to know the size of the file and we must
+	 * be able to seek in order to mmap(2). If this isn't
+	 * possible, then treat the file as a stream/pipe.
+	 */
+	end = lseek(fd, 0L, SEEK_END);
+	if (end == -1L)
+		return (image_copyin_stream(blk, fd, sizep));
+
+	/*
+	 * We need the file opened for the duration and our
+	 * caller is going to close the file. Make a dup(2)
+	 * so that control the faith of the descriptor.
+	 */
+	fd = dup(fd);
+	if (fd == -1)
+		return (errno);
+
+	iosz = secsz * image_swap_pgsz;
+
+	bytesize = 0;
+	cur = pos = 0;
+	error = 0;
+	while (!error && cur < end) {
+		hole = lseek(fd, cur, SEEK_HOLE);
+		if (hole == -1)
+			hole = end;
+		data = lseek(fd, cur, SEEK_DATA);
+		if (data == -1)
+			data = end;
+
+		/*
+		 * Treat the entire file as data if sparse files
+		 * are not supported by the underlying file system.
+		 */
+		if (hole == end && data == end)
+			data = cur;
+
+		if (cur == hole && data > hole) {
+			hole = pos;
+			pos = data & ~((uint64_t)secsz - 1);
+
+			blk += (pos - hole) / secsz;
+			error = image_chunk_skipto(blk);
+
+			bytesize += pos - hole;
+			cur = data;
+		} else if (cur == data && hole > data) {
+			data = pos;
+			pos = (hole + secsz - 1) & ~((uint64_t)secsz - 1);
+
+			while (data < pos) {
+				sz = (pos - data > (off_t)iosz)
+				    ? iosz : (size_t)(pos - data);
+
+				buf = mp = image_file_map(fd, data, sz, &iof);
+				if (mp != NULL) {
+					buf += iof;
+					error = image_chunk_copyin(blk, buf,
+					    sz, data, fd);
+					image_file_unmap(mp, sz);
+				} else
+					error = errno;
+
+				blk += sz / secsz;
+				bytesize += sz;
+				data += sz;
+			}
+			cur = hole;
+		} else {
+			/*
+			 * I don't know what this means or whether it
+			 * can happen at all...
+			 */
+			assert(0);
+		}
+	}
+	if (error)
+		close(fd);
+	if (!error && sizep != NULL)
+		*sizep = bytesize;
+	return (error);
+}
+
+int
+image_copyin(lba_t blk, int fd, uint64_t *sizep)
+{
+	struct stat sb;
+	int error;
+
+	error = image_chunk_skipto(blk);
+	if (!error) {
+		if (fstat(fd, &sb) == -1 || !S_ISREG(sb.st_mode))
+			error = image_copyin_stream(blk, fd, sizep);
+		else
+			error = image_copyin_mapped(blk, fd, sizep);
+	}
+	return (error);
+}
+
+/*
+ * Output/sink file handling.
+ */
+
+int
+image_copyout(int fd)
+{
+	int error;
+
+	error = image_copyout_region(fd, 0, image_size);
+	if (!error)
+		error = image_copyout_done(fd);
+	return (error);
+}
+
+int
+image_copyout_done(int fd)
+{
+	off_t ofs;
+	int error;
+
+	ofs = lseek(fd, 0L, SEEK_CUR);
+	if (ofs == -1)
+		return (0);
+	error = (ftruncate(fd, ofs) == -1) ? errno : 0;
+	return (error);
+}
+
+static int
+image_copyout_memory(int fd, size_t size, void *ptr)
+{
+
+	if (write(fd, ptr, size) == -1)
+		return (errno);
+	return (0);
+}
+
+int
+image_copyout_zeroes(int fd, size_t count)
+{
+	static uint8_t *zeroes = NULL;
+	size_t sz;
+	int error;
+
+	if (lseek(fd, (off_t)count, SEEK_CUR) != -1)
+		return (0);
+
+	/*
+	 * If we can't seek, we must write.
+	 */
+
+	if (zeroes == NULL) {
+		zeroes = calloc(1, secsz);
+		if (zeroes == NULL)
+			return (ENOMEM);
+	}
+
+	while (count > 0) {
+		sz = (count > secsz) ? secsz : count;
+		error = image_copyout_memory(fd, sz, zeroes);
+		if (error)
+			return (error);
+		count -= sz;
+	}
+	return (0);
+}
+
+static int
+image_copyout_file(int fd, size_t size, int ifd, off_t iofs)
+{
+	void *mp;
+	char *buf;
+	size_t iosz, sz;
+	int error;
+	off_t iof;
+
+	iosz = secsz * image_swap_pgsz;
+
+	while (size > 0) {
+		sz = (size > iosz) ? iosz : size;
+		buf = mp = image_file_map(ifd, iofs, sz, &iof);
+		if (buf == NULL)
+			return (errno);
+		buf += iof;
+		error = image_copyout_memory(fd, sz, buf);
+		image_file_unmap(mp, sz);
+		if (error)
+			return (error);
+		size -= sz;
+		iofs += sz;
+	}
+	return (0);
+}
+
+int
+image_copyout_region(int fd, lba_t blk, lba_t size)
+{
+	struct chunk *ch;
+	size_t ofs, sz;
+	int error;
+
+	size *= secsz;
+
+	error = 0;
+	while (!error && size > 0) {
+		ch = image_chunk_find(blk);
+		if (ch == NULL) {
+			error = EINVAL;
+			break;
+		}
+		ofs = (blk - ch->ch_block) * secsz;
+		sz = ch->ch_size - ofs;
+		sz = ((lba_t)sz < size) ? sz : (size_t)size;
+		switch (ch->ch_type) {
+		case CH_TYPE_ZEROES:
+			error = image_copyout_zeroes(fd, sz);
+			break;
+		case CH_TYPE_FILE:
+			error = image_copyout_file(fd, sz, ch->ch_u.file.fd,
+			    ch->ch_u.file.ofs + ofs);
+			break;
+		case CH_TYPE_MEMORY:
+			error = image_copyout_memory(fd, sz, ch->ch_u.mem.ptr);
+			break;
+		default:
+			assert(0);
+		}
+		size -= sz;
+		blk += sz / secsz;
+	}
+	return (error);
+}
+
+int
+image_data(lba_t blk, lba_t size)
+{
+	struct chunk *ch;
+	lba_t lim;
+
+	while (1) {
+		ch = image_chunk_find(blk);
+		if (ch == NULL)
+			return (0);
+		if (ch->ch_type != CH_TYPE_ZEROES)
+			return (1);
+		lim = ch->ch_block + (ch->ch_size / secsz);
+		if (lim >= blk + size)
+			return (0);
+		size -= lim - blk;
+		blk = lim;
+	}
+	/*NOTREACHED*/
+}
+
+lba_t
+image_get_size(void)
+{
+
+	return (image_size);
+}
+
+int
+image_set_size(lba_t blk)
+{
+	int error;
+
+	error = image_chunk_skipto(blk);
+	if (!error)
+		image_size = blk;
+	return (error);
+}
+
+int
+image_write(lba_t blk, void *buf, ssize_t len)
+{
+	struct chunk *ch;
+
+	while (len > 0) {
+		if (!is_empty_sector(buf)) {
+			ch = image_chunk_find(blk);
+			if (ch == NULL)
+				return (ENXIO);
+			/* We may not be able to write to files. */
+			if (ch->ch_type == CH_TYPE_FILE)
+				return (EINVAL);
+			if (ch->ch_type == CH_TYPE_ZEROES) {
+				ch = image_chunk_memory(ch, blk);
+				if (ch == NULL)
+					return (ENOMEM);
+			}
+			assert(ch->ch_type == CH_TYPE_MEMORY);
+			memcpy(ch->ch_u.mem.ptr, buf, secsz);
+		}
+		blk++;
+		buf = (char *)buf + secsz;
+		len--;
+	}
+	return (0);
+}
+
+static void
+image_cleanup(void)
+{
+	struct chunk *ch;
+
+	while ((ch = TAILQ_FIRST(&image_chunks)) != NULL) {
+		switch (ch->ch_type) {
+		case CH_TYPE_FILE:
+			/* We may be closing the same file multiple times. */
+			if (ch->ch_u.file.fd != -1)
+				close(ch->ch_u.file.fd);
+			break;
+		case CH_TYPE_MEMORY:
+			free(ch->ch_u.mem.ptr);
+			break;
+		default:
+			break;
+		}
+		TAILQ_REMOVE(&image_chunks, ch, ch_list);
+		free(ch);
+	}
+	if (image_swap_fd != -1)
+		close(image_swap_fd);
+	unlink(image_swap_file);
+}
+
+int
+image_init(void)
+{
+	const char *tmpdir;
+
+	TAILQ_INIT(&image_chunks);
+	image_nchunks = 0;
+
+	image_swap_size = 0;
+	image_swap_pgsz = getpagesize();
+
+	if (atexit(image_cleanup) == -1)
+		return (errno);
+	if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
+		tmpdir = _PATH_TMP;
+	snprintf(image_swap_file, sizeof(image_swap_file), "%s/mkimg-XXXXXX",
+	    tmpdir);
+	image_swap_fd = mkstemp(image_swap_file);
+	if (image_swap_fd == -1)
+		return (errno);
+	return (0);
+}
diff --git a/usr.bin/mkimg/image.h b/usr.bin/mkimg/image.h
new file mode 100644
index 0000000000..eda6db89ad
--- /dev/null
+++ b/usr.bin/mkimg/image.h
@@ -0,0 +1,45 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: head/usr.bin/mkimg/image.h 286215 2015-08-03 01:24:48Z marcel $
+ */
+
+#ifndef _MKIMG_IMAGE_H_
+#define	_MKIMG_IMAGE_H_
+
+typedef int64_t lba_t;
+
+int image_copyin(lba_t blk, int fd, uint64_t *sizep);
+int image_copyout(int fd);
+int image_copyout_done(int fd);
+int image_copyout_region(int fd, lba_t blk, lba_t size);
+int image_copyout_zeroes(int fd, size_t count);
+int image_data(lba_t blk, lba_t size);
+lba_t image_get_size(void);
+int image_init(void);
+int image_set_size(lba_t blk);
+int image_write(lba_t blk, void *buf, ssize_t len);
+
+#endif /* _MKIMG_IMAGE_H_ */
diff --git a/usr.bin/mkimg/mbr.c b/usr.bin/mkimg/mbr.c
new file mode 100644
index 0000000000..584fd0f389
--- /dev/null
+++ b/usr.bin/mkimg/mbr.c
@@ -0,0 +1,125 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/mbr.c 307550 2016-10-18 05:43:12Z imp $");
+
+#include <sys/errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <mbr.h>
+
+#include "endian.h"
+#include "image.h"
+#include "mkimg.h"
+#include "scheme.h"
+
+static struct mkimg_alias mbr_aliases[] = {
+    {	ALIAS_EBR, ALIAS_INT2TYPE(DOSPTYP_EXT) },
+    {	ALIAS_EFI, ALIAS_INT2TYPE(DOSPTYP_EFI) },
+    {	ALIAS_FAT16B, ALIAS_INT2TYPE(DOSPTYP_FAT16) },
+    {	ALIAS_FAT32, ALIAS_INT2TYPE(DOSPTYP_FAT32) },
+    {	ALIAS_FREEBSD, ALIAS_INT2TYPE(DOSPTYP_386BSD) },
+    {	ALIAS_NTFS, ALIAS_INT2TYPE(DOSPTYP_NTFS) },
+    {	ALIAS_PPCBOOT, ALIAS_INT2TYPE(DOSPTYP_PPCBOOT) },
+    {	ALIAS_NONE, 0 }		/* Keep last! */
+};
+
+static lba_t
+mbr_metadata(u_int where, lba_t blk)
+{
+
+	blk += (where == SCHEME_META_IMG_START) ? 1 : 0;
+	return (round_track(blk));
+}
+
+static void
+mbr_chs(u_char *cylp, u_char *hdp, u_char *secp, lba_t lba)
+{
+	u_int cyl, hd, sec;
+
+	mkimg_chs(lba, 1023, &cyl, &hd, &sec);
+	*cylp = cyl;
+	*hdp = hd;
+	*secp = (sec & 0x3f) | ((cyl >> 2) & 0xc0);
+}
+
+static int
+mbr_write(lba_t imgsz __unused, void *bootcode)
+{
+	u_char *mbr;
+	struct dos_partition *dpbase, *dp;
+	struct part *part;
+	lba_t size;
+	int error;
+
+	mbr = malloc(secsz);
+	if (mbr == NULL)
+		return (ENOMEM);
+	if (bootcode != NULL) {
+		memcpy(mbr, bootcode, DOSPARTOFF);
+		memset(mbr + DOSPARTOFF, 0, secsz - DOSPARTOFF);
+	} else
+		memset(mbr, 0, secsz);
+	le16enc(mbr + DOSMAGICOFFSET, DOSMAGIC);
+	dpbase = (void *)(mbr + DOSPARTOFF);
+	TAILQ_FOREACH(part, &partlist, link) {
+		size = round_track(part->size);
+		dp = dpbase + part->index;
+		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);
+		mbr_chs(&dp->dp_ecyl, &dp->dp_ehd, &dp->dp_esect,
+		    part->block + size - 1);
+		le32enc(&dp->dp_start, part->block);
+		le32enc(&dp->dp_size, size);
+	}
+	error = image_write(0, mbr, 1);
+	free(mbr);
+	return (error);
+}
+
+static struct mkimg_scheme mbr_scheme = {
+	.name = "mbr",
+	.description = "Master Boot Record",
+	.aliases = mbr_aliases,
+	.metadata = mbr_metadata,
+	.write = mbr_write,
+	.bootcode = 512,
+	.nparts = NDOSPART,
+	.maxsecsz = 4096
+};
+
+SCHEME_DEFINE(mbr_scheme);
diff --git a/usr.bin/mkimg/mkimg.1 b/usr.bin/mkimg/mkimg.1
new file mode 100644
index 0000000000..9cacf2c7e0
--- /dev/null
+++ b/usr.bin/mkimg/mkimg.1
@@ -0,0 +1,366 @@
+.\" Copyright (c) 2013, 2014 Juniper Networks, Inc.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\"
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD: head/usr.bin/mkimg/mkimg.1 318137 2017-05-10 09:36:34Z manu $
+.\"
+.Dd April 26, 2017
+.Dt MKIMG 1
+.Os
+.Sh NAME
+.Nm mkimg
+.Nd "utility to make disk images"
+.Sh SYNOPSIS
+.Nm
+.Op Fl H Ar heads
+.Op Fl P Ar blksz
+.Op Fl S Ar secsz
+.Op Fl T Ar tracksz
+.Op Fl b Ar bootcode
+.Op Fl c Ar min_capacity
+.Op Fl C Ar max_capacity
+.Op Fl -capacity 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 ...
+.Nm
+.Ar --formats | --schemes | --version
+.Sh DESCRIPTION
+The
+.Nm
+utility creates a disk image from the raw partition contents specified with
+the
+.Ar partition
+argument(s) and using the partitioning scheme specified with the
+.Ar scheme
+argument.
+The disk image is written to
+.Ar stdout
+by default or the file specified with the
+.Ar outfile
+argument.
+The image file is a raw disk image by default, but the format of the
+image file can be specified with the
+.Ar format
+argument.
+.Pp
+The disk image can be made bootable by specifying the scheme-specific boot
+block contents with the
+.Ar bootcode
+argument and,
+depending on the scheme,
+with a boot partition.
+The contents of such a boot partition is provided like any other partition
+and the
+.Nm
+utility does not treat it any differently from other partitions.
+.Pp
+Some partitioning schemes need a disk geometry and for those the
+.Nm
+utility accepts the
+.Ar tracksz
+and
+.Ar heads
+arguments, specifying the number of sectors per track and the number of
+heads per cylinder (resp.)
+.Pp
+Both the logical and physical sector size can be specified and for that the
+.Nm
+utility
+accepts the
+.Ar secsz
+and
+.Ar blksz
+arguments.
+The
+.Ar secsz
+argument is used to specify the logical sector size.
+This is the sector size reported by a disk when queried for its capacity.
+Modern disks use a larger sector size internally,
+referred to as block size by the
+.Nm
+utility and this can be specified by the
+.Ar blksz
+argument.
+The
+.Nm
+utility will use the (physical) block size to determine the start of
+partitions and to round the size of the disk image.
+.Pp
+The
+.Fl c
+option can be used to specify a minimal capacity for the disk image.
+Use this option without the
+.Fl s
+and
+.Fl p
+options to create an empty disk image with the given (virtual) size.
+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 for all the partitions is larger than the
+given capacity, then the disk image will be larger than the capacity
+given.
+.Pp
+The
+.Fl C
+option specifies a maximum capacity for the disk image.
+If the combined sizes of the given partitions exceed the size given with
+.Fl C ,
+image creation fails.
+.Pp
+The
+.Fl -capacity
+option is a shorthand to specify the minimum and maximum capacity at the
+same time.
+.Pp
+The
+.Fl v
+option increases the level of output that the
+.Nm
+utility prints.
+.Pp
+The
+.Fl y
+option is used for testing purposes only and is not to be used in production.
+When present, the
+.Nm
+utility will generate predictable values for Universally Unique Identifiers
+(UUIDs) and time stamps so that consecutive runs of the
+.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.
+Options in this set should be given by themselves because the
+.Nm
+utility exits immediately after providing the requested information.
+The version of the
+.Nm
+utility is printed when the
+.Ar --version
+option is given.
+The list of supported output formats is printed when the
+.Ar --formats
+option is given and the list of supported partitioning schemes is printed
+when the
+.Ar --schemes
+option is given.
+Both the format and scheme lists a space-separated lists for easy handling
+in scripts.
+.Pp
+For a more descriptive list of supported partitioning schemes or supported
+output format, or for a detailed description of how to specify partitions,
+run the
+.Nm
+utility without any arguments.
+This will print a usage message with all the necessary details.
+.Sh DISK FORMATS
+The
+.Nm
+utility supports a number of output file formats.
+A short description of these is given below.
+.Ss QCOW and QCOW2
+QCOW stands for "QEMU Copy On Write".
+It's a sparse file format akin to VHD and VMDK and QCOW represents the
+first version.
+QCOW2 represents version 2 of the file format.
+Version 2 is not backward compatible with version 1 and adds support for
+snapshots among other things.
+The QCOW file formats are natively supported by QEMU and Xen.
+To write QCOW, specify
+.Fl f Ar qcow
+on the command line.
+To write version 2 QCOW, specify
+.Fl f Ar qcow2
+on the command line.
+The preferred file extension is ".qcow" and ".qcow2" for QCOW and QCOW2
+(resp.), but ".qcow" is sometimes used for version 2 files as well.
+.Ss RAW file format
+This file format is a sector by sector representation of an actual disk.
+There is no extra information that describes or relates to the format
+itself. The size of the file is the size of the (virtual) disk.
+This file format is suitable for being copyied onto a disk with utilities
+like
+.Nm dd .
+To write a raw disk file, either omit the
+.Fl f
+option, or specify
+.Fl f Ar raw
+on the command line.
+The preferred file extension is one of ".img" or ".raw", but there's no
+real convention for it.
+.Ss Dynamic VHD and Fixed VHD
+Microsoft's "Virtual Hard Disk" file formats.
+The dynamic format is a sparse format akin to QCOW and VMDK.
+The fixed format is effectively a raw format with a footer appended to the
+file and as such it's often indistinguishable from the raw format.
+The fixed file format has been added to support Microsoft's Azure platform
+and due to inconsistencies in interpretation of the footer is not compatible
+with utilities like
+.Nm qemu
+when it is specifically instructed to interpreted the file as a VHD file.
+By default
+.Nm qemu
+will treat the file as a raw disk file, which mostly works fine.
+To have
+.Nm
+create a dynamic VHD file, specify
+.Fl f Ar vhd
+on the command line.
+To create a fixed VHD file for use by Azure, specify
+.Fl f Ar vhdf
+on the command line.
+The preferred file extension is ".vhd".
+.Ss VMDK
+VMware's "Virtual Machine Disk" file format.
+It's a sparse file format akin to QCOW and VHD and supported by many
+virtualization solutions.
+To create a VMDK file, specify
+.Fl f Ar vmdk
+on the command line.
+The preferred file extension is ".vmdk".
+.Pp
+Not all virtualization solutions support all file formats, but often those
+virtualization environments have utilities to convert from one format to
+another.
+Note however that conversion may require that the virtual disk size is
+changed to match the constraints of the output format and this may invalidate
+the contents of the disk image.
+For example, the GUID Partition Table (GPT) scheme has a header in the last
+sector on the disk.
+When changing the disk size, the GPT must be changed so that the last header
+is moved accordingly.
+This is typically not part of the conversion process.
+If possible, use an output format specifically for the environment in which
+the file is intended to be used.
+.Sh ENVIRONMENT
+.Bl -tag -width "TMPDIR" -compact
+.It Ev TMPDIR
+Directory to put temporary files in; default is
+.Pa /tmp .
+.El
+.Sh EXAMPLES
+To create a bootable disk image that is partitioned using the GPT scheme and
+containing a root file system that was previously created using
+.Xr makefs 8
+and also containing a swap partition, run the
+.Nm
+utility as follows:
+.Dl % mkimg -s gpt -b /boot/pmbr -p freebsd-boot:=/boot/gptboot \
+-p freebsd-ufs:=root-file-system.ufs -p freebsd-swap::1G \
+-o gpt.img
+.Pp
+The command line given above results in a raw image file.
+This is because no output format was given.
+To create a VMDK image for example, add the
+.Fl f Ar vmdk
+argument to the
+.Nm
+utility and name the output file accordingly.
+.Pp
+A nested partitioning scheme is created by running the
+.Nm
+utility twice.
+The output of the first will be fed as the contents of a partition to the
+second.
+This can be done using a temporary file, like so:
+.Dl % mkimg -s bsd -b /boot/boot -p freebsd-ufs:=root-file-system.ufs \
+-p freebsd-swap::1G -o /tmp/bsd.img
+.Dl % mkimg -s mbr -b /boot/mbr -p freebsd:=/tmp/bsd.img -o mbr-bsd.img
+.Pp
+Alternatively, the
+.Nm
+utility can be run in a cascaded fashion, whereby the output of the
+first is fed directly into the second.
+To do this, run the
+.Nm
+utility as follows:
+.Dl % mkimg -s mbr -b /boot/mbr -p freebsd:-'mkimg -s bsd -b /boot/boot \
+-p freebsd-ufs:=root-file-system.ufs -p freebsd-swap::1G' -o mbr-bsd.img
+.Pp
+To accommodate the need to have partitions named or numbered in a certain
+way, the
+.Nm
+utility allows for the specification of empty partitions.
+For example, to create an image that is compatible with partition layouts
+found in
+.Pa /etc/disktab ,
+the 'd' partition often needs to be skipped.
+This is accomplished by inserting an unused partition after the first 2
+partition specifications.
+It is worth noting at this time that the BSD scheme will automatically
+skip the 'c' partition by virtue of it referring to the entire disk.
+To create an image that is compatible with the qp120at disk, use the
+.Nm
+utility as follows:
+.Dl % mkimg -s bsd -b /boot/boot -p freebsd-ufs:=root-file-system.ufs \
+-p freebsd-swap::20M -p- -p- -p- -p- -p freebsd-ufs:=usr-file-system.ufs \
+-o bsd.img
+.Pp
+For partitioning schemes that feature partition labels, the
+.Nm
+utility supports assigning labels to the partitions specified.
+In the following example the file system partition is labeled as 'backup':
+.Dl % mkimg -s gpt -p freebsd-ufs/backup:=file-system.ufs -o gpt.img
+.Sh SEE ALSO
+.Xr dd 1 ,
+.Xr gpart 8 ,
+.Xr makefs 8 ,
+.Xr mdconfig 8 ,
+.Xr newfs 8
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Fx 10.1 .
+.Sh AUTHORS
+The
+.Nm
+utility and manpage were written by
+.An Marcel Moolenaar Aq Mt marcel@FreeBSD.org .
diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c
new file mode 100644
index 0000000000..5cf46e5fe1
--- /dev/null
+++ b/usr.bin/mkimg/mkimg.c
@@ -0,0 +1,734 @@
+/*-
+ * Copyright (c) 2013,2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/mkimg.c 332440 2018-04-12 17:16:13Z benno $");
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <err.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <libutil.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+#include "image.h"
+#include "format.h"
+#include "mkimg.h"
+#include "scheme.h"
+
+#define	LONGOPT_FORMATS		0x01000001
+#define	LONGOPT_SCHEMES		0x01000002
+#define	LONGOPT_VERSION		0x01000003
+#define	LONGOPT_CAPACITY	0x01000004
+
+static struct option longopts[] = {
+	{ "formats", no_argument, NULL, LONGOPT_FORMATS },
+	{ "schemes", no_argument, NULL, LONGOPT_SCHEMES },
+	{ "version", no_argument, NULL, LONGOPT_VERSION },
+	{ "capacity", required_argument, NULL, LONGOPT_CAPACITY },
+	{ NULL, 0, NULL, 0 }
+};
+
+static uint64_t min_capacity = 0;
+static uint64_t max_capacity = 0;
+
+struct partlisthead partlist = TAILQ_HEAD_INITIALIZER(partlist);
+u_int nparts = 0;
+
+u_int unit_testing;
+u_int verbose;
+
+u_int ncyls = 0;
+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)
+{
+	struct mkimg_format *f;
+	const char *sep;
+
+	if (usage) {
+		fprintf(stderr, "    formats:\n");
+		f = NULL;
+		while ((f = format_iterate(f)) != NULL) {
+			fprintf(stderr, "\t%s\t-  %s\n", f->name,
+			    f->description);
+		}
+	} else {
+		sep = "";
+		f = NULL;
+		while ((f = format_iterate(f)) != NULL) {
+			printf("%s%s", sep, f->name);
+			sep = " ";
+		}
+		putchar('\n');
+	}
+}
+
+static void
+print_schemes(int usage)
+{
+	struct mkimg_scheme *s;
+	const char *sep;
+
+	if (usage) {
+		fprintf(stderr, "    schemes:\n");
+		s = NULL;
+		while ((s = scheme_iterate(s)) != NULL) {
+			fprintf(stderr, "\t%s\t-  %s\n", s->name,
+			    s->description);
+		}
+	} else {
+		sep = "";
+		s = NULL;
+		while ((s = scheme_iterate(s)) != NULL) {
+			printf("%s%s", sep, s->name);
+			sep = " ";
+		}
+		putchar('\n');
+	}
+}
+
+static void
+print_version(void)
+{
+	u_int width;
+
+#ifdef __LP64__
+	width = 64;
+#else
+	width = 32;
+#endif
+	printf("mkimg %u (%u-bit)\n", MKIMG_VERSION, width);
+}
+
+static void
+usage(const char *why)
+{
+
+	warnx("error: %s", why);
+	fputc('\n', stderr);
+	fprintf(stderr, "usage: %s <options>\n", getprogname());
+
+	fprintf(stderr, "    options:\n");
+	fprintf(stderr, "\t--formats\t-  list image formats\n");
+	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-  minimum capacity (in bytes) of the disk\n");
+	fprintf(stderr, "\t-C <num>\t-  maximum capacity (in bytes) of the disk\n");
+	fprintf(stderr, "\t-f <format>\n");
+	fprintf(stderr, "\t-o <file>\t-  file to write image into\n");
+	fprintf(stderr, "\t-p <partition>\n");
+	fprintf(stderr, "\t-s <scheme>\n");
+	fprintf(stderr, "\t-v\t\t-  increase verbosity\n");
+	fprintf(stderr, "\t-y\t\t-  [developers] enable unit test\n");
+	fprintf(stderr, "\t-H <num>\t-  number of heads to simulate\n");
+	fprintf(stderr, "\t-P <num>\t-  physical sector size\n");
+	fprintf(stderr, "\t-S <num>\t-  logical sector size\n");
+	fprintf(stderr, "\t-T <num>\t-  number of tracks to simulate\n");
+	fputc('\n', stderr);
+	print_formats(1);
+	fputc('\n', stderr);
+	print_schemes(1);
+	fputc('\n', stderr);
+	fprintf(stderr, "    partition specification:\n");
+	fprintf(stderr, "\t<t>[/<l>]::<size>[:[+]<offset>]\t-  "
+	    "empty partition of given size and\n\t\t\t\t\t"
+	    "   optional relative or absolute offset\n");
+	fprintf(stderr, "\t<t>[/<l>]:=<file>\t\t-  partition content and size "
+	    "are\n\t\t\t\t\t   determined by the named file\n");
+	fprintf(stderr, "\t<t>[/<l>]:-<cmd>\t\t-  partition content and size "
+	    "are taken\n\t\t\t\t\t   from the output of the command to run\n");
+	fprintf(stderr, "\t-\t\t\t\t-  unused partition entry\n");
+	fprintf(stderr, "\t    where:\n");
+	fprintf(stderr, "\t\t<t>\t-  scheme neutral partition type\n");
+	fprintf(stderr, "\t\t<l>\t-  optional scheme-dependent partition "
+	    "label\n");
+
+	exit(EX_USAGE);
+}
+
+static int
+parse_uint32(uint32_t *valp, uint32_t min, uint32_t max, const char *arg)
+{
+	uint64_t val;
+
+	if (dehumanize_number(arg, &val) == -1)
+		return (errno);
+	if (val > UINT_MAX || val < (uint64_t)min || val > (uint64_t)max)
+		return (EINVAL);
+	*valp = (uint32_t)val;
+	return (0);
+}
+
+static int
+parse_uint64(uint64_t *valp, uint64_t min, uint64_t max, const char *arg)
+{
+	uint64_t val;
+
+	if (dehumanize_number(arg, &val) == -1)
+		return (errno);
+	if (val < min || val > max)
+		return (EINVAL);
+	*valp = val;
+	return (0);
+}
+
+static int
+pwr_of_two(u_int nr)
+{
+
+	return (((nr & (nr - 1)) == 0) ? 1 : 0);
+}
+
+/*
+ * A partition specification has the following format:
+ *	<type> ':' <kind> <contents>
+ * where:
+ *	type	  the partition type alias
+ *	kind	  the interpretation of the contents specification
+ *		  ':'   contents holds the size of an empty partition
+ *		  '='   contents holds the name of a file to read
+ *		  '-'   contents holds a command to run; the output of
+ *			which is the contents of the partition.
+ *	contents  the specification of a partition's contents
+ *
+ * A specification that is a single dash indicates an unused partition
+ * entry.
+ */
+static int
+parse_part(const char *spec)
+{
+	struct part *part;
+	char *sep;
+	size_t len;
+	int error;
+
+	if (strcmp(spec, "-") == 0) {
+		nparts++;
+		return (0);
+	}
+
+	part = calloc(1, sizeof(struct part));
+	if (part == NULL)
+		return (ENOMEM);
+
+	sep = strchr(spec, ':');
+	if (sep == NULL) {
+		error = EINVAL;
+		goto errout;
+	}
+	len = sep - spec + 1;
+	if (len < 2) {
+		error = EINVAL;
+		goto errout;
+	}
+	part->alias = malloc(len);
+	if (part->alias == NULL) {
+		error = ENOMEM;
+		goto errout;
+	}
+	strlcpy(part->alias, spec, len);
+	spec = sep + 1;
+
+	switch (*spec) {
+	case ':':
+		part->kind = PART_KIND_SIZE;
+		break;
+	case '=':
+		part->kind = PART_KIND_FILE;
+		break;
+	case '-':
+		part->kind = PART_KIND_PIPE;
+		break;
+	default:
+		error = EINVAL;
+		goto errout;
+	}
+	spec++;
+
+	part->contents = strdup(spec);
+	if (part->contents == NULL) {
+		error = ENOMEM;
+		goto errout;
+	}
+
+	spec = part->alias;
+	sep = strchr(spec, '/');
+	if (sep != NULL) {
+		*sep++ = '\0';
+		if (strlen(part->alias) == 0 || strlen(sep) == 0) {
+			error = EINVAL;
+			goto errout;
+		}
+		part->label = strdup(sep);
+		if (part->label == NULL) {
+			error = ENOMEM;
+			goto errout;
+		}
+	}
+
+	part->index = nparts;
+	TAILQ_INSERT_TAIL(&partlist, part, link);
+	nparts++;
+	return (0);
+
+ errout:
+	if (part->alias != NULL)
+		free(part->alias);
+	free(part);
+	return (error);
+}
+
+#if defined(SPARSE_WRITE)
+ssize_t
+sparse_write(int fd, const void *ptr, size_t sz)
+{
+	const char *buf, *p;
+	off_t ofs;
+	size_t len;
+	ssize_t wr, wrsz;
+
+	buf = ptr;
+	wrsz = 0;
+	p = memchr(buf, 0, sz);
+	while (sz > 0) {
+		len = (p != NULL) ? (size_t)(p - buf) : sz;
+		if (len > 0) {
+			len = (len + secsz - 1) & ~(secsz - 1);
+			if (len > sz)
+				len = sz;
+			wr = write(fd, buf, len);
+			if (wr < 0)
+				return (-1);
+		} else {
+			while (len < sz && *p++ == '\0')
+				len++;
+			if (len < sz)
+				len &= ~(secsz - 1);
+			if (len == 0)
+				continue;
+			ofs = lseek(fd, len, SEEK_CUR);
+			if (ofs < 0)
+				return (-1);
+			wr = len;
+		}
+		buf += wr;
+		sz -= wr;
+		wrsz += wr;
+		p = memchr(buf, 0, sz);
+	}
+	return (wrsz);
+}
+#endif /* SPARSE_WRITE */
+
+void
+mkimg_chs(lba_t lba, u_int maxcyl, u_int *cylp, u_int *hdp, u_int *secp)
+{
+	u_int hd, sec;
+
+	*cylp = *hdp = *secp = ~0U;
+	if (nsecs == 1 || nheads == 1)
+		return;
+
+	sec = lba % nsecs + 1;
+	lba /= nsecs;
+	hd = lba % nheads;
+	lba /= nheads;
+	if (lba > maxcyl)
+		return;
+
+	*cylp = lba;
+	*hdp = hd;
+	*secp = sec;
+}
+
+static int
+capacity_resize(lba_t end)
+{
+	lba_t min_capsz, max_capsz;
+
+	min_capsz = (min_capacity + secsz - 1) / secsz;
+	max_capsz = (max_capacity + secsz - 1) / secsz;
+
+	if (max_capsz != 0 && end > max_capsz)
+		return (ENOSPC);
+	if (end >= min_capsz)
+		return (0);
+
+	return (image_set_size(min_capsz));
+}
+
+static void
+mkimg_validate(void)
+{
+	struct part *part, *part2;
+	lba_t start, end, start2, end2;
+	int i, j;
+
+	i = 0;
+
+	TAILQ_FOREACH(part, &partlist, link) {
+		start = part->block;
+		end = part->block + part->size;
+		j = i + 1;
+		part2 = TAILQ_NEXT(part, link);
+		if (part2 == NULL)
+			break;
+
+		TAILQ_FOREACH_FROM(part2, &partlist, link) {
+			start2 = part2->block;
+			end2 = part2->block + part2->size;
+
+			if ((start >= start2 && start < end2) ||
+			    (end > start2 && end <= end2)) {
+				errx(1, "partition %d overlaps partition %d",
+				    i, j);
+			}
+
+			j++;
+		}
+
+		i++;
+	}
+}
+
+static void
+mkimg(void)
+{
+	FILE *fp;
+	struct part *part;
+	lba_t block, blkoffset;
+	off_t bytesize, byteoffset;
+	char *size, *offset;
+	bool abs_offset;
+	int error, fd;
+
+	/* First check partition information */
+	TAILQ_FOREACH(part, &partlist, link) {
+		error = scheme_check_part(part);
+		if (error)
+			errc(EX_DATAERR, error, "partition %d", part->index+1);
+	}
+
+	block = scheme_metadata(SCHEME_META_IMG_START, 0);
+	abs_offset = false;
+	TAILQ_FOREACH(part, &partlist, link) {
+		byteoffset = blkoffset = 0;
+		abs_offset = false;
+
+		/* Look for an offset. Set size too if we can. */
+		switch (part->kind) {
+		case PART_KIND_SIZE:
+			offset = part->contents;
+			size = strsep(&offset, ":");
+			if (dehumanize_number(size, &bytesize) == -1)
+				error = errno;
+			if (offset != NULL) {
+				if (*offset != '+')
+					abs_offset = true;
+				else
+					offset++;
+				if (dehumanize_number(offset, &byteoffset) == -1)
+					error = errno;
+			}
+			break;
+		}
+
+		/* Work out exactly where the partition starts. */
+		blkoffset = (byteoffset + secsz - 1) / secsz;
+		if (abs_offset) {
+			part->block = scheme_metadata(SCHEME_META_PART_ABSOLUTE,
+			    blkoffset);
+		} else {
+			block = scheme_metadata(SCHEME_META_PART_BEFORE,
+			    block + blkoffset);
+			part->block = block;
+		}
+
+		if (verbose)
+			fprintf(stderr, "partition %d: starting block %llu "
+			    "... ", part->index + 1, (long long)part->block);
+
+		/* Pull in partition contents, set size if we haven't yet. */
+		switch (part->kind) {
+		case PART_KIND_FILE:
+			fd = open(part->contents, O_RDONLY, 0);
+			if (fd != -1) {
+				error = image_copyin(block, fd, &bytesize);
+				close(fd);
+			} else
+				error = errno;
+			break;
+		case PART_KIND_PIPE:
+			fp = popen(part->contents, "r");
+			if (fp != NULL) {
+				fd = fileno(fp);
+				error = image_copyin(block, fd, &bytesize);
+				pclose(fp);
+			} else
+				error = errno;
+			break;
+		}
+		if (error)
+			errc(EX_IOERR, error, "partition %d", part->index + 1);
+		part->size = (bytesize + secsz - 1) / secsz;
+		if (verbose) {
+			bytesize = part->size * secsz;
+			fprintf(stderr, "size %llu bytes (%llu blocks)\n",
+			     (long long)bytesize, (long long)part->size);
+			if (abs_offset) {
+				fprintf(stderr,
+				    "    location %llu bytes (%llu blocks)\n",
+				    (long long)byteoffset,
+				    (long long)blkoffset);
+			} else if (blkoffset > 0) {
+				fprintf(stderr,
+				    "    offset %llu bytes (%llu blocks)\n",
+				    (long long)byteoffset,
+				    (long long)blkoffset);
+			}
+		}
+		if (!abs_offset) {
+			block = scheme_metadata(SCHEME_META_PART_AFTER,
+			    part->block + part->size);
+		}
+	}
+
+	mkimg_validate();
+
+	block = scheme_metadata(SCHEME_META_IMG_END, block);
+	error = image_set_size(block);
+	if (!error) {
+		error = capacity_resize(block);
+		block = image_get_size();
+	}
+	if (!error) {
+		error = format_resize(block);
+		block = image_get_size();
+	}
+	if (error)
+		errc(EX_IOERR, error, "image sizing");
+	ncyls = block / (nsecs * nheads);
+	error = scheme_write(block);
+	if (error)
+		errc(EX_IOERR, error, "writing metadata");
+}
+
+int
+main(int argc, char *argv[])
+{
+	int bcfd, outfd;
+	int c, error;
+
+	bcfd = -1;
+	outfd = 1;	/* Write to stdout by default */
+	while ((c = getopt_long(argc, argv, "a:b:c: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");
+			bcfd = open(optarg, O_RDONLY, 0);
+			if (bcfd == -1)
+				err(EX_UNAVAILABLE, "%s", optarg);
+			break;
+		case 'c':	/* MINIMUM CAPACITY */
+			error = parse_uint64(&min_capacity, 1, INT64_MAX, optarg);
+			if (error)
+				errc(EX_DATAERR, error, "minimum capacity in bytes");
+			break;
+		case 'C':	/* MAXIMUM CAPACITY */
+			error = parse_uint64(&max_capacity, 1, INT64_MAX, optarg);
+			if (error)
+				errc(EX_DATAERR, error, "maximum capacity in bytes");
+			break;
+		case 'f':	/* OUTPUT FORMAT */
+			if (format_selected() != NULL)
+				usage("multiple formats given");
+			error = format_select(optarg);
+			if (error)
+				errc(EX_DATAERR, error, "format");
+			break;
+		case 'o':	/* OUTPUT FILE */
+			if (outfd != 1)
+				usage("multiple output files given");
+			outfd = open(optarg, O_WRONLY | O_CREAT | O_TRUNC,
+			    S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
+			if (outfd == -1)
+				err(EX_CANTCREAT, "%s", optarg);
+			break;
+		case 'p':	/* PARTITION */
+			error = parse_part(optarg);
+			if (error)
+				errc(EX_DATAERR, error, "partition");
+			break;
+		case 's':	/* SCHEME */
+			if (scheme_selected() != NULL)
+				usage("multiple schemes given");
+			error = scheme_select(optarg);
+			if (error)
+				errc(EX_DATAERR, error, "scheme");
+			break;
+		case 'y':
+			unit_testing++;
+			break;
+		case 'v':
+			verbose++;
+			break;
+		case 'H':	/* GEOMETRY: HEADS */
+			error = parse_uint32(&nheads, 1, 255, optarg);
+			if (error)
+				errc(EX_DATAERR, error, "number of heads");
+			break;
+		case 'P':	/* GEOMETRY: PHYSICAL SECTOR SIZE */
+			error = parse_uint32(&blksz, 512, INT_MAX+1U, optarg);
+			if (error == 0 && !pwr_of_two(blksz))
+				error = EINVAL;
+			if (error)
+				errc(EX_DATAERR, error, "physical sector size");
+			break;
+		case 'S':	/* GEOMETRY: LOGICAL SECTOR SIZE */
+			error = parse_uint32(&secsz, 512, INT_MAX+1U, optarg);
+			if (error == 0 && !pwr_of_two(secsz))
+				error = EINVAL;
+			if (error)
+				errc(EX_DATAERR, error, "logical sector size");
+			break;
+		case 'T':	/* GEOMETRY: TRACK SIZE */
+			error = parse_uint32(&nsecs, 1, 63, optarg);
+			if (error)
+				errc(EX_DATAERR, error, "track size");
+			break;
+		case LONGOPT_FORMATS:
+			print_formats(0);
+			exit(EX_OK);
+			/*NOTREACHED*/
+		case LONGOPT_SCHEMES:
+			print_schemes(0);
+			exit(EX_OK);
+			/*NOTREACHED*/
+		case LONGOPT_VERSION:
+			print_version();
+			exit(EX_OK);
+			/*NOTREACHED*/
+		case LONGOPT_CAPACITY:
+			error = parse_uint64(&min_capacity, 1, INT64_MAX, optarg);
+			if (error)
+				errc(EX_DATAERR, error, "capacity in bytes");
+			max_capacity = min_capacity;
+			break;
+		default:
+			usage("unknown option");
+		}
+	}
+
+	if (argc > optind)
+		usage("trailing arguments");
+	if (scheme_selected() == NULL && nparts > 0)
+		usage("no scheme");
+	if (nparts == 0 && min_capacity == 0)
+		usage("no partitions");
+	if (max_capacity != 0 && min_capacity > max_capacity)
+		usage("minimum capacity cannot be larger than the maximum one");
+
+	if (secsz > blksz) {
+		if (blksz != 0)
+			errx(EX_DATAERR, "the physical block size cannot "
+			    "be smaller than the sector size");
+		blksz = secsz;
+	}
+
+	if (secsz > scheme_max_secsz())
+		errx(EX_DATAERR, "maximum sector size supported is %u; "
+		    "size specified is %u", scheme_max_secsz(), secsz);
+
+	if (nparts > scheme_max_parts())
+		errx(EX_DATAERR, "%d partitions supported; %d given",
+		    scheme_max_parts(), nparts);
+
+	if (format_selected() == NULL)
+		format_select("raw");
+
+	if (bcfd != -1) {
+		error = scheme_bootcode(bcfd);
+		close(bcfd);
+		if (error)
+			errc(EX_DATAERR, error, "boot code");
+	}
+
+	if (verbose) {
+		fprintf(stderr, "Logical sector size: %u\n", secsz);
+		fprintf(stderr, "Physical block size: %u\n", blksz);
+		fprintf(stderr, "Sectors per track:   %u\n", nsecs);
+		fprintf(stderr, "Number of heads:     %u\n", nheads);
+		fputc('\n', stderr);
+		if (scheme_selected())
+			fprintf(stderr, "Partitioning scheme: %s\n",
+			    scheme_selected()->name);
+		fprintf(stderr, "Output file format:  %s\n",
+		    format_selected()->name);
+		fputc('\n', stderr);
+	}
+
+	error = image_init();
+	if (error)
+		errc(EX_OSERR, error, "cannot initialize");
+
+	mkimg();
+
+	if (verbose) {
+		fputc('\n', stderr);
+		fprintf(stderr, "Number of cylinders: %u\n", ncyls);
+	}
+
+	error = format_write(outfd);
+	if (error)
+		errc(EX_IOERR, error, "writing image");
+
+	return (0);
+}
diff --git a/usr.bin/mkimg/mkimg.h b/usr.bin/mkimg/mkimg.h
new file mode 100644
index 0000000000..8fd47a13c4
--- /dev/null
+++ b/usr.bin/mkimg/mkimg.h
@@ -0,0 +1,113 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: head/usr.bin/mkimg/mkimg.h 314577 2017-03-03 01:56:55Z sjg $
+ */
+
+#ifndef _MKIMG_MKIMG_H_
+#define	_MKIMG_MKIMG_H_
+
+#include <sys/queue.h>
+#include <sys/types.h>
+
+struct part {
+	TAILQ_ENTRY(part) link;
+	char	*alias;		/* Partition type alias. */
+	char	*contents;	/* Contents/size specification. */
+	u_int	kind;		/* Content kind. */
+#define	PART_UNDEF	0
+#define	PART_KIND_FILE	1
+#define	PART_KIND_PIPE	2
+#define	PART_KIND_SIZE	3
+	u_int	index;		/* Partition index (0-based). */
+	uintptr_t type;		/* Scheme-specific partition type. */
+	lba_t	block;		/* Block-offset of partition in image. */
+	lba_t	size;		/* Size in blocks of partition. */
+	char	*label;		/* Partition label. */
+};
+
+extern TAILQ_HEAD(partlisthead, part) partlist;
+extern u_int nparts;
+
+extern u_int unit_testing;
+extern u_int verbose;
+
+extern u_int ncyls;
+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)
+{
+	lba_t b = blksz / secsz;
+	return ((n + b - 1) & ~(b - 1));
+}
+
+static inline lba_t
+round_cylinder(lba_t n)
+{
+	u_int cyl = nsecs * nheads;
+	u_int r = n % cyl;
+	return ((r == 0) ? n : n + cyl - r);
+}
+
+static inline lba_t
+round_track(lba_t n)
+{
+	u_int r = n % nsecs;
+	return ((r == 0) ? n : n + nsecs - r);
+}
+
+#if !defined(SPARSE_WRITE)
+#define	sparse_write	write
+#else
+ssize_t sparse_write(int, const void *, size_t);
+#endif
+
+void mkimg_chs(lba_t, u_int, u_int *, u_int *, u_int *);
+
+struct mkimg_uuid {
+	uint32_t	time_low;
+	uint16_t	time_mid;
+	uint16_t	time_hi_and_version;
+	uint8_t		clock_seq_hi_and_reserved;
+	uint8_t		clock_seq_low;
+	uint8_t		node[6];
+};
+typedef struct mkimg_uuid mkimg_uuid_t;
+
+void mkimg_uuid(mkimg_uuid_t *);
+void mkimg_uuid_enc(void *, const mkimg_uuid_t *);
+
+#ifdef __linux__
+# if !defined(__unused)
+#   define __unused __attribute__ ((__unused__))
+# endif
+#endif
+
+#endif /* _MKIMG_MKIMG_H_ */
diff --git a/usr.bin/mkimg/qcow.c b/usr.bin/mkimg/qcow.c
new file mode 100644
index 0000000000..567327beb0
--- /dev/null
+++ b/usr.bin/mkimg/qcow.c
@@ -0,0 +1,369 @@
+/*-
+ * Copyright (c) 2014 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/qcow.c 315212 2017-03-13 20:14:07Z pfg $");
+
+#include <sys/errno.h>
+#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "endian.h"
+#include "image.h"
+#include "format.h"
+#include "mkimg.h"
+
+/* Default cluster sizes. */
+#define	QCOW1_CLSTR_LOG2SZ	12	/* 4KB */
+#define	QCOW2_CLSTR_LOG2SZ	16	/* 64KB */
+
+/* Flag bits in cluster offsets */
+#define	QCOW_CLSTR_COMPRESSED	(1ULL << 62)
+#define	QCOW_CLSTR_COPIED	(1ULL << 63)
+
+struct qcow_header {
+	uint32_t	magic;
+#define	QCOW_MAGIC		0x514649fb
+	uint32_t	version;
+#define	QCOW_VERSION_1		1
+#define	QCOW_VERSION_2		2
+	uint64_t	path_offset;
+	uint32_t	path_length;
+	uint32_t	clstr_log2sz;	/* v2 only */
+	uint64_t	disk_size;
+	union {
+		struct {
+			uint8_t		clstr_log2sz;
+			uint8_t		l2_log2sz;
+			uint16_t	_pad;
+			uint32_t	encryption;
+			uint64_t	l1_offset;
+		} v1;
+		struct {
+			uint32_t	encryption;
+			uint32_t	l1_entries;
+			uint64_t	l1_offset;
+			uint64_t	refcnt_offset;
+			uint32_t	refcnt_clstrs;
+			uint32_t	snapshot_count;
+			uint64_t	snapshot_offset;
+		} v2;
+	} u;
+};
+
+static u_int clstr_log2sz;
+
+static uint64_t
+round_clstr(uint64_t ofs)
+{
+	uint64_t clstrsz;
+
+	clstrsz = 1UL << clstr_log2sz;
+	return ((ofs + clstrsz - 1) & ~(clstrsz - 1));
+}
+
+static int
+qcow_resize(lba_t imgsz, u_int version)
+{
+	uint64_t imagesz;
+
+	switch (version) {
+	case QCOW_VERSION_1:
+		clstr_log2sz = QCOW1_CLSTR_LOG2SZ;
+		break;
+	case QCOW_VERSION_2:
+		clstr_log2sz = QCOW2_CLSTR_LOG2SZ;
+		break;
+	default:
+		assert(0);
+	}
+
+	imagesz = round_clstr(imgsz * secsz);
+
+	if (verbose)
+		fprintf(stderr, "QCOW: image size = %ju, cluster size = %u\n",
+		    (uintmax_t)imagesz, (u_int)(1U << clstr_log2sz));
+
+	return (image_set_size(imagesz / secsz));
+}
+
+static int
+qcow1_resize(lba_t imgsz)
+{
+
+	return (qcow_resize(imgsz, QCOW_VERSION_1));
+}
+
+static int
+qcow2_resize(lba_t imgsz)
+{
+
+	return (qcow_resize(imgsz, QCOW_VERSION_2));
+}
+
+static int
+qcow_write(int fd, u_int version)
+{
+	struct qcow_header *hdr;
+	uint64_t *l1tbl, *l2tbl, *rctbl;
+	uint16_t *rcblk;
+	uint64_t clstr_imgsz, clstr_l2tbls, clstr_l1tblsz;
+	uint64_t clstr_rcblks, clstr_rctblsz;
+	uint64_t n, imagesz, nclstrs, ofs, ofsflags = 0;
+	lba_t blk, blkofs, blk_imgsz;
+	u_int l1clno, l2clno = 0, rcclno;
+	u_int blk_clstrsz, refcnt_clstrs;
+	u_int clstrsz, l1idx, l2idx;
+	int error;
+
+	assert(clstr_log2sz != 0);
+
+	clstrsz = 1U << clstr_log2sz;
+	blk_clstrsz = clstrsz / secsz;
+	blk_imgsz = image_get_size();
+	imagesz = blk_imgsz * secsz;
+	clstr_imgsz = imagesz >> clstr_log2sz;
+	clstr_l2tbls = round_clstr(clstr_imgsz * 8) >> clstr_log2sz;
+	clstr_l1tblsz = round_clstr(clstr_l2tbls * 8) >> clstr_log2sz;
+	nclstrs = clstr_imgsz + clstr_l2tbls + clstr_l1tblsz + 1;
+	clstr_rcblks = clstr_rctblsz = 0;
+	do {
+		n = clstr_rcblks + clstr_rctblsz;
+		clstr_rcblks = round_clstr((nclstrs + n) * 2) >> clstr_log2sz;
+		clstr_rctblsz = round_clstr(clstr_rcblks * 8) >> clstr_log2sz;
+	} while (n < (clstr_rcblks + clstr_rctblsz));
+
+	/*
+	 * We got all the sizes in clusters. Start the layout.
+	 * 0 - header
+	 * 1 - L1 table
+	 * 2 - RC table (v2 only)
+	 * 3 - L2 tables
+	 * 4 - RC block (v2 only)
+	 * 5 - data
+	 */
+
+	l1clno = 1;
+	rcclno = 0;
+	rctbl = l2tbl = l1tbl = NULL;
+	rcblk = NULL;
+
+	hdr = calloc(1, clstrsz);
+	if (hdr == NULL)
+		return (errno);
+
+	be32enc(&hdr->magic, QCOW_MAGIC);
+	be32enc(&hdr->version, version);
+	be64enc(&hdr->disk_size, imagesz);
+	switch (version) {
+	case QCOW_VERSION_1:
+		ofsflags = 0;
+		l2clno = l1clno + clstr_l1tblsz;
+		hdr->u.v1.clstr_log2sz = clstr_log2sz;
+		hdr->u.v1.l2_log2sz = clstr_log2sz - 3;
+		be64enc(&hdr->u.v1.l1_offset, clstrsz * l1clno);
+		break;
+	case QCOW_VERSION_2:
+		ofsflags = QCOW_CLSTR_COPIED;
+		rcclno = l1clno + clstr_l1tblsz;
+		l2clno = rcclno + clstr_rctblsz;
+		be32enc(&hdr->clstr_log2sz, clstr_log2sz);
+		be32enc(&hdr->u.v2.l1_entries, clstr_l2tbls);
+		be64enc(&hdr->u.v2.l1_offset, clstrsz * l1clno);
+		be64enc(&hdr->u.v2.refcnt_offset, clstrsz * rcclno);
+		refcnt_clstrs = round_clstr(clstr_rcblks * 8) >> clstr_log2sz;
+		be32enc(&hdr->u.v2.refcnt_clstrs, refcnt_clstrs);
+		break;
+	default:
+		assert(0);
+	}
+
+	if (sparse_write(fd, hdr, clstrsz) < 0) {
+		error = errno;
+		goto out;
+	}
+
+	free(hdr);
+	hdr = NULL;
+
+	ofs = clstrsz * l2clno;
+	nclstrs = 1 + clstr_l1tblsz + clstr_rctblsz;
+
+	l1tbl = calloc(clstr_l1tblsz, clstrsz);
+	if (l1tbl == NULL) {
+		error = ENOMEM;
+		goto out;
+	}
+
+	for (n = 0; n < clstr_imgsz; n++) {
+		blk = n * blk_clstrsz;
+		if (image_data(blk, blk_clstrsz)) {
+			nclstrs++;
+			l1idx = n >> (clstr_log2sz - 3);
+			if (l1tbl[l1idx] == 0) {
+				be64enc(l1tbl + l1idx, ofs + ofsflags);
+				ofs += clstrsz;
+				nclstrs++;
+			}
+		}
+	}
+
+	if (sparse_write(fd, l1tbl, clstrsz * clstr_l1tblsz) < 0) {
+		error = errno;
+		goto out;
+	}
+
+	clstr_rcblks = 0;
+	do {
+		n = clstr_rcblks;
+		clstr_rcblks = round_clstr((nclstrs + n) * 2) >> clstr_log2sz;
+	} while (n < clstr_rcblks);
+
+	if (rcclno > 0) {
+		rctbl = calloc(clstr_rctblsz, clstrsz);
+		if (rctbl == NULL) {
+			error = ENOMEM;
+			goto out;
+		}
+		for (n = 0; n < clstr_rcblks; n++) {
+			be64enc(rctbl + n, ofs);
+			ofs += clstrsz;
+			nclstrs++;
+		}
+		if (sparse_write(fd, rctbl, clstrsz * clstr_rctblsz) < 0) {
+			error = errno;
+			goto out;
+		}
+		free(rctbl);
+		rctbl = NULL;
+	}
+
+	l2tbl = malloc(clstrsz);
+	if (l2tbl == NULL) {
+		error = ENOMEM;
+		goto out;
+	}
+
+	for (l1idx = 0; l1idx < clstr_l2tbls; l1idx++) {
+		if (l1tbl[l1idx] == 0)
+			continue;
+		memset(l2tbl, 0, clstrsz);
+		blkofs = (lba_t)l1idx * blk_clstrsz * (clstrsz >> 3);
+		for (l2idx = 0; l2idx < (clstrsz >> 3); l2idx++) {
+			blk = blkofs + (lba_t)l2idx * blk_clstrsz;
+			if (blk >= blk_imgsz)
+				break;
+			if (image_data(blk, blk_clstrsz)) {
+				be64enc(l2tbl + l2idx, ofs + ofsflags);
+				ofs += clstrsz;
+			}
+		}
+		if (sparse_write(fd, l2tbl, clstrsz) < 0) {
+			error = errno;
+			goto out;
+		}
+	}
+
+	free(l2tbl);
+	l2tbl = NULL;
+	free(l1tbl);
+	l1tbl = NULL;
+
+	if (rcclno > 0) {
+		rcblk = calloc(clstr_rcblks, clstrsz);
+		if (rcblk == NULL) {
+			error = ENOMEM;
+			goto out;
+		}
+		for (n = 0; n < nclstrs; n++)
+			be16enc(rcblk + n, 1);
+		if (sparse_write(fd, rcblk, clstrsz * clstr_rcblks) < 0) {
+			error = errno;
+			goto out;
+		}
+		free(rcblk);
+		rcblk = NULL;
+	}
+
+	error = 0;
+	for (n = 0; n < clstr_imgsz; n++) {
+		blk = n * blk_clstrsz;
+		if (image_data(blk, blk_clstrsz)) {
+			error = image_copyout_region(fd, blk, blk_clstrsz);
+			if (error)
+				break;
+		}
+	}
+	if (!error)
+		error = image_copyout_done(fd);
+
+ out:
+	if (rcblk != NULL)
+		free(rcblk);
+	if (l2tbl != NULL)
+		free(l2tbl);
+	if (rctbl != NULL)
+		free(rctbl);
+	if (l1tbl != NULL)
+		free(l1tbl);
+	if (hdr != NULL)
+		free(hdr);
+	return (error);
+}
+
+static int
+qcow1_write(int fd)
+{
+
+	return (qcow_write(fd, QCOW_VERSION_1));
+}
+
+static int
+qcow2_write(int fd)
+{
+
+	return (qcow_write(fd, QCOW_VERSION_2));
+}
+
+static struct mkimg_format qcow1_format = {
+	.name = "qcow",
+	.description = "QEMU Copy-On-Write, version 1",
+	.resize = qcow1_resize,
+	.write = qcow1_write,
+};
+FORMAT_DEFINE(qcow1_format);
+
+static struct mkimg_format qcow2_format = {
+	.name = "qcow2",
+	.description = "QEMU Copy-On-Write, version 2",
+	.resize = qcow2_resize,
+	.write = qcow2_write,
+};
+FORMAT_DEFINE(qcow2_format);
diff --git a/usr.bin/mkimg/raw.c b/usr.bin/mkimg/raw.c
new file mode 100644
index 0000000000..2ce3c6c0c1
--- /dev/null
+++ b/usr.bin/mkimg/raw.c
@@ -0,0 +1,61 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/raw.c 306621 2016-10-03 02:37:28Z marcel $");
+
+#include <sys/errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "image.h"
+#include "format.h"
+#include "mkimg.h"
+
+static int
+raw_resize(lba_t imgsz __unused)
+{
+
+	return (0);
+}
+
+static int
+raw_write(int fd)
+{
+
+	return (image_copyout(fd));
+}
+
+static struct mkimg_format raw_format = {
+	.name = "raw",
+	.description = "Raw Disk",
+	.resize = raw_resize,
+	.write = raw_write,
+};
+
+FORMAT_DEFINE(raw_format);
diff --git a/usr.bin/mkimg/scheme.c b/usr.bin/mkimg/scheme.c
new file mode 100644
index 0000000000..2f111290fa
--- /dev/null
+++ b/usr.bin/mkimg/scheme.c
@@ -0,0 +1,202 @@
+/*-
+ * Copyright (c) 2013,2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/scheme.c 306621 2016-10-03 02:37:28Z marcel $");
+
+#include <sys/stat.h>
+#include <assert.h>
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "image.h"
+#include "mkimg.h"
+#include "scheme.h"
+
+static struct {
+	const char *name;
+	enum alias alias;
+} scheme_alias[] = {
+	{ "ebr", ALIAS_EBR },
+	{ "efi", ALIAS_EFI },
+	{ "fat16b", ALIAS_FAT16B },
+	{ "fat32", ALIAS_FAT32 },
+	{ "freebsd", ALIAS_FREEBSD },
+	{ "freebsd-boot", ALIAS_FREEBSD_BOOT },
+	{ "freebsd-nandfs", ALIAS_FREEBSD_NANDFS },
+	{ "freebsd-swap", ALIAS_FREEBSD_SWAP },
+	{ "freebsd-ufs", ALIAS_FREEBSD_UFS },
+	{ "freebsd-vinum", ALIAS_FREEBSD_VINUM },
+	{ "freebsd-zfs", ALIAS_FREEBSD_ZFS },
+	{ "mbr", ALIAS_MBR },
+	{ "ntfs", ALIAS_NTFS },
+	{ "prepboot", ALIAS_PPCBOOT },
+	{ NULL, ALIAS_NONE }		/* Keep last! */
+};
+
+static struct mkimg_scheme *first;
+static struct mkimg_scheme *scheme;
+static void *bootcode;
+
+static enum alias
+scheme_parse_alias(const char *name)
+{
+	u_int idx;
+
+	idx = 0;
+	while (scheme_alias[idx].name != NULL) {
+		if (strcasecmp(scheme_alias[idx].name, name) == 0)
+			return (scheme_alias[idx].alias);
+		idx++;
+	}
+	return (ALIAS_NONE);
+}
+
+struct mkimg_scheme *
+scheme_iterate(struct mkimg_scheme *s)
+{
+
+	return ((s == NULL) ? first : s->next);
+}
+
+void
+scheme_register(struct mkimg_scheme *s)
+{
+	s->next = first;
+	first = s;
+}
+
+int
+scheme_select(const char *spec)
+{
+	struct mkimg_scheme *s;
+
+	s = NULL;
+	while ((s = scheme_iterate(s)) != NULL) {
+		if (strcasecmp(spec, s->name) == 0) {
+			scheme = s;
+			return (0);
+		}
+	}
+	return (EINVAL);
+}
+
+struct mkimg_scheme *
+scheme_selected(void)
+{
+
+	return (scheme);
+}
+
+int
+scheme_bootcode(int fd)
+{
+	struct stat sb;
+
+	if (scheme == NULL || scheme->bootcode == 0)
+		return (ENXIO);
+
+	if (fstat(fd, &sb) == -1)
+		return (errno);
+	if (sb.st_size > scheme->bootcode)
+		return (EFBIG);
+
+	bootcode = malloc(scheme->bootcode);
+	if (bootcode == NULL)
+		return (ENOMEM);
+	memset(bootcode, 0, scheme->bootcode);
+	if (read(fd, bootcode, sb.st_size) != sb.st_size) {
+		free(bootcode);
+		bootcode = NULL;
+		return (errno);
+	}
+	return (0);
+}
+
+int
+scheme_check_part(struct part *p)
+{
+	struct mkimg_alias *iter;
+	enum alias alias;
+
+	assert(scheme != NULL);
+
+	/* Check the partition type alias */
+	alias = scheme_parse_alias(p->alias);
+	if (alias == ALIAS_NONE)
+		return (EINVAL);
+
+	iter = scheme->aliases;
+	while (iter->alias != ALIAS_NONE) {
+		if (alias == iter->alias)
+			break;
+		iter++;
+	}
+	if (iter->alias == ALIAS_NONE)
+		return (EINVAL);
+	p->type = iter->type;
+
+	/* Validate the optional label. */
+	if (p->label != NULL) {
+		if (strlen(p->label) > scheme->labellen)
+			return (EINVAL);
+	}
+
+	return (0);
+}
+
+u_int
+scheme_max_parts(void)
+{
+
+	return ((scheme == NULL) ? 0 : scheme->nparts);
+}
+
+u_int
+scheme_max_secsz(void)
+{
+
+	return ((scheme == NULL) ? INT_MAX+1U : scheme->maxsecsz);
+}
+
+lba_t
+scheme_metadata(u_int where, lba_t start)
+{
+
+	return ((scheme == NULL) ? start : scheme->metadata(where, start));
+}
+
+int
+scheme_write(lba_t end)
+{
+
+	return ((scheme == NULL) ? 0 : scheme->write(end, bootcode));
+}
diff --git a/usr.bin/mkimg/scheme.h b/usr.bin/mkimg/scheme.h
new file mode 100644
index 0000000000..01367f177c
--- /dev/null
+++ b/usr.bin/mkimg/scheme.h
@@ -0,0 +1,96 @@
+/*-
+ * Copyright (c) 2013,2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: head/usr.bin/mkimg/scheme.h 332436 2018-04-12 15:47:47Z benno $
+ */
+
+#ifndef _MKIMG_SCHEME_H_
+#define	_MKIMG_SCHEME_H_
+
+enum alias {
+	ALIAS_NONE,		/* Keep first! */
+	/* start */
+	ALIAS_EBR,
+	ALIAS_EFI,
+	ALIAS_FAT16B,
+	ALIAS_FAT32,
+	ALIAS_FREEBSD,
+	ALIAS_FREEBSD_BOOT,
+	ALIAS_FREEBSD_NANDFS,
+	ALIAS_FREEBSD_SWAP,
+	ALIAS_FREEBSD_UFS,
+	ALIAS_FREEBSD_VINUM,
+	ALIAS_FREEBSD_ZFS,
+	ALIAS_MBR,
+	ALIAS_NTFS,
+	ALIAS_PPCBOOT,
+	/* end */
+	ALIAS_COUNT		/* Keep last! */
+};
+
+struct mkimg_alias {
+	u_int		alias;
+	uintptr_t	type;
+#define	ALIAS_PTR2TYPE(p)	(uintptr_t)(p)
+#define	ALIAS_INT2TYPE(i)	(i)
+#define	ALIAS_TYPE2PTR(p)	(void *)(p)
+#define	ALIAS_TYPE2INT(i)	(i)
+};
+
+struct mkimg_scheme {
+	struct mkimg_scheme *next;
+	const char	*name;
+	const char	*description;
+	struct mkimg_alias *aliases;
+	lba_t		(*metadata)(u_int, lba_t);
+#define	SCHEME_META_IMG_START		1
+#define	SCHEME_META_IMG_END		2
+#define	SCHEME_META_PART_BEFORE		3
+#define	SCHEME_META_PART_AFTER		4
+#define	SCHEME_META_PART_ABSOLUTE	5
+	int		(*write)(lba_t, void *);
+	u_int		nparts;
+	u_int		labellen;
+	u_int		bootcode;
+	u_int		maxsecsz;
+};
+
+#define	SCHEME_DEFINE(nm)						\
+static void scheme_register_##nm(void) __attribute__((constructor));	\
+static void scheme_register_##nm(void) { scheme_register(&nm); }
+
+struct mkimg_scheme *scheme_iterate(struct mkimg_scheme *);
+void	scheme_register(struct mkimg_scheme *);
+int	scheme_select(const char *);
+struct mkimg_scheme *scheme_selected(void);
+
+int scheme_bootcode(int fd);
+int scheme_check_part(struct part *);
+u_int scheme_max_parts(void);
+u_int scheme_max_secsz(void);
+lba_t scheme_metadata(u_int, lba_t);
+int scheme_write(lba_t);
+
+#endif /* _MKIMG_SCHEME_H_ */
diff --git a/usr.bin/mkimg/tests/Makefile b/usr.bin/mkimg/tests/Makefile
new file mode 100644
index 0000000000..b3cc8d5b9d
--- /dev/null
+++ b/usr.bin/mkimg/tests/Makefile
@@ -0,0 +1,23 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/Makefile 319294 2017-05-31 07:49:49Z ngie $
+
+.PATH:	${.CURDIR}
+
+PACKAGE=	tests
+
+_REBASE_SCRIPT=	mkimg_test
+ATF_TESTS_SH=	${_REBASE_SCRIPT}
+
+SOURCES!=	cd ${.CURDIR}; echo *.uu
+${PACKAGE}FILES+=		${SOURCES:S,.gz.uu,,g}
+
+.for f in ${${PACKAGE}FILES}
+$f: $f.gz.uu
+	uudecode -p ${.ALLSRC} | gunzip -c > ${.TARGET}
+.endfor
+
+CLEANFILES+=	${${PACKAGE}FILES}}
+
+rebase: .PHONY
+	(cd ${.CURDIR}; atf-sh ${_REBASE_SCRIPT}.sh rebase)
+
+.include <bsd.test.mk>
diff --git a/usr.bin/mkimg/tests/Makefile.depend b/usr.bin/mkimg/tests/Makefile.depend
new file mode 100644
index 0000000000..44cacf11d9
--- /dev/null
+++ b/usr.bin/mkimg/tests/Makefile.depend
@@ -0,0 +1,11 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/Makefile.depend 296587 2016-03-09 22:46:01Z bdrewery $
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-apm.qcow.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-apm.qcow.gz.uu
new file mode 100644
index 0000000000..4eae05aa7b
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-apm.qcow.gz.uu
@@ -0,0 +1,127 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-apm.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-1x1-4096-apm.qcow.gz
+M'XL("*DS(E0``VEM9RTQ>#$M-#`Y-BUA<&TN<6-O=RYO=70`K9W9CAW9<47?
+M^RLN9[(XW8C(D;,$N0$_&&A;T+.4(R!`MA.R`+_PXUW%.D-5W+T9E+NI0H-$
+M(3>R3BTN":W%P_/Y]L?IU,JIZ4[->-KGT_6OTX><[OSB_L?IZ[___*]O[O[X
+M^M/MF)R_\Y3[=:,G27/WMGY?Y_3FJ>5T'G]@[OH#SMUY._LGWN[.%WLY=_73
+M[1>+GU,V:/<&3VGNG-Y/R.DU/_9^7]R7*[>G]]M]N4J^W)8-=O<&?TES?TGO
+MI^3+[=G<<&_N<%^NDB]W9'/3=V%1`LO,YI9@KH%/K6QN"^9:^-2.Y^0[W]O;
+MN0X^)6Q.X=RIS/7P*6-SS;VY\YL,=)X;X%.$.PFY&^%3A#L)N9O@4X0[";F;
+MX5.$.PFY6^!3A#L)N5OA4X0[#;G;X%.$.PVYV^%3A#N-N!/\%.%.(^X$^4X9
+M=QIQ)\AWRKC3B#M!OE/&G4;<"?*=,NXTXDZ0[Y1Q9Q%W@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[Y]7;J>\!F/;__^=];$//[
+C_<;GUYW3^9TG\$_^B:^_O+G_G]O!YMO@3_\'*;=.DB.F````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-apm.qcow2.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-apm.qcow2.gz.uu
new file mode 100644
index 0000000000..b4a8e744d4
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-apm.qcow2.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-apm.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-1x1-4096-apm.qcow2.gz
+M'XL(")T[(U0``VEM9RTQ>#$M-#`Y-BUA<&TN<6-O=S(N;W5T`*V826_;,!!&
+M[_D53/>F32K.D)35/9N!'@JD#7H.O,A`@"Y&&J`7__A2ULB4J1DQ-N0(1@SB
+M>Q@/GT>FLZQ^*&6U,DZ90BVFRK^F"U3KQ?:E5M_&7T[:C]5!#=.9D&(6#&YP
+M6ZSS@`,)E^GN@N9QK>J0P4&3ZH)2."-6U[?`X(X.UJU;;\8H2N`^P!HG;L9>
+M]4%=7YPP>]8'0]>'?/]LDXL77']]6-<7IW()-TKB@$D5$FZ2Q"&3FDJX61)G
+MF-1<PI5)G&52"P&G$ZIXG&-26L)!$I<S*91P)HD;,2G).YWVKF!2DG<Z[=V$
+M24G>Z;1W4R8E>:?3WLV8E.2=3GLW9U*2=R!XIP*N9%*2=Q!Y=TBX1P&W8%*2
+M=Q!Y]YAP3S8XS:4D[R#R[BGAG@4<,^]`\@XB[YX3[D7`,?,.).\@\NXEX8X"
+MCIEW('D'D7>O"/<ZX)AY!Y)W$'EWW/%.,_,.).\P\NX-L;*`8^8=2MYAY)TF
+M'`0<,^]0\@XC[Y!P)N"8>8>2=QAY9PGG`HZ9=RAYAY%W.>%&`<?,.Y2\P\B[
+M@G!O`XZ9=RAYAY%W[PCW/N"8>8>2=QAY]X%P'P..F7<H>6<B[SX1[G/`,?/.
+M2-Z9R+M3PIT%'#/OC.2=B;P[)]S%!@=<:N-=EO$7X2X[GUD8]ONG"=^/-?,L
+M+_0`1[L`^RJL<<6@;]C6;]CO@(5PCLK6=\A1+_#R>X4YW*[/#GT@L+4P?C*;
+M>2>'TH'/+ZRNOC+]L[4P_N/@IZF_W$PY^Z#Z3I?+GR6#DT^WNQ^G/`Z[U=G%
+M^G\O2PXJ-\H5].P6RI75,E5WLYS<W=_>W_[Y?=/@JANDFU?A?)?J?DV6;'5V
+MX+TU#]S;YGX!!-S>6]749X9VSZRWPU6-]QOA+S\N+593SG_-4-96:Q:[P/%=
+M69Y=7QS_&%^W^V>&_;'!^A-5NG_0ZE_](6GW3[7K<T/WS_7V+T>5YXR;H7]_
+J_]4B-O4-W#^=4?_\2;W[+"^LKDZV_VJ@(>!@%1I73>>#_Z4*H1'E$P``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-apm.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-apm.raw.gz.uu
new file mode 100644
index 0000000000..1f8a61c843
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-apm.raw.gz.uu
@@ -0,0 +1,12 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-apm.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-4096-apm.raw.gz
+M'XL(".W%'50``VEM9RTQ>#$M-#`Y-BUA<&TN<F%W+F]U=`"MD\UJPS`0A.]^
+MBNFU4"/)*RD]MK2Y%4)#S\'4#@3:Q*2!7O3PE2*)R#\)+FB]"(ME/\:S:\9\
+M`"0A!9A-%E)PL`4N]T'"O+Z7-N[*&*;P,,YN=%W'E8,PQ;T'"E>6#-2,^JH4
+MR/L%LWH;`CW.Z2,.S5RJ3R@Y2]]3UWVU$SB1ZW,]KAJKD]OS.P>T@":HQW"J
+M+53KRD'=IJN/I]UI=]AO(HXL3C6N6?]'W7?=3:J3F6=+,V>[B$L9@/W9(NJC
+MW+M'YW$H9[P=A$T2D!6((!HK7+J:O8^`RV/;/J]?'CZ6Z]0_HLSZU`S_1.*?
+M_TE2_Y#J4[G]4S?]TQ6TGMC-BW\_OWX1H[[,_G$6_&/UQ'F]8%9E__%`"L!L
+."DDX8/$'F8$ZXZ<%````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-apm.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-apm.vhd.gz.uu
new file mode 100644
index 0000000000..1eeaf78ce3
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-apm.vhd.gz.uu
@@ -0,0 +1,19 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-apm.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-1x1-4096-apm.vhd.gz
+M'XL("`0UQ%4``VEM9RTQ>#$M-#`Y-BUA<&TN=FAD+F]U=`"M5EUOVR`4?<^O
+MN%/?*BT"##A[7+7VK5*UJMICY3FXL[JV41.I?<C^>[E\%&R#E60X!$'(/3Z<
+M^P&$V`=`5B`[D`JDP''-07Z#>@6@%UUCIJ=N"OOVY5FUN_Y]Z9[]PH)1$EL-
+MS=&>5<#U2VI@#;Y$KG$,>P^S/+M\..^?'CP<<W#,`8D:K2H&\O?D/5S_NK+L
+M$.E7SQX-Y,6?3W;5E%VPTM]Z#80#I=$_*L].PRS_#3?+M577F58#448?WP:3
+MP4+8[$@[0496$<V4J"1L-@4GYZR.@3M?.%_84-&!4>N>@*10,QSKL/$Z3)H.
+ME??MIGG=JA$_E@D5^<F/3M:J_':9"Q7F_^P8<`SGN>V"0=F-X1*A\E_JR:$=
+M=P,M`A%^@9GM#]4+4!#SDY3,:)YW1I9?@_QT:@H6L@TI4:AF];O\B3!?^$B_
+M)N/=D_5K<5EG"%^GHB),QKE[<YT,EQ;Y<8IAC)'<8@P?PN_[9O-7)>!8J>U:
+MN&K*3G0NYTS2V1)M>ENZ1>?9W>MLV_6[_N7YWL-AH<)2:Q`/9_?4;)+L1&'?
+MJ@-]NXKRA$Q\"YZ?*AU[RKA#HO!X0@H\-(0^R#BPM28N<$W/)X!7KTI=W/[X
+M>G=U&^NG>%E^E!R@'XOTLTD2ZQ?7%IH[Q$_G-ZL?'B9U(C:#?MLW&XB>7VG]
+M&J<?:1)]?F%_LQQ^+"!SQ;18=6:A^I5AR!U@,88\Y'`IAE3-.O-8+TO'L-!5
+M5^:KS"E7780K>-65KF1EK<A15UWI2E:AJR["%;SJ(ES1JZXT!77Q`0\AJT,?
+##0``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-apm.vhdf.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-apm.vhdf.gz.uu
new file mode 100644
index 0000000000..e164fa6b86
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-apm.vhdf.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-apm.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-1x1-4096-apm.vhdf.gz
+M'XL("'`EAE4``VEM9RTQ>#$M-#`Y-BUA<&TN=FAD9BYO=70`K551:\(P$'[W
+M5QSL90@K:7))]'%C^C8HD[%'J;:5LJG%"=M#?_R2)EE36T5'XA$:SOOX[KO+
+MA1"S`)`#IT"4$6MTHO?V?&)0SUXCM>XCM^J1`8LO19V'BTY6/1H;0*K=G`!F
+MO3CF`\9=1YV\G`(:.,T/8Y!$FUB#X%?Q>ZRJSWP`CH9*U\"Q/CM>--\Q@*0@
+M$<34[J(`D6NW9;>LTL.Q/);[W=+!H8(3F0Z6M[#;IM4@.QZXMGAE;2>N*2U@
+MM[;@^&'HWL.F'$(+KPJA#"EP!HA`,T6<:Y\Z]P#GASQ_6CP_O,T7OGZ(@?F)
+M*_2CGG[FDOCZ@<]/A-9/7-1/,I!RH#=;_;Z^32,Z?H'UBXG5CZ0#^WE'G43=
+MGP%$"QB,(;?363![U[6(S,V`B0](V_(V@.O]+E\?RQ__!G,[G8MBV'0\9?HM
+M$!)HVHR83'][_.YFFW&YW3@X-_W<P\&ECF*JW*M>NKR;[GM)/QK(I&7'^B)Q
+M7[VI`((0QYW$+;O$5\_`X5^R>0$K;/1QUCET'(.S6<,UT\__\W]K:^!$X%91
+,#^7H%Z>,MH[2!P``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-apm.vmdk.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-apm.vmdk.gz.uu
new file mode 100644
index 0000000000..9175b1cecf
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-apm.vmdk.gz.uu
@@ -0,0 +1,82 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-apm.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-4096-apm.vmdk.gz
+M'XL(".[%'50``VEM9RTQ>#$M-#`Y-BUA<&TN=FUD:RYO=70`K9Q;;]S($87?
+M_2L([\LB0`2>X?W!0-:1#03!`L9ZDSQN>(V%V)8@"4D,S(\/F^S3.I1$-[$J
+M[V@YY:FJZ:X>E>2O#IBFZY\DR;LDSY-\2(HR29',?[4^DC1[,.;'J>8+Y[]>
+M_OSW"_[Y\>+B_&I-!A<E(4@UG1B;]SE?//K#=*?O16U>F!^G:+K,175/`GVZ
+MT\X+N^GR^<73<R%<7;N\/+@GDBX)B9)-NN*9/>UN]GNK^\,K7SRWOLRM83[>
+MLDFJ+"D[;R9EL=A94IV6U]*DFIVF.>$/R>75W;^3R_&NO[VZN;_VZSNYLYV=
+M\]+YE[W+,&^L*MT3]X)+U[@4Y9AD0Y+!O9R<;]]??1XO_C/>WEU=?WT#;O?D
+MSC;/DKQQRW'^Z<-C8[@W29,2[CV2\Y__<OG&?W+3BYOVENE<U+R0^;WG?6C>
+MLDS<U]/'LKKQZ[W+./D_877N;'UQBN6]<_>DR).J29;E%"[W:7YY\%M>:M??
+MCNW]^.NWF_'-ZR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]O[J_NKZZV],M]RO=_"W<3V^NB_MS;.K,[X7<YX?/%O^
+M"^'D$V[/-N'ZK._]F>?+<92\WW'A[J);+'?4/0WSP@OW6I$]3?C^=AS??KS\
+MX]_>?]3ZY;GQ^LH#]5-IR/I-HO5+='W6VN.\_&[]JBRIJF<^FP_UN_OO^D'D
+J^HSK5Z2^?N[^SD_^O__"^</%]K\U8>X3FJTP=S>?35_]'S/@3HZ37@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-bsd.qcow.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-bsd.qcow.gz.uu
new file mode 100644
index 0000000000..87d357f973
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-bsd.qcow.gz.uu
@@ -0,0 +1,125 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-bsd.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-1x1-4096-bsd.qcow.gz
+M'XL("*LS(E0``VEM9RTQ>#$M-#`Y-BUB<V0N<6-O=RYO=70`K9W+CAM)DD7W
+M]174^RW1S()DA-YHH`>87<]F9EM\KOD!^OA1*2/<E<9S96ITJ01!0BHN2,^C
+M4RC5@>=Z??=MM=K8:MBNAFEU.:R^_WK^;JN??G'_^^K;__S7?[_]^=NW/^[&
+M;/V+I]*O!U_Y/'=OZQ^K-N=_/75<K:??F/O^W6CNIU<7_\:K^^G-WLZ]_./N
+MS?)SK@;CWN!JGEO/K\_$Z0V_]_J^IK=K=Z?W][U=%V]WHP:W]P;_-<_].;\^
+M%V]WI^;&>W/7]'9=O-U)S>U_"8L+6`YJ[EC,#?C42<V=B[D-/G7A.?O%Y_9N
+M;HM/F9K#/[=O5VUNAT^%FAONS:W?+D`O<R,^);BSDKL)GQ+<6<G='I\2W%G)
+MW0&?$MQ9R=T1GQ+<6<G="9\2W'G)W1F?$MR)?U_\Q-T%GQ+<><6=\5.".Z^X
+M,_*=*^Z\XL[(=ZZX\XH[(]^YXLXK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M_<N_F
+D_.\5P>Z'6?[RW!Y^U!_X]J^W]_^Y&QQ^#/[Q_[+N5S>!I0``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-bsd.qcow2.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-bsd.qcow2.gz.uu
new file mode 100644
index 0000000000..5df1b3bc6e
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-bsd.qcow2.gz.uu
@@ -0,0 +1,21 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-bsd.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-1x1-4096-bsd.qcow2.gz
+M'XL(")X[(U0``VEM9RTQ>#$M-#`Y-BUB<V0N<6-O=S(N;W5T`*V8VY+20!"&
+M[WF*6<^NBIGN24@\K+KK6N6=WN@UL/`4/+P;ILDDG?XS2`52J:*&_ZN>S)=F
+M0E'$EW.E=Z%RH7'[C7O\+`>YWH?AX0Z_?_Q<]E^'183Y`J2,@<`=;L"Z2SA"
+MN,*/![R-ZU7'!HY.J3$HAPNPNJD!`W>].%ZZXV+4*L&7`",.+L9%]5&L3R?"
+MA?71W/6Q??W*4TX/5-/U<:Q/IU8(5V=Q9*0:A%MG<6RD-@BWS>*"D7I`N%T6
+M5QJI/<#YC"J/N,I(>82C+&YEI!CA0A97&RGDG<][UQ@IY)W/>[<V4L@[G_=N
+M8Z20=S[OW=9((>]\WKL'(X6\(^"=2[B=D4+>D?+N2G!/$FYOI)!WI+Q[*KAG
+M'<Y;*>0=*>^>"^Y%PAG]CI!WI+Q[*;A7"6?T.T+>D?+NM>"N$\[H=X2\(^7=
+M&\&]33BCWQ'RCI1W[T;>>:/?$?*.E7?OA54DG-'O&'G'RCLO.$HXH]\Q\HZ5
+M=RRXD'!&OV/D'2OO2L%5"6?T.T;>L?)N);@ZX8Q^Q\@[5MXU@ON0<$:_8^0=
+M*^\^"NY3PAG]CI%WK+S[++B;A#/Z'2/O@O+NB^"^)IS1[P+R+BCOO@GN-N&,
+M?A>0=T%Y=R>X[QV.K%3G75'8A^#N1_<LS;O_#&E_[(TS'I@`UO\#G*HPXII9
+M)US&";<:K(TS'CC<+H?O#GA<X7+5KFI9N9K.K?#O_9_QA,L95SCB\..H#'0%
+M^W-PQ\?1WC?K_N8"#@PW%U<)-_DXVNZQ=]8`K*Z<61:J5:Z_SJ[9'Q]23MU=
+M;<VZ]76I/D-F&DQWHCXWGF[[J]$]W:E5;'&4F:X;XC:3:SM=W=6XNNW,B\'Z
+MSCCSSFTAPSLWXFC>1D#Q?ZFB_=;XC`<.OY;#=P0&`<YV!4/5]K[%/SE0:JE#
+#$P``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-bsd.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-bsd.raw.gz.uu
new file mode 100644
index 0000000000..1e4a765d0b
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-bsd.raw.gz.uu
@@ -0,0 +1,10 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-bsd.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-4096-bsd.raw.gz
+M'XL(".[%'50``VEM9RTQ>#$M-#`Y-BUB<V0N<F%W+F]U=`"ME,$.@R`,AN\^
+M1;WN0$J%Z:Y+=M]I.SNS/04//U!4*@-=0C$DI.V7O]2".!F`(L#^QYYVF*O@
+MRU2G:J21`^H6E`9]ALZ&X_JQ`W.8Y^TA0C,>)W-9:9S8V(RC/=PB6![!-2XK
+MB+1J22ZXE&/"U9Y5KSB54V<1^/ZK6%WJ[N;>=IN\L,^`'\`!L/,^XL"EO[#J
+MN\0RB)6;T0=QN;W#M3Q>!CC:*1<X[I7M;5Y=':L;"C>CV4[&P<EU$#ZY$X[*
+C/@0TOBSV#[11\9YVF+O@:P(J#RQV@XH<L/H"TT^@ZP4%````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-bsd.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-bsd.vhd.gz.uu
new file mode 100644
index 0000000000..c3fb323464
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-bsd.vhd.gz.uu
@@ -0,0 +1,17 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-bsd.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-1x1-4096-bsd.vhd.gz
+M'XL("`<UQ%4``VEM9RTQ>#$M-#`Y-BUB<V0N=FAD+F]U=`"METUOPR`,AN_]
+M%9YVZZ0('`+9=5+O.ZWG-$VW:MJ'UAYZR/[[[`12R-?:C8124O"3U\8@*D1[
+M`>@4]`YT!3KCME&@[\'D`-1I"S:UM(]0EQ_O57G<GQ)[U8L6)H5O%9JS/::@
+MZ"4&L."7Z"VWH7:8Y';UO-R_/3L<6AQ:4&;8*D70F\%[%/V:M^J8M-[C:X-\
+M>.G4I4-U9ROZF"T(!5)Z(U*GCC#)=^BL(JO=KBD&1-7$QY7@(>@X.]N+729Z
+M5I[,L:"*L[-C.#UG=0UNN;!ST:8*)8:A6H"68)#;E#8N#H-"J7(Z?!9?AZJG
+M#R=217?ZY*`OG787;:J@&VP5*$[G.7>AH1S[N)%4^5?T=&BG;(."(#+7@8W[
+M8?3.*/#U:2EF8CX]&9/Z"M9'BT$4(_5T1_V0A'<'+!E(ZY66>Z8AQTLCN%X]
+MC<UO.9$N?UP=)?Z&ZP3+2W"I7;MN9*H`N]URLJ/!J9L6Q=\.I^;4<<Y45SF;
+M14[F,N_9^?,,N`%1@LB]K/:`/+]W-I^=OONA#`S<G=$'0W<+QIEPO/1P^(N[
+M$.(VLW,[J\[-K8\K(T_&MK\R+ERY#`E7;HO#N!L!-CL+92"-&M;3'?5C$MXM
+M$.U6%6WO0[=5Q5*H+#":0@)6D15B-9MLUV:AM@HC'209%_$@R;B(!TG&13Q(
+<,B[B09)Q$0^2C(MZD-3T%T&(Q0_L]):$?0P`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-bsd.vhdf.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-bsd.vhdf.gz.uu
new file mode 100644
index 0000000000..f11728a841
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-bsd.vhdf.gz.uu
@@ -0,0 +1,13 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-bsd.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-1x1-4096-bsd.vhdf.gz
+M'XL("',EAE4``VEM9RTQ>#$M-#`Y-BUB<V0N=FAD9BYO=70`K90[;X0P#(!W
+M?H6E+N@&E)@DP%KI=J9V!@HG5+5=.G3@QS<&`C&ONU:$*`(Y_O!;B&$!*`11
+M;)S[@NXYXD\77(*>A@34"2@-VD!JKXMYLP\FZ%ZO+Y&_NA$GC[3V<=%B.1S>
+MPTT&RT=P,6E)1L%TPNT)!EPXLL(9IXZLLY$0]9^<U6?%SN4V7>CY>0;9@-`@
+MG)?(@5-^8;8O6YN!S-T#^V#M;D&XA-^7'@[ON`L<5Q[F]MBZ<&U==7(RXF5G
+M/-BY!.&=.^#PW$&`_62Q%6AOK<]]09='_!F`:@2>%D$]SCX3@VG`U&`TO2<*
+M3`9)Z@.15U)7?7W6U7?[XV>8<)20IMG>I(\Q=8M)``OZB7FC=\^^I^OMTG[<
+M',Z-*C>1;+-9K1C!E"MW]:+96GSOD?EL7;P.DO:CEQD0"J1DCH_6Y;R<":<F
+F9^L&2M7'QVWVP02;HXIP6BRT_IO;`6=.+A5;?,$O]2/CMC`'````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-bsd.vmdk.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-bsd.vmdk.gz.uu
new file mode 100644
index 0000000000..8ae7398953
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-bsd.vmdk.gz.uu
@@ -0,0 +1,81 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4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OI%<+YMHU\$Y]LV^D5POFVC7T28;]/R5?I%A/DV+5^E7T28;]/R5?I%A/DV
+M+5^E7T28;YOH%Q'FVR;Z183YMHE^$6&^;:)?1)AOF^@7$>;;)OI%A/FVB7X1
+M8;YMHE]$F&^;Z!<1YMLF^D6$^;:)?A%AOFVB7T28;YOH%Q'FVR;Z183YMHE^
+M$6&^;:)?1)AOF^@7$>;;)OI%A/FVB7X18;YMHE]$F&^;Z!<1YMLF^D6$^;:)
+M?A%AOFVB7T28;YOH%Q'FVR;Z183YMHE^$6&^;:)?!.?;-OI%#*;Z10RF^D4,
+MIOI%#*;Z10RF^D4,IOI%#*;Z10RF^D4,IOI%#*;Z10RF^D4,IOI%#*;Z10RF
+M^D4,IOI%C&EJJ%_$:*I?Q&BJ7\1HJE_$:*I?Q&BJ7\1HJE_$:*I?Q&BJ7\1H
+MJE_$:*I?Q&BJ7\1HJE_$:*I?Q&BJ7\1HJE\\IFEJJ%\\7GR6\,YPE\DN^L!\
+MWM_RZ:"7?V\_</YP6/\)`></V"TJ]T&G19G4Q[T[_/WC;\\DG!_-$E["77QX
+M\M-P8<,[/HLYGS]@5RU3_4#HS0>6<.]\K'>/X?*7=J=SBGW)&G]X<CY_B*W:
+MZCG/[Y+B<1[_Y+T1SC=YW%]SN8WC*MT7]I=<INN:J'Y\J)[BZMVZD6ZR#M>^
+M>+8O[^[=Y>XZX\.X^"C6G>]<%V3]SEW"'6T;03EWEF7X?_GW]@/G3X?UGR5@
+-/@=\\W^I>^KAH%T`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-ebr.qcow.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-ebr.qcow.gz.uu
new file mode 100644
index 0000000000..1230d5862f
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-ebr.qcow.gz.uu
@@ -0,0 +1,127 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-ebr.qcow.gz.uu 272073 2014-09-24 15:15:14Z marc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/'/WN7%'
+M]]^%ZN\B]7>?9^X^-^[H_KM0_5VD_N[S-9\=W7\7JK^+U-^UL^MSY#O5WT7J
+M[V".?*?ZNTC]'<R1[U1_%ZF_6^:^]#GRG>KO(O5W7Y:YQAW=?Q>JOXO4WWV9
+MN?O2N2/?J?XN4G_W9>;N2^>.?*?ZNTC]W9?KS=F1[U1_%ZF_:V?7Y\AWJK^+
+MU-_!'/E.]7>1^CN8(]^I_FY8OI/FOO8Y\-V@^KLA]7=?E[G.'?CN^U/,W9#Z
+MNZ\S=U\7[H8U/\7<#:F_^SIS]_5?;0Y\-ZC^KGTL<[DW'NC^N_Y4,7?GV[<_
+M7OX<W-#-/,7@Y8*#O^9^D/?]%WS_V&_F[WS_6-N=N1]?4MCTZWMP=XZ^\O%?
+M>KOTQ=E_,[C9K/;[F\'_6E[?S\MT!E^M]_!W_1/?_O'V_E_M]?W\T]N;W6K8
+MK#;;U>A_]@W_S[_]-WTZZ$]O___.[]=<25][P?9GYG[^;GOG5]XE0__$MX[)
+MVSO7UFWH3V_W%_%#+V?Z"?GJZ*N]_Q7V;OZ$]-W/\\^O%__]7XV7__N1KA%M
+MG]]5?WU4E-][N[]Y?:O;M_OS=[3=_5]O=^:\>+NK^W.'WWYN?__J'MR^.OJ*
+MZG_EDW'SYWS_Y#^Y/T;N_Y/[:\[_7A'L?IKEQV\Z>_B[_HEO_WQ[_Z]?@\,\
+4^+>=X+`>O[_*/_X7*6^YQ%^G````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-ebr.qcow2.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-ebr.qcow2.gz.uu
new file mode 100644
index 0000000000..49e81529c8
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-ebr.qcow2.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-ebr.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-1x1-4096-ebr.qcow2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RY`0?S-@)H.TMM8/VM\:L^</RU&CX#T!%PME_0Y<U?Y>(_(V[D
+%[($4````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-ebr.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-ebr.raw.gz.uu
new file mode 100644
index 0000000000..7e048d0b50
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-ebr.raw.gz.uu
@@ -0,0 +1,11 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-ebr.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-4096-ebr.raw.gz
+M'XL("._%'50``VEM9RTQ>#$M-#`Y-BUE8G(N<F%W+F]U=`"ME,T.@R`,Q^\^
+M17?=P4`'TUV7[+[+MC.Z^10\_(KX`2*H"8!H4OK+O[:%,3L`Z%E=<8,N%T,7
+MYZ*G\>8PL.M6@1;7DA<=H*7D\$&+<0?'&2"/ZSNYN&_N<+MC0"E!J0#X&O6A
+M\1((3*WL<8.^E_Z<]`D#E!4("?(*->X-^/-XKZ5#\%S_S^)P"S<)YGMP%^/E
+MG'0K(V[0<YG8]X@3*76$8+]#P<K,M2?JA9^;9V#4)2VP>K"A#YSR"[.^6R@#
+MO7`3^B`,5QE<Y9_G#@XWP@4?UR1SFU9W"M6UF9,AEYVQLW,-Q.]<B\.\%P'V
+?-PM5()T*][A!/TM_6J`8@-G^H$`#+/YC5JB9E`8`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-ebr.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-ebr.vhd.gz.uu
new file mode 100644
index 0000000000..355a53439c
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-ebr.vhd.gz.uu
@@ -0,0 +1,18 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-ebr.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-1x1-4096-ebr.vhd.gz
+M'XL("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
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-ebr.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-1x1-4096-ebr.vhdf.gz
+M'XL("'@EAE4``VEM9RTQ>#$M-#`Y-BUE8G(N=FAD9BYO=70`K96Q<H,P#(;W
+M/(5RW3)PMK`,K+W+GJ7M#`1RN5[:I4,''KXVQL3&0$C/X!#G9'WY94F&,7,!
+MJ,_L6#9TR>3J=H==3^/5T\"VG04:7*V\U`(U2AHF:C#NX#@#Y,OZ]B[N'#O<
+M]CD@$91E`'RS^E!["016SCR7#=UKXM^C/J&!E($@(`DY;@WXX_@^EP[!8^V?
+MP>$CW"B8;\&EVLM9Z5;&LJ&[EXGYMCBQIDXA6/-4L!2Y]D0^\7/S#$QU20TL
+M'VSH`\?\PEU?$<I`+]P5?1"&6VI<YJ_G#@X?A`L^KEK-[;JZ?:BNCIP,FG;&
+MQL[5$+]S#0[C'@38GRRJ`M6J\+ELZ$Z)?QN@&(#1=I"&5Y%,0;8@&Y"DYYD`
+M64"6NT#T*ZFKO[^:^N?ZZV98X_CXY@B']L=4=XO,`$O])_*LYXZ^E^/E<+U=
+M+,X>5?9$4LVFO%($607ATJ39KOC9(T]W=6FX2>3N7B&!">#<"WQ0=_++F?IS
+HW@;;M%")?G_L\'YXAMFC2N.(3;S^FUN#DY%+1=7>[@^&L-RROP@`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-ebr.vmdk.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-ebr.vmdk.gz.uu
new file mode 100644
index 0000000000..5b1828d9ef
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-ebr.vmdk.gz.uu
@@ -0,0 +1,82 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-ebr.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-4096-ebr.vmdk.gz
+M'XL("/#%'50``VEM9RTQ>#$M-#`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Y(OTBPGR;GB_2+R+,MTWTBPCS;1/](L)\VT2_B##?-M$O(LRW3?2+"/-M
+M$_TBPGS;1+^(,-\VT2\BS+=-](L(\VT3_2+"?-M$OX@PWS;1+R+,MTWTBPCS
+M;1/](L)\VT2_B##?-M$O(LRW3?2+"/-M$_TBPGS;1+^(,-\VT2\BS+=-](L(
+M\VT3_2+"?-M$OX@PWS;1+R+,MTWTBPCS;1/](L)\VT2_B##?-M$O@O-M&_TB
+M)E/](B93_2(F4_TB)E/](B93_2(F4_TB)E/](B93_2(F4_TB)E/](B93_2(F
+M4_TB)E/](B93_2(F4_TBYCPWU"]B-M4O8C;5+V(VU2]B-M4O8C;5+V(VU2]B
+M-M4O8C;5+V(VU2]B-M4O8C;5+V(VU2]B-M4O8C;5+V(VU2^>\SPWU"^>;SY+
+M>!<53W=;[*8/+-'_YH3S'.U>"?>H+`[+T57^8CDV(9GT#?'U?:WI1NMRY]^6
+ML*JRKKM)^$^N;_TTX>VS56__CM^X?G/:_PGK6S\.LZK=Q\16EZPY'RWXIV]_
+M?%;PEL[L<=G2W7ST]/-T8<$'/LFZ+->/GA9/?3+B-ZY/C\EV9KKR2ZO3*<^Q
+M8HT_>KHLFV=QNL_KC&!X4C,\0Y:PO]G3^MK;99QWY7YA?3?(4I;N1Y!^^*KN
+MX@[K(N5F^W3]%_?VRZO[^G9U@_%F5,_?&0??N2[)_IV[I3O;`L%E199-.G'[
+>=_S&];O3_L^6L/0)S3I8N@].R[_Z/_V4$^TO7P``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow.gz.uu
new file mode 100644
index 0000000000..42ac08c42e
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow.gz.uu
@@ -0,0 +1,132 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 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usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow2.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow2.gz.uu
new file mode 100644
index 0000000000..8edc41a9ed
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow2.gz.uu
@@ -0,0 +1,26 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow2.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-1x1-4096-gpt.qcow2.gz
+M'XL(",]Q+ED``VEM9RTQ>#$M-#`Y-BUG<'0N<6-O=S(N;W5T`*V92V_<(!"`
+M[_D5I.\FS=8,8'O[2)JD62FWI&IOO?AYC-1KY?:WUQALUGC&)%MVD945FD^`
+MOQFPDR3FPYCB3*9,;EE;LOZW;<#V?LP;Z^YWMYO]3W=D8#PAHI`.*2;<C'7M
+M<$#A$K[LX#AN;W0"P<$8M02%<)(<W5H'@CLY&I9NN!FY%R$.`1H<>3,.&A^8
+M\?D1\L#Q0>SQ"7S]U!CG=Z3KXQ-F?'Y41N'R(`Z0J"V%*X(X@425%*X*XB02
+M55.X)HA32%1+X'A`E1Z7(E&<PD$0ER%1@L+)("Y'HBCO>-B[+1)%><?#WA5(
+M%.4=#WM7(E&4=SSL785$4=[QL'<U$D5Y!X1WS.$:)(KR#CSOCBWNF<.U2!3E
+M'7C>/;>X%Q..8U&4=^!Y]]+B7CD<4N^`\@X\[UY;W!N'0^H=4-Z!Y]U;BSMQ
+M.*3>`>4=>-Z=6MP[AT/J'5#>@>?=V<([CM0[H+P3GG?O+2MQ.*3>"<H[X7G'
+M+0X<#JEW@O).>-X)BY,.A]0[07DG/.^4Q:4.A]0[07DG/.\RB\L=#JEW@O).
+M>-YM+>Z#PR'U3E#>"<^[CQ;WR>&0>B<H[X3GW6>+.W<XI-X)RCOI>7=A<5\<
+M#JEWDO).>MY=6MR5PR'U3E+>2<^[:XO[.N$`BYJ\2Q*\6=S-(F<!J7<R?21N
+MM\31#RN''&>E.VYSY$IWK`#SIP/)O5::<TJ\"2LS86U5@5SICNYJ,_].P"%W
+MGP`<1SC'V0DKD[OF@;%I6-O:9E;*!F>M.R`@$S[>[.'JR.LWI-L3@$JQHE@`
+M?XSC&]*MSR_S;J"W6PW%0`%3<L(-<U75_OAN=K?L[O+;=PW[Z:8[I%M6L(JS
+M(F>%/SI.3?<W9I\RZ;9<[1$G*-QT+/-P^GB1U2LXK+'N#X&3:U'32X='W%N#
+M4\D\:K]LZ6VB%*PM6%$3N',/ET8V3^KN,F59Q=)&OT^J6OU'G>JG-);W:6*V
+M;1C.6%N6<7UVZX'=P_WFP<#.-K].[?@DMT9@C>Z@5D\.E3FGIINY!P%BNFR.
+MPUXC_=?JZ;I<JFBKM[6R8(WN(%>O,*N'+Y)>/31ENG'5QH0;<67<U>/F%6:B
+MZ_?R2G=T=YOYUP"E!48;H4S;*F)V:%S$[-"XB-FA<5&S0P,C9H?&1<P.C8N8
+M'1H7-3MZ8)/$V\0U3KM79*P&_9PX^W_!VG;<#8^/R^DVL+;UKVSB^,UH(F[B
+B&K>ZB6<-/5GS^>M--N(FKG%1-W&9Z>/WT3]QQ=U%%1H`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-gpt.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-gpt.raw.gz.uu
new file mode 100644
index 0000000000..74bb75e7f9
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-gpt.raw.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-gpt.raw.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-1x1-4096-gpt.raw.gz
+M'XL("-!Q+ED``VEM9RTQ>#$M-#`Y-BUG<'0N<F%W+F]U=`"MEDU/A#`0AN_[
+M*UZO&INVM"Q[,=%$$V^KT9L>^"C'3;SSX^U0D*^6N,E`0TB&>7;FI2^S4H8#
+M,!JRC%S3@>Y)+,_N<'OH::JZ#NA_GTI8`84'!ESM@U+3,\ZA;8<E59\5DF4+
+MK<;[`2>FXT;,<,V4M5GIP!PG`FYLM[T.:"W*<@/\'.O3_>NP,#G,"=H_+V$4
+MK(8U?[B^5UO/ZWM^><7Y\?V#8%]3NUKY8.7S&Y09W$HDJ9+M?J_;#3A-61NU
+M1UR6Q-W$<1EE-3NXV$KCS%Y6V$/_>[<!9^4RJYAG90Y5AK9$V21P#RM<SKSS
+M#(6K',<:N8-5J%NZ:7(H!13>)D4/T="^Q!.."KHB8'=Y$Y<`NQ<_=T-]1@T[
+M(K;2@91ZIM\J1:K=(^WMW7:QQ&7<ZA6DGF53[S1LEMA*!Y+JE4&]N$BD7M0R
+MW:C:Z)`15_&JI_JIX?WAO]_;:SK0G<7R#$`S`-DJ--J/#3YW$([1'81C=`?A
+M6-U!0$9W$([1'81C=`?A6-WA@4[R#7'"J3`FVP:%ALM6]:7&\53?LEVG]T;_
+ESA"/OPS'.,0)MS_$W;7-,@YQPK$.<>/_3TEY^`7C-"Q#B`L`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-gpt.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-gpt.vhd.gz.uu
new file mode 100644
index 0000000000..6a14b8db1c
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-gpt.vhd.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-gpt.vhd.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-1x1-4096-gpt.vhd.gz
+M'XL("-!Q+ED``VEM9RTQ>#$M-#`Y-BUG<'0N=FAD+F]U=`"MF$MOVS`,@._]
+M%2QVZS!#;R>7`2O0`KMUPX9==K$=IPN&98_VT(/WWT?*4FS9EK&T=%0CB<+/
+M)$61K(3H+P"GP>W!M>`LO2\-N"V4&P"<#$/YNPP?H6M^'MOF\?!4A*N[Z&%2
+MC*52<9)7&@P^I`15T4/<CMY#%S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G$N5^.'__;8>5SM5
+-[%^#W3\[9-S+LPT`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-gpt.vmdk.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-gpt.vmdk.gz.uu
new file mode 100644
index 0000000000..3fc6e7d715
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-gpt.vmdk.gz.uu
@@ -0,0 +1,87 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-gpt.vmdk.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-1x1-4096-gpt.vmdk.gz
+M'XL("-%Q+ED``VEM9RTQ>#$M-#`Y-BUG<'0N=FUD:RYO=70`K5Q=C]S&$7SW
+MKYC(#PX29,%:DLOE@X+8.3LP@@"*["0O>0@_XT/LDW(Z&!&P/SX<<FJN>'=S
+MI'Q]VM-NB]VUTSW+YJJZP"Q;?IPK6E<4KNA=>7(9W/1/R\-E^;TQ/8YG'KC\
+M^>HO?S_PY]>'P^6S!0P^2D*0*9P8J_>Y'![\$.[X7-3JP/0X;L+E/JI]%!C@
+MCHD#2;AB.GA\*H2K:^;#O7\A<"X"N15<^41.R62?6]UO/@O%\^O+_1JF[3W5
+MKLK=J0VF.Y6SG;OJ.!_+7#4YC1/@Y^[J^L-_W-7PH;N]?G_W+JSOZ/=V<BY.
+MWO_4>80IL>KD7_@#'J[V$*?!Y;W+X0^[R^TWUS\.AY^'VP_7[VY>@^D>_=X6
+MN2MJOQSOG]T_5H9_D\R=X-_#7?[X[=7K\,G-#N^;6\+YJ&DATWM/>2CNZ>3\
+M[^/'O+KAYLXCCN$GKL[O;2A..;]WX5^4A:MJ-R^G]-C'Z7`?4IYKU]T.S=WP
+M_<?WP^M7/[V[B;7S>^M+5L]`Y[E0N2MS#Q52\^4K/:+_V,R[YBX_7M_]<-U]
+M-Z7Y87AU^-P1[N1K-VW@.:QKR7H*.25W=EKVY>O_W4WYNC[L[#7AYD7,24SO
+M71Y=67FL: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V[W)-M1>51UJM#.MT_O7U\=A3S[9T?5YMP>1+N
+MBZ=.MF*^O?/8/P/WU",-5SP7]:EW`B_FVSMKE*IO73ZX-G=CXYH^`??[!W`G
+MXT_>?.?9]N2JSM\_N(3KYIL]]R=/2[OS=)HL__,[NF/OE0@5W-'?D?EPN?GK
+MX68!^]WAO[\-ZUON/(NG'^D#J>H5\UW>SZETJT3#7K=Y@<NMJ^>_K[2E6?7J
+M\&%YZI$^D*Q>LU0O<56;JO?4J3O!\:KVJS5<:UN]<KYJ+,*3QW^G#US>'-9_
+M%L`B`)JML/"W%+0[.SR<X=GAX0S/#@]G>G9X0,.SP\,9GAT>SO#L\'"F9T?A
+M;QAI=Q'W<%B^,5<G-U;^"\1J&<G+\>7P\_2]PO]\L4IWYAR3E_YG+N)/;\9@
+E>!'W<,]>Q,<AF2Q_'B1K>!'W<*87\<+?O3/[[/^_O`I!M&4`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-mbr.qcow.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-mbr.qcow.gz.uu
new file mode 100644
index 0000000000..5b9468b9fe
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-mbr.qcow.gz.uu
@@ -0,0 +1,127 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-mbr.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-1x1-4096-mbr.qcow.gz
+M'XL("+`S(E0``VEM9RTQ>#$M-#`Y-BUM8G(N<6-O=RYO=70`K9W+CAM)DD7W
+M]174^RW1S()DA-YH8`:87<]B9K;%YYH?H(\?E13AGFD\5U;=5:I$08(4%Z3G
+MT1&ZZ\ASO?[Y;;7:V&K8KH9I=3FLOO]X_K#5G1_<_UA]^^___*^W=[]]^^WG
+MF*U_\53Z\>"KF.?N;?UCW>;\CZ>.J_7T)^:^?QC-W7EU\2^\NCMO]G;NY6\_
+MWRP_YVKP_MM=S7/+VS5Q>L.?>WU?T]NU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4#WW_6GBKD[W[[]
+M]O+'X.;'VQU\M=[#O_5/?/O'V_O_M,$?5_W\"X/??Z-=+C>#RQO>_+CJY_LO
+M^/ZQW\S?^?ZQMCMO^(^O46SZ#3]X>V>.OI3R7SD_NIWG5X.;S6J_OQG\G^7U
+M^=_]Z?CQU\$WN]6P66VVJ]'_[!O^O__XW_2&?\[1EX__M\[OYUR)<WO!]F?F
+M?OSQ?>=7WB5#_\2WCLG;._?@;>BO@_<7\8>OSO03\M71EX__*^S=_)7KNY_G
+M'U^`_OO_UE[^<TJZE[1]?E?]]5&B?N_M_N+UK6[?[H\_(G?W?[W=F?/B[:[N
+MSQU^^;G]]:M[</OJZ$NT_Y5/QLU?'/Z3OW/_&+G_._?GG/^](MC],,L??XKM
+BX=_Z)[[]\^W]?WX.#O/@WW:"PWK\_BI_^W]F=\)"L*<`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-mbr.qcow2.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-mbr.qcow2.gz.uu
new file mode 100644
index 0000000000..fe4e0bce30
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-mbr.qcow2.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-mbr.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-1x1-4096-mbr.qcow2.gz
+M'XL("*0[(U0``VEM9RTQ>#$M-#`Y-BUM8G(N<6-O=S(N;W5T`*V8V;+3,`Q`
+MW_L5+LL%+E!BR4Y3E@O<A1G>X`%X3I=\13^>)%;C1)'BMI/6DVG'T1G9/E:6
+M+`L?8[PU+C=N8ZJMJ?]3`]/[,VSF^/O'SU7_<UP$F,V4**'#88<;L!XB#C1<
+M9L<=5L;ULD,!!Z>H,2B%<VIV4QT"[G;13EV[&`6+P&N``:<NQE7Y0<B/1[@K
+M\X.Y\T-Y_OPICG?DT_EAR(]'K35<D<2!$+71<&42AT+45L/MDC@G1.TUW"&)
+M\T)4I>!L0I4:EPM15L-!$K<6HE##N22N$*(T[VS:NXT0I7EGT]Z50I3FG4U[
+MMQ6B-.]LVKN=$*5Y9]/>[84HS3M0O#,1=Q"B-.^`>;<DW+.(JX0HS3M@WCTG
+MW(L.9Z4HS3M@WKTDW$W$"?4.-.^`>?>*<*\C3JAWH'D'S+LWA+N-.*'>@>8=
+M,._>$NY=Q`GU#C3O@'GW?N2=%>H=:-XA\^X#L;*($^H=:MXA\\X2#B).J'>H
+M>8?,.R2<BSBAWJ'F'3+O/.'RB!/J'6K>(?-N3;@BXH1ZAYIWR+S;$.YCQ`GU
+M#C7OD'GWB7"?(TZH=ZAYA\R[+X2[BSBAWJ'FG6/>?27<MX@3ZIW3O'/,N^^$
+MNX\XH=XYS3O'O'L@W&.'`RFJ\R[+Y$:XI]&>A7GO/UV\/[;"4>^8`!:7`*<R
+M#+C-K`/V8<"-!J5PU#N.]ZOAMP.VF^T"8#T_534"TH!]V&SU"74K/?VH6Y@O
+M&I[M7=&%`2]7/=Q^YOEK]\<%0.]-68Z`?T[YP=S+X1J@7S>;S.>F@','_._I
+M[]B_&C?;A@LX_>T`=70)VW-P[=N!WIE],_2.X;W>,N(FWPXTCSP'J4/-SL_L
+MGBM87'^=VV>U77RH97?*W?J:F)]06V`PW(G\S'BXS46\>]AFJ]@N0&*X9HC;
+M3J[M=';+<7:[F1?#\YUQYLYM(,.=&W`P;R&`MK+4!M9GC8]ZQ_'7:O@-0$?`
+1V6;0Y<VE:/$?-R^$K](4````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-mbr.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-mbr.raw.gz.uu
new file mode 100644
index 0000000000..16732e2015
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-mbr.raw.gz.uu
@@ -0,0 +1,11 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-mbr.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-4096-mbr.raw.gz
+M'XL("/+%'50``VEM9RTQ>#$M-#`Y-BUM8G(N<F%W+F]U=`"ME,NRPB`,AO=]
+MBKAUP80(Q[IUQKT;=8WU]"EX>(/I!8JM[0R04F8"W_PA!$1I`(8`W9=QWN'/
+M*NV^VE<?FGYN`]8(;9L!%0,%US".%[`YVTW84$,0SA^;1B#=S<7`J['M5(1[
+M#;MRFW?$."6X/MQV&]!:<"X#WGI]5#H=)@#M$8P%^P<UK0WX<;E/`A:<+G5^
+M@J-?N$&P7H,[A%W1ROAFS#O\>$WDW^/,DCI&X/^F8&WANV?JR;XXSX!<)0U@
+MW?DH!0[YA5'?*9=!2;@+^B`/UP7<,5VO(QS]"!=2W',QM\OJ=KFZIG`R[+0R
+L5E9N@*25*S@J^Q#0YV7A&\BK\G'>X:\J[0(T';#8"1H*P.H-:WH%_)0&````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-mbr.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-mbr.vhd.gz.uu
new file mode 100644
index 0000000000..aa12fb8065
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-mbr.vhd.gz.uu
@@ -0,0 +1,18 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-mbr.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-1x1-4096-mbr.vhd.gz
+M'XL("!$UQ%4``VEM9RTQ>#$M-#`Y-BUM8G(N=FAD+F]U=`"M5\]SG"`4ON]?
+M\3*]Y>#`$Y[FFIG<>VES5E?3G4[;3))##O9_+P@HB)@U15D6%][']W[*,F8N
+M`"J!!J`>2.IQ)8#NH*H!U*1M./7</L+8_?G==V^7]\)>X\F`<>9+A>):'DL0
+M:I,*L-&;T%F/870PQ9>'I]O+KR<'AQ8.+9"LM%2)0&VTCU"_UH:=1GJ\X,\)
+M\O['S*Z,V2U2ZE.=@0G@W%M1.G8*IO@;*BN4U#!,K0+63_9Q+7@()A9E5[:3
+M;"7ET=PR*EN4W8*C/:DC<+<GZPL3*BHP*M4S(`X5ZK$*&V>'J*E0>7]];EY>
+M^Q4_3(0*S?QX-%>FU44;*N@66P9"A_.>NC"AO*WA-D+EOZQ'H9RP`V4$)MT$
+M3NJ'UEN@P.='G.W8/.V,)+]&\U/)P)J-/CTQWA?A/0.V[3'`FAF&(=RL<-O-
+M"C=RT<@$R6),Y&F'W'CV:\^9_=L.QP"EA*:)`+\Y?EUN=_0:4)5/57TE08W7
+M*OSX\'TKW?I$]GZR6/7X$=Q,F%\#5]I2ZE;ZD9&>&)<P,=\.3NRQTRG<'U)6
+M9HZ]OE[)^7X&IK*D`U9[1<8#G/T+"[^[F`8&ZN[P@UC=1L-5X7KNP>$'ZD((
+MU^[Z=I_=3<RNR^R,89T95V:N!@DSU\!AWD*`4V51$:A6Q7UZ8OQ:A+<!1/OF
+MR/8J0EO[LC$4%C`;0^&*:3Z&)=L-MJ-12)9AIG,]I<O]9\[UY)7[#.=Z<N4^
+D)<4.G>O)EOM,YWIRY3[/N5[#93W7D_K'QMCI'_LT8,@,#@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-mbr.vhdf.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-mbr.vhdf.gz.uu
new file mode 100644
index 0000000000..7673a98c52
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-mbr.vhdf.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-mbr.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-1x1-4096-mbr.vhdf.gz
+M'XL("(`EAE4``VEM9RTQ>#$M-#`Y-BUM8G(N=FAD9BYO=70`K96]<H,P#(#W
+M/(5RW3)PMK`,67N7/4O;&0CD<KVT2X<./'QEC,'&@20]0"'.R?HB63\(82\`
+MA2"*&\]Y1?N:A'>[V6TZFBR?`^8"FB8")@RTN(IQO(&EH'[!(B08Q_G#(@6@
+M[-=6H$W&:YMXN--@%<N\PL<E%N?";9X#$D%11,`WYQ^NG0YE@)2!(B`-.3X:
+M\,?A?1*PQ<FUSL_B\!YN<%@^@DN-E;?3KXQY13N6B?UV.+7D'2-$_52PM'+M
+MJ7QBY^<9!'=)!2+O=1@"A_S"Z-\^=@.#<!?\@SC<PN"R<+_T<'@G7`AQY6)N
+ME[W;QMY5*R>#IIWQ8.<:2-BY%H?K#@+L)@M7(.^*G_.*]IB$MP6J'KC:"5+_
+M*M(IZ`9T#9K,.E.@]Y#E/A##2FJK[Z^Z^KG\^ADV.#F\.6(Q]IB:;M$98&'^
+M1)_,VO/OY7#>7:YGAW.CRDTD;C:V2A%T&85+DV:[X&>'/([>I?$AD7]Z>PU"
+M@91!X+UWQ["<J9OS+MBZ@5)UY^,D^!$H;HXJ@R,QL?IO;BU.KUPJ7'N;/\%5
+&,,:_"```
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-mbr.vmdk.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-mbr.vmdk.gz.uu
new file mode 100644
index 0000000000..de49d44930
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-mbr.vmdk.gz.uu
@@ -0,0 +1,82 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-mbr.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-4096-mbr.vmdk.gz
+M'XL("//%'50``VEM9RTQ>#$M-#`Y-BUM8G(N=FUD:RYO=70`K5Q=C]S&$7SW
+MKZ"EER`/"]:27)(/`A+G'"`(`AB68[^&G]$AMB2<#D$,[(_/##DU5[P5-;2O
+MY3V1H^VNG>[9JSM7%S;/US]95O9966;EF%67+$?F_FE]9'GQM'"/<\,GKG^_
+M^\>/)_[YP^ET_6H%@\^2%.0*)XO-ZUQ/S_X0[OREK,T3[G%.PA4^J[])#'#G
+MG2=VX4KWY/ES*=Q=MSP]^AN!RR)0MH&K/E/3;K%?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LZW3?R+X'S;QK^(
+MR=2_B,G4OXC)U+^(R=2_B,G4OXC)U+^(R=2_B,G4OXC)U+^(R=2_B,G4OXC)
+MU+^(R=2_B,G4OXC)U+^(.<\-_8N83?V+F$W]BYA-_8N83?V+F$W]BYA-_8N8
+M3?V+F$W]BYA-_8N83?V+F$W]BYA-_8N83?V+F$W]BYA-_8OG/,\-_8OGF\\2
+MWF3MP]T6N_H#RV5_ZZ>#WOZ]_\3UF]/VOPB(_K<!NO.>YQM`%ES"O_=<@'MT
+M5;AQC]69)@>!_8*_/@G<:-P_S+\-L*JRKKL!_"?W=[8^CN7S-:O:?^YL=<F:
+M\]&"?_KVQV<%KW!F[[\5[N:SK)_#Q0T?^&CLLEP^RUHB]9VQ_\3UZ6VR7@E7
+M?FEW.C8Z5JSQ9UF79?,L3\]Y&3H,3_:(9U05SS=[VE][NXWSIMPO[.^&JLK2
+M_TS33W/54]R0YTZYV1:N_^+9?GEW7]_N;C`^C.KY=\;![UP/LOW.7>'.MD1P
+E69AE]6+<_KW_Q/6[T_:_%;`,@&8=+/TGL>5?_1_0^/1A@%\`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.qcow.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.qcow.gz.uu
new file mode 100644
index 0000000000..a8fe3f7b76
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.qcow.gz.uu
@@ -0,0 +1,125 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-1x1-4096-vtoc8.qcow.gz
+M'XL("+,S(E0``VEM9RTQ>#$M-#`Y-BUV=&]C."YQ8V]W+F]U=`"MG=NN&\>2
+M!=_]%=3]+C$SFV2W[C@8'&`>!CB#^0'S^DS,LSY^).WN*NUD+.49V+)@2!!J
+M@;L4#AAVH+1>WWU;K3:V&K:K85I=#JOO/Y^_V^J7G]S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]4?Q>I
+MOX,Y\IWJ[R+U=S!'OE/]W;#\(,U][7/@NT'U=T/J[[XN<YT[\-WW4\S=D/J[
+MKS-W7Q?NAC6?$G_N<?IBORZ]\=LV1W_>=CM5S/WR[=L?+W\.;GY^OF&[VOEJ
+MN_GQ??#5)E;#\.-_7:Z&DQK\Y_^>S__XG_\8_NO>Y]O\_9_O_C^W]OO!<;6>
+M5FO'P;NY7_ZYG<JYWWV^NSGZ<Z/_PAS]N=$X]T-/W_^-X[OCSVGNSU_FZ,^-
+M_BN_&;?/./W\]XH?;P6.]>"#7P;OYGY\N7>'\^^PJ;GOO_#MP<WGNYOK7Z[_
+M<L3OS1E]NA^/&ZYNYKJF\F<L;N\!?CK0U%]`A9YQXKG3?G4X_WS2[G(S]_#+
+J//?S&:<?4MK#W_4O?/O7V_M_W:$RS(-_&WO#>OO]4_[Q?X8;4W9_I0``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.qcow2.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.qcow2.gz.uu
new file mode 100644
index 0000000000..c7b9836521
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.qcow2.gz.uu
@@ -0,0 +1,21 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-1x1-4096-vtoc8.qcow2.gz
+M'XL("*@[(U0``VEM9RTQ>#$M-#`Y-BUV=&]C."YQ8V]W,BYO=70`K9C;CM,P
+M$(;O^Q3N<EY@B6?L-.&PP.ZR$A=((%Z`IG$?@.L^/$[LULED)BY5VK129?V?
+MQO;7J=.B"`^EK%:F5*96^T;YS_$"-?@POM3AU^/WF^'CL`HP70@I9L#@"3=B
+MW2<<2+A"3P<TCQM4APP.CJDI*(<S8G5S`PSN>M4O7;\9%4G@)<"`$S?CHOH@
+MU$<3YL+Z8.GZD%\_>\S1@7*^/@SUT=1&PE59'#"I6L)MLSAD4HV$VV5QADFU
+M$LYE<99)[06<SJCB<263TA(.LK@-DT()9[*XBDE)WNF\=S63DKS3>>^V3$KR
+M3N>]:YB4Y)W.>[=C4I)W.N]=RZ0D[T#P3B6<8U*2=T"\6T?<5<+MF93D'1#O
+MGD3<TQ-.<RG).R#>/8NXYPG']#N0O`/BW8N(>YEP3+\#R3L@WKV*N.N$8_H=
+M2-X!\>YUQ+U).*;?@>0=$._>3KS33+\#R3LDWKV+K"+AF'Z'DG=(O-,1!PG'
+M]#N4O$/B'4:<23BFWZ'D'1+O;,25"<?T.Y2\0^+=)N*JA&/Z'4K>(?&NCKCW
+M"<?T.Y2\0^+=AXC[F'!,OT/).R3>?8JXVX1C^AU*WAGBW>>(^Y)P3+\SDG>&
+M>/<UXNX2CNEW1O+.$._N(^[AA`,N=?*N*/@KXKY-OK.P[/G3I/.Q9M[E@1E@
+M]3_`N0H#KEYTPC9,V-\Z;D"5MKN\$A:[G?1-1)E6`C[^=>[N]X/Y,:S/+GU#
+M8-/Z%=PR4535'\=!6C\[6K\ZB\MLAPT'LT6F&W#-N3C_X^*/]JU3SA'<GP%N
+MM_!FZ,ET77?R]\>IZ@S@>@`,N&ZZ(4QWF/EOX#BL#NM)?0&7I@N#"(QPFJO.
+MGQ;[UQC7)IRF/6MVLFNV.K>H*GU?/@O7;E7CNI-MLYG@KHZXOB_[`Y"_:9V^
+;RP.'GS?C9U#%1.!B[IFR:U2K?VQQ7;KP$@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.raw.gz.uu
new file mode 100644
index 0000000000..d10e5c4c25
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.raw.gz.uu
@@ -0,0 +1,10 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-4096-vtoc8.raw.gz
+M'XL("/3%'50``VEM9RTQ>#$M-#`Y-BUV=&]C."YR87<N;W5T`*V230Z",!"%
+M]YSBX=(%:8=296N,.Q,3+R#8>@#7/;QMA@0*Y<>$H73S>%_F,2,$%Z`T3@1=
+MA:,(50FE4"HO&'A]>N!N7VLOSZNZ%UPN8YCT8M(BE@17C,IEQPYXCGQR&7B&
+MJ"$H"61<W;OJ5=Q2?XQK]HK+N'8K3OO;P%A8.\*]!KCWSL.0D[@6?N`DPY]<
+M!>;CN#+$9?-XPK,X+[A\TA_C^K@TL%"$DZGN4/`;XTR/DW^M2I[LSNZZ*O*S
+M%6<:M!9$*/4$=]`=CH*K\M\WB7M><(\B?GA55`?<;?<4!6#V`]&)2;VR!```
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vhd.gz.uu
new file mode 100644
index 0000000000..eee85fd977
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vhd.gz.uu
@@ -0,0 +1,17 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-1x1-4096-vtoc8.vhd.gz
+M'XL("!@UQ%4``VEM9RTQ>#$M-#`Y-BUV=&]C."YV:&0N;W5T`*V634_#,`R&
+M[_L5!FX[3(F;IML5`3<D)`Y<2==L3(@/`8<=QG_';I.U:9MM0+HL2I?ZZ6O'
+MSB)$<P'H#/0*M`6=\[A0H!=0S`%HTC6L>^EN8;=\>[7+K\UVYJ[=I(%)T;4*
+MS=D>,U#TD@+0\$MTQ6/8><SLXGH]W;RL/0X=#ATH+]@J0]#EX#V*?ITWZICT
+ML,'G&GGYM%>7#=6U5O0M*A`*I.P\D7EUA)E]A\XJLEJMZE:`L'5\?`MN@HG6
+MV5[L<M&SZL@<"ZIHG1W#Z4-6O\%-)VXMFE2AQ"BH%Z`E%,AC2AL?AT&C5-E^
+MOIN/3]O3AY%4T7M]<C"7Q=U%ERKH'W8*%*?S(7>AIGSU<2.I\J_HZ=!.N0$%
+M0>1^`FOWP^BU*.CJTU(<B'E\,:+Z#.M3FE>4=X&<"R.G8E604?Q4%7/XYL/:
+MR_LK=1O&ST16]\_Q,_/`[DAU4$4O>->(IHM9M%:+_Q>;,:G<;7#EJ3@J<E%!
+M9<':'NZQ@ULF7HQRX*[E3$99)\LQX)GJN5NRNXUQ?X5E#,<;:0L*<:V[V#'!
+M`#?87%@=[,NLBZM:7$_CD>B%^CS.)DV5<G4JKC)06D`<VT;//6[)5O1'),Q(
+M'Y_8W<W"3Y,JZ/:59!L5IE:H'#"90@+:Q`JE.)@9OZU?[10F.O4Q+N&ICW$)
+A3WV,2WCJ8US"4Q_C$I[Z&)?TU*?KW)O\`()N%&`J#```
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vhdf.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vhdf.gz.uu
new file mode 100644
index 0000000000..77e1491537
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vhdf.gz.uu
@@ -0,0 +1,14 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-1x1-4096-vtoc8.vhdf.gz
+M'XL("(@EAE4``VEM9RTQ>#$M-#`Y-BUV=&]C."YV:&1F+F]U=`"ME$]+PS`8
+MQN_[%`]X&1-*_K>]BGH3!AZ\VJ[I&$,%\>`A']YDR6S39'5(T[2TO'U^>9_D
+MY27$#T`HE`Q*NBD8)(<0X-(&.MAX.F$>/[6^>[Z73X4?9N5AU`:S$C(7,,5D
+MF-4F`*M(1^>!%4@-PK)`CZL'5?TG;BX_CVN6LNMQ[;4X99\=.@VM)[C7$6ZW
+M\&'0Q*Z&/7!6705<3^U29]>+IR=,+^%LP*R3_#QNL,M&$A;A:"X[%/Z.<=V`
+MJQ+5G-EU-CN]:*G0_EI<UZ#58"VX2G"W*N"84TG[?Y-Y7@Z8;1%?OE1$`"Y6
+M>S(T*L6A>BA]ZE4<I8"J459C((N.&6;W\:YW7X?O\?[)T*CZ/C^=GMDF:!<I
+MP1JWB.K<^RB_FX?]YO"V/^-8<,7"PK)T*FZ[:IO8E;'=EP,[GI#;(3N>;I(<
+M[UZM0`0HC8R'[+9QL3B<^#6K>[3BM#_G&7U$@6SM.9PD$]7_2]GAU,*E8FMO
+*]0/Z[P?!W08`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vmdk.gz.uu b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vmdk.gz.uu
new file mode 100644
index 0000000000..cc0886214f
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vmdk.gz.uu
@@ -0,0 +1,81 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-4096-vtoc8.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-4096-vtoc8.vmdk.gz
+M'XL("/7%'50``VEM9RTQ>#$M-#`Y-BUV=&]C."YV;61K+F]U=`"M7%UOY,81
+M?/>O&)Q?#@D@L);?#P<DCFP@"`P8/B-Y-3]C(?;=02<$,;`_/AQR:E24Q!O"
+M:F5E<FZ[:Z=[5B6ENK!9MGTY5_2N*%PQNK)R&=SR3]O#9?GC8GE<&CYQ_<?M
+M]_^\X=?;FYOK5QL8?):D(%,X6>Q>YWKSY(MPER]E[9Y8'I<D7.ZS^F>)`>YR
+M\,0A7+$\>7DIA;OKUJ='?R-P+@*Y'5SY0DV'Q7YI=W_Z*C3/[R_W>UB.MVI=
+MG;NJ#TM7E>LZ=_5E?2YS]1(T+X!?N]N[S_]QM]/GX?[NT\/'L+^+/]LEN*A\
+M?#5XA*6PNO(W_@D/UWJ(:G+YZ'+XI]WU_KN[7Z>;_T[WG^\^?G@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q&SJ7\1LZE_$;.I?Q&SJ7\1LZE_$;.I?O&199NA?O#S[+.&3<,^+W?R!
+MQ;J_HN)GNI;^DT++]5-#\]+YCS\^`/SN?IJ^>7];?K_;7V&_OV:7AR\#-NM(
+M\W)XND76/F:U2;@O[6^#ZZS*W>#ZLW#;V&6<W#0]@?M9X`;CP\"S<J?UIZ`Y
+M!?CV:;GPY<;/S]Z=,([@_">GOGVVOPWNL5S]:;OLX/#2[L*/[!.X\1&N>9;U
+MI6+?OKB[R?2M@ODLW-BY?G*7WN75,[@_5P%N_5CL;5+__+_'3UQ_N-G_;WNK
+5%`'0[+U7^,]AS;[Z/YH4:2:>70``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-apm.qcow.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-apm.qcow.gz.uu
new file mode 100644
index 0000000000..4cb0a13efb
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-apm.qcow.gz.uu
@@ -0,0 +1,127 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-apm.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-1x1-512-apm.qcow.gz
+M'XL(")XS(E0``VEM9RTQ>#$M-3$R+6%P;2YQ8V]W+F]U=`"MG=F.'=EQ1=_[
+M*RYGLCC=B,B1LP2Y`3\8:%O0LY0C($"V$[(`O_#C7<4Z0U7<O1F4NZE"@T0A
+M-[).+:X6I,7#\_GVQ^G4RJGI3LUXVN?3]:_3AYSN_.+^Q^GKO__\KV_N_OCZ
+MT^V8G+_SE/MUHR=)<_>V?E_G].:IY70>?V#N^@/.W7D[^R?>[LX7>SEW]=/M
+M%XN?4S9H]P9/:>Z<WD_(Z34_]GY?W)<KMZ?WVWVY2K[<E@UV]P9_27-_2>^G
+MY,OMV=QP;^YP7ZZ2+W=D<]-W85$"R\SFEF"N@4^M;&X+YEKXU([GY#O?V]NY
+M#CXE;$[AW*G,]?`I8W/-O;GSFPQTGAO@4X0[";D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=?__'7__ZO/^>YFW]?
+M=.O-P_T_\W;_.1WP[=#?5_YKOK?-#WYO<Z*1?^?>_][FW[DM^K/EO^[]OGT[
+MNIN#O_Y&7'\T>FKMU#0W?SSBU+8WGVOM<O#GOV_;[__XA]=_^OF/=\\/_7'P
+M7_5^W0^<G]XYO]O?)'?/[W3W_="?W?IU[_?=\^OMU/>`S7I^__._MR#F]_NM
+HSV](YW>>P#_Y)[[^\N;^?VX'FS3XF[UA<[[^!I]_^C_<Q@LX=*8`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-apm.qcow2.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-apm.qcow2.gz.uu
new file mode 100644
index 0000000000..582b310d59
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-apm.qcow2.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-apm.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-1x1-512-apm.qcow2.gz
+M'XL("(\[(U0``VEM9RTQ>#$M-3$R+6%P;2YQ8V]W,BYO=70`K9A);]LP$$;O
+M^15,]Z9-*LZ0E-P]FX$>"J0->@Z\R$"`+D8:H!?_^%+6R)2I&3$VY`A"#.)[
+M&`^?QZ:SK'XH9;4R3IF16DR5?TX7J-:3[4NMOHV_G+0?JX,:IC,AQ2P8W."V
+M6.<!!Q(NT]T%S>-:U2&#@R;5!:5P1JRN;X'!'1VL6[?>C")*X#[`&B=NQE[U
+M05U?G#![U@=#UX=\_VR3BQ=<?WU8UQ>G<@E7)''`I$82;I+$(9.:2KA9$F>8
+MU%S"E4F<95(+`:<3JGB<8U):PD$2ES,IE'`FB2N8E.2=3GLW8E*2=SKMW81)
+M2=[IM'=3)B5YI]/>S9B4Y)U.>S=G4I)W('BG`JYD4I)W$'EW2+A'`;=@4I)W
+M$'GWF'!/-CC-I23O(/+N*>&>!1PS[T#R#B+OGA/N1<`Q\PXD[R#R[B7AC@*.
+MF7<@>0>1=Z\(]SK@F'D'DG<0>7?<\4XS\PXD[S#R[@VQLH!CYAU*WF'DG28<
+M!!PS[U#R#B/OD'`FX)AYAY)W&'EG"><"CIEW*'F'D7<YX8J`8^8=2MYAY-V(
+M<&\#CIEW*'F'D7?O"/<^X)AYAY)W&'GW@7`?`XZ9=RAY9R+O/A'N<\`Q\\Y(
+MWIG(NU/"G04<,^^,Y)V)O#LGW,4&!UQJXUV6\1?A+COO61CV^Z<)WX\U<Y<7
+M>H#%+L"^"FO<:-`7;.L7['?`0CA'9>M/R*(7>/F]PAQNUV>'/A#86A@_F<V\
+MDT/IP.<75E=?F?[96AC_=O#3U%]NIIQ]4'VGR^7/DL')I]O=CU,>A]WJ[&+]
+MOY<E!Y4;Y49T=POERFJ9JKM93N[N;^]O__R^:7#5!Z2;5^%\E^I^399L=7;@
+MO34/W-MFJ@`!M_=6-?69H=TSZ^UP5>/]1OC+CTN+U93S7S.4M=6:Q2YP?%>6
+M9]<7QS_&U^W^F6%_;+#^1)7N'[3Z5[])VOU3[?K<T/USO?W+4>4YXV;HW]]_
+HM8A-?4/WKZ#^^9-Z]RXOK*Y.MO]JH"'@8!4:5TWG@_\+*`W"Y1,`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-apm.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-apm.raw.gz.uu
new file mode 100644
index 0000000000..77ba55fac6
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-apm.raw.gz.uu
@@ -0,0 +1,12 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-apm.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-512-apm.raw.gz
+M'XL(".3%'50``VEM9RTQ>#$M-3$R+6%P;2YR87<N;W5T`*V3S6K#,!"$[WZ*
+MZ;50(\DKJ3FFM+D50D//P=0.!-K4I(%>]/"5(HG(/PDN:+T(BV4_QK-KQGP`
+M)"$%F$T64G`PPN4^2)B7M]+&71G#%![&V8VNZ[AR$*:X]T#ARI*!FE%?E0)Y
+MOV#6KT.@QSE]Q*&92_4!)6?I6W;=9SN!$[D^U^.JL3JY.[]S0`MH@EJ$4^V@
+M6E<.ZK9=?3SM3_OOPS;BR.)4XYKU?]1]U=VD.IEYMC1SMA27,@#[LT741[EW
+MC\[C4,YX.PB;)"`K$$$T5KAT-7L?`5?'MGW:/#^\KS:I?T29]:D9_HG$/_^3
+MI/XAU:=R^Z=N^J<K:#VQFQ?_?G[](D9]N?U[#/ZQ>N*\7C#KLO]X(`5@-H4D
+,'+#X`^%)]I"G!0``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-apm.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-apm.vhd.gz.uu
new file mode 100644
index 0000000000..aefb2775ef
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-apm.vhd.gz.uu
@@ -0,0 +1,19 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-apm.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-1x1-512-apm.vhd.gz
+M'XL(".XTQ%4``VEM9RTQ>#$M-3$R+6%P;2YV:&0N;W5T`*U6R6[;,!"]^RNF
+MZ"U`#7)$CM)C@R:W`D&#HL=`E:E4:),8L8'FX/Y[.5RBC1)LES)-D*;GZ?'-
+M0@KA'P`J@!H@`Z1Y7"J@CU!>`MC%T-#U,DSA4#\_F7K?OJ[#<UAY,"GZ5D-S
+MML<"E'U)"5CQ2VC#8SA$F/7[ZX>+]O$APF&`PP"D2[8J$.C'Y#W*_GKIV3'2
+M]Q9_.<BKGV_LBBF[SLI^RPT(!5+V_E%$=A9F_7>X666MFL:U$H1Q^L0VF`P6
+MNLV.M--B9-6CF1)5=)M-P=&2U2EP%ZO@"Q\J-C!*VPL@"27RV(9-U&'2;*B\
+M[K;5R\Z,^.%,J-`;/SE9*^:WBR%4,/XY,%`<SDO;!8>R'\,E0N6_U*.AG0H#
+M*X+0<0'=]H?J=5#0YT=2+&@^[XQ9?A7SLZFIL<LVIB2A6-3O^BO#O%,C_:H9
+M[YZM7\W+-D/4)A45W62<N[=?DN%2,S\E.8PYDFN.X6/X?=IN?YL$'.;:KH<K
+MINQT$W+.)9TOT:[WI5LWD=V]S;9]NV^?G^XC'!<J+K4.\7AVC]4VR4YG]JTY
+MTK<Q:3``#GT+D9_)'7O&N8-8>#XA-1\:VAYD"G!CB6M>L_,)X,V+,5=WGS]\
+MN[GKZV=47GY2'*$?]O3S2=+7KU];Y-PA?CZ_1?WX,"D3L=GIM_OC`S'RRZT?
+M!OU$E>CG%PZWZ^''`V(HIMFJ,W;5+P]#%0"S,51=#N=B*&G1F:=ZF0+#3%==
+MFJ\RYUQU&2[C59="R9JU$B===2F4K$Q778;+>-5EN*Q777(%=?4/V&/DOA\-
+"````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-apm.vhdf.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-apm.vhdf.gz.uu
new file mode 100644
index 0000000000..42912413e9
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-apm.vhdf.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-apm.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-1x1-512-apm.vhdf.gz
+M'XL("%4EAE4``VEM9RTQ>#$M-3$R+6%P;2YV:&1F+F]U=`"M55%KPC`0?O=7
+M'.QE""MM<DGT<6/Z-BB3L4=QMI6RJ<4)VT-__')-LJ:VBAN)1V@X[^.[[RZ7
+M.#8+``4(!K&VV!J;T-Z>3PSJV7.DUVWD5CTR8,FEJ/-PT<FJ1V,#R,@M8L"L
+M%\=]P*3KJ-.G4T`#1_PP`163R35(<16_^ZKZR`?@6*AT#1SOLQ-%\YT`*`8*
+M04[M+@N0.;DMNV6U.AS+8[G?+1T<:CB94;#Z"[OMJAID)P+7%J^L+;JFM(#=
+MVH+CAZ%[#YMR2!)>%T(;,A`<$(%EFK@@GS[W`.>'/']8/-Z]S!>^?HB!^<DK
+M]&.>?N:2^/J!ST^&UD]>U$]Q4&J@-UO]/K],(SI^H?6;6/WBU<!^WE&G4?=G
+M`-$"!F,H['26W-YU$I&[&3#Q`5E;W@9PO=_EZV/Y[=]@8:=S40P;Q3-.;X%4
+MP%;-B,GHV^-W,]N,R^W&P;GIYQX.H2B*ZW*_]=(5W71?2_;>0*8M.]X72?CJ
+M327U<I)T$K?L4E\]`X>_R>8%O&&CC[/.H>,8G,T$UTP__\__K:V!DX%;13^4
+*HQ\K>!7WT@<`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-apm.vmdk.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-apm.vmdk.gz.uu
new file mode 100644
index 0000000000..a08b7a8b1e
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-apm.vmdk.gz.uu
@@ -0,0 +1,82 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-apm.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-512-apm.vmdk.gz
+M'XL(".7%'50``VEM9RTQ>#$M-3$R+6%P;2YV;61K+F]U=`"MG%MOW,@1A=_]
+M*PCORR)`!)[A_<%`UI$-!,$"QGJ3/&YXC878EB`)20S,CP^;[-,ZE$0WL2IE
+MM)SR5-5T5X]*RE<'3-/U*TGR+LGS)!^2HDQ2)/,_K8\DS1Z,^7&J^<+YKY<_
+M__V"7S]>7)Q?K<G@HB0$J:838_,^YXM'7TQW^E[4YH7Y<8JFRUQ4]R30ISOM
+MO+";+I]?/#T7PM6UR\N#>R+IDI`HV:0KGMG3[F:_M[H_O/+%<^O+W!KFXRV;
+MI,J2LO-F4A:+G275:7DM3:K9:9H3_I!<7MW].[D<[_K;JYO[:[^^DSO;V3DO
+MG7_9NPSSQJK2/7$ON'2-2U&.238D&=S+R?GV_=7G\>(_X^W=U?77-^!V3^YL
+M\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O>[VJL.3N$P38OO"^<//S]4O
+M7^[7FR^W-76W,5WOUWM@?3_=W'P>GTGWY%[,OW>[:[KLZ>J*R=_H=[ES9\Z[
+MY?*>PL7$U?UVT][>7]U?77_]C>F6^_4._C:NQU?WI;UY=G7&]V+.\X-G2R)R
+M\@FW9YMP?=;W_LSSY3A*WN^X<'?1+98[ZIZ&>>&%>ZW(GB9\?SN.;S]>_O%O
+M[S]J_?+<>'WE@?JI%&[](='Z);H^:^UQ7GZW?E665-4SG\V'^MW]=_T@<GW6
+G]:M]_=S]G9_\=_^%\X>+[?_6A+E/:+;"W-U\-GWU?YW"XEV37@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-bsd.qcow.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-bsd.qcow.gz.uu
new file mode 100644
index 0000000000..9aa89a68dd
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-bsd.qcow.gz.uu
@@ -0,0 +1,125 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-bsd.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-1x1-512-bsd.qcow.gz
+M'XL(")\S(E0``VEM9RTQ>#$M-3$R+6)S9"YQ8V]W+F]U=`"MG<N.&TF21??U
+M%=3[+=',@F2$WFB@!YA=SV9F6WRN^0'Z^%$I(]R5QG-E:G2I!$%"*BY(SZ-3
+M*-6!YWI]]VVUVMAJV*Z&:74YK+[_>OYNJY]^<?_[ZMO__-=_O_WYV[<_[L9L
+M_8NGTJ\'7_D\=V_K'ZLVYW\]=5RMI]^8^_[=:.ZG5Q?_QJO[Z<W>SKW\X^[-
+M\G.N!N/>X&J>6\^OS\3I#;_W^KZFMVMWI_?WO5T7;W>C!K?W!O\US_TYOSX7
+M;W>GYL9[<]?T=EV\W4G-[7\)BPM8#FKN6,P-^-1)S9V+N0T^=>$Y^\7G]FYN
+MBT^9FL,_MV]7;6Z'3X6:&^[-K=\N0"]S(SXEN+.2NPF?$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1_OV_QI:_<$\W5[;/[ZJ_/HJ8[[W=7[R^U>W;_2'1
+MW?W?;S_->?%V5_?G#K_\W/[ZU3VX?77T1;S_DT_&S=4AO_DG]Z^1^W]R[^;\
+C[Q7![H=9_O+<'G[4'_CVK[?W_[D;''X,_O'_LNY7-X&E````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-bsd.qcow2.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-bsd.qcow2.gz.uu
new file mode 100644
index 0000000000..e8d783dcb9
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-bsd.qcow2.gz.uu
@@ -0,0 +1,21 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-bsd.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-1x1-512-bsd.qcow2.gz
+M'XL(")$[(U0``VEM9RTQ>#$M-3$R+6)S9"YQ8V]W,BYO=70`K9C;DM)`$(;O
+M>8I9SZZ*F>Y)2#RLNNM:Y9W>Z#6P\!0\O!NFR22=_C-(!5*IHH;_JY[,EV9"
+M4<27<Z5WH7*A<?N->_PL![G>A^'A#K]__%SV7X=%A/D"I(R!P!UNP+I+.$*X
+MPH\'O(WK5<<&CDZI,2B'"["ZJ0$#=[TX7KKC8M0JP9<`(PXNQD7U4:Q/)\*%
+M]='<];%]_<I33@]4T_5QK$^G5@A79W%DI!J$6V=Q;*0V"+?-XH*1>D"X7197
+M&JD]P/F,*H^XRDAYA*,L;F6D&.%"%E<;*>2=SWO7&"GDG<][MS92R#N?]VYC
+MI)!W/N_=UD@A[WS>NP<CA;PCX)U+N)V10MZ1\NY*<$\2;F^DD'>DO'LJN&<=
+MSELIY!TI[YX+[D7"&?V.D'>DO'LIN%<)9_0[0MZ1\NZUX*X3SNAWA+PCY=T;
+MP;U-.*/?$?*.E'?O1MYYH]\1\HZ5=^^%522<T>\8><?*.R\X2CBCWS'RCI5W
+M++B0<$:_8^0=*^]*P54)9_0[1MZQ\FXEN#KAC'['R#M6WC6"^Y!P1K]CY!TK
+M[SX*[E/"&?V.D7>LO/LLN)N$,_H=(^^"\NZ+X+XFG-'O`O(N*.^^">XVX8Q^
+M%Y!W07EW)[CO'8ZL5.==4=B'X.Y']RS-N_\,:7_LC3,>F`#6_P.<JC#BFEDG
+M7,8)MQJLC3,>.-PNA^\.>%SA<M6N:EFYFLZM\._]G_&$RQE7..+PXZ@,=`7[
+M<W#'Q]'>-^O^Y@(.##<75PDW^3C:[K%WU@"LKIQ9%JI5KK_.KMD?'U).W5UM
+MS;KU=:D^0V8:3'>B/C>>;ONKT3W=J55L<929KAOB-I-K.UW=U;BZ[<R+P?K.
+M.//.;2'#.S?B:-Y&0/%_J:+]UOB,!PZ_EL-W!`8!SG8%0]7VOL4_.5!JJ4,3
+"````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-bsd.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-bsd.raw.gz.uu
new file mode 100644
index 0000000000..03c68950af
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-bsd.raw.gz.uu
@@ -0,0 +1,10 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-bsd.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-512-bsd.raw.gz
+M'XL(".;%'50``VEM9RTQ>#$M-3$R+6)S9"YR87<N;W5T`*V4P0Z#(`R&[SY%
+MO>Y`2H7IKDMVWVD[.[,]!0\_4%0J`UU",22D[9>_U((X&8`BP/['GG:8J^#+
+M5*=JI)$#ZA:4!GV&SH;C^K$#<YCG[2%",QXG<UEIG-C8C*,]W")8'L$U+BN(
+MM&I)+KB48\+5GE6O.)539Q'X_JM87>KNYMYVF[RPSX`?P`&P\S[BP*6_L.J[
+MQ#*(E9O1!W&YO<.U/%X&.-HI%SCNE>UM7ET=JQL*-Z/93L;!R740/KD3CLH^
+B!#2^+/8/M%'QGG:8N^!K`BH/+':#BARP^@+33Z#K!04`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-bsd.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-bsd.vhd.gz.uu
new file mode 100644
index 0000000000..effc86fb99
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-bsd.vhd.gz.uu
@@ -0,0 +1,17 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-bsd.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-1x1-512-bsd.vhd.gz
+M'XL("/$TQ%4``VEM9RTQ>#$M-3$R+6)S9"YV:&0N;W5T`*V736_#(`R&[_T5
+MGG;KI`@<`MEU4N\[K><T3;=JVH?6'GK(_OOL!%+(U]J-A%)2\)/7QB`J1'L!
+MZ!3T#G0%.N.V4:#OP>0`U&D+-K6TCU"7'^]5>=R?$GO5BQ8FA6\5FK,]IJ#H
+M)0:PX)?H+;>A=ICD=O6\W+\].QQ:'%I09M@J1=";P7L4_9JWZIBTWN-K@WQX
+MZ=2E0W5G*_J8+0@%4GHC4J>.,,EWZ*PBJ]VN*09$U<3'E>`AZ#@[VXM=)GI6
+MGLRQH(JSLV,X/6=U#6ZYL'/1I@HEAJ%:@)9@D-N4-BX.@T*I<CI\%E^'JJ</
+M)U)%=_KDH"^==A=MJJ`;;!4H3N<Y=Z&A'/NXD53Y5_1T:*=L@X(@,M>!C?MA
+M],XH\/5I*69B/CT9D_H*UD>+010C]71'_9"$=P<L&4CKE99[IB''2R.X7CV-
+MS6\YD2Y_7!TE_H;K!,M+<*E=NVYDJ@"[W7*RH\&IFQ;%WPZGYM1QSE17.9M%
+M3N8R[]GY\PRX`5&"R+VL]H`\OW<VGYV^^Z$,#-R=T0=#=PO&F7"\]'#XB[L0
+MXC:S<SNKSLVMCRLC3\:VOS(N7+D,"5=NB\.X&P$V.PME((T:UM,=]6,2WBT0
+M[585;>]#MU7%4J@L,)I"`E:1%6(UFVS79J&V"B,=)!D7\2#)N(@'2<9%/$@R
+;+N)!DG$1#Y*,BWJ0U/0708C%#^STEH1]#```
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-bsd.vhdf.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-bsd.vhdf.gz.uu
new file mode 100644
index 0000000000..c4adfecd68
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-bsd.vhdf.gz.uu
@@ -0,0 +1,13 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-bsd.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-1x1-512-bsd.vhdf.gz
+M'XL("%DEAE4``VEM9RTQ>#$M-3$R+6)S9"YV:&1F+F]U=`"ME#MOA#`,@'=^
+MA:4NZ`:4F"3`6NEVIG8&"B=4M5TZ=.#'-P8",:^[5H0H`CG^\%N(80$H!%%L
+MG/N"[CGB3Q=<@IZ&!-0)*`W:0&JOBWFS#R;H7J\OD;^Z$2>/M/9QT6(Y'-[#
+M30;+1W`Q:4E&P73"[0D&7#BRPAFGCJRSD1#UGYS59\7.Y39=Z/EY!MF`T""<
+ME\B!4WYAMB];FX',W0/[8.UN0;B$WY<>#N^X"QQ7'N;VV+IP;5UU<C+B96<\
+MV+D$X9T[X/#<08#]9+$5:&^MSWU!ET?\&8!J!)X603W./A.#:<#48#2])PI,
+M!DGJ`Y%74E=]?=;5=_OC9YAPE)"FV=ZDCS%UBTD`"_J)>:-WS[ZGZ^W2?MP<
+MSHTJ-Y%LLUFM&,&4*W?UHME:?.^1^6Q=O`Z2]J.7&1`*I&2.C];EO)P)IR9G
+EZP9*U<?';?;!!)NCBG!:++3^F]L!9TXN%5M\P2_U(^.V,`<`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-bsd.vmdk.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-bsd.vmdk.gz.uu
new file mode 100644
index 0000000000..4185190082
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-bsd.vmdk.gz.uu
@@ -0,0 +1,81 @@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X7J[R+U=Y]G[CXW[NC^NU#]7:3^[O,UGQW=?Q>JOXO4W[6SZW/D.]7?1>KO
+M8(Y\I_J[2/T=S)'O5'\7J;];YK[T.?*=ZN\B]7=?EKG&'=U_%ZJ_B]3??9FY
+M^]*Y(]^I_BY2?_=EYNY+YXY\I_J[2/W=E^O-V9'O5'\7J;]K9]?GR'>JOXO4
+MW\$<^4[U=Y'Z.Y@CWZG^;EB^D^:^]CGPW:#ZNR'U=U^7N<X=^.[[4\S=D/J[
+MKS-W7Q?NAC4_Q=P-J;_[.G/W]5]M#GPWJ/ZN?2QSN3<>Z/Z[_E0Q=^?;MS]>
+M_AS<T,T\Q>#E@H._YGZ0]_T7?/_8;^;O?/]8VYVY'U]2V/3K>W!WCK[R\5]Z
+MN_3%V7\SN-FL]ON;P?]:7M_/RW0&7ZWW\'?]$]_^\?;^7^WU_?S3VYO=:MBL
+M-MO5Z'_V#?_/O_TW?3KH3V___\[OUUQ)7WO!]F?F?OYN>^=7WB5#_\2WCLG;
+M.]?6;>A/;_<7\4,O9_H)^>KHJ[W_%?9N_H3TW<_SSZ\7__U?C9?_^Y&N$6V?
+MWU5_?524WWN[OWE]J]NW^_-WM-W]7V]WYKQXNZO[<X???FY__^H>W+XZ^HKJ
+M?^63<?/G?/_D/[D_1N[_D_MKSO]>$>Q^FN7';SI[^+O^B6__?'O_KU^#PSSX
+3MYW@L!Z_O\H__A<I;[G$7Z<`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-ebr.qcow2.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-ebr.qcow2.gz.uu
new file mode 100644
index 0000000000..2ccdc28e36
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-ebr.qcow2.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-ebr.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-1x1-512-ebr.qcow2.gz
+M'XL("),[(U0``VEM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_+4:/@/0$7"V7]#ES5_EXC\C;N3L
+$@10`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-ebr.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-ebr.raw.gz.uu
new file mode 100644
index 0000000000..39e42283f9
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-ebr.raw.gz.uu
@@ -0,0 +1,11 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-ebr.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-512-ebr.raw.gz
+M'XL(".?%'50``VEM9RTQ>#$M-3$R+65B<BYR87<N;W5T`*V4S0Z#(`S'[SY%
+M=]W!0`?379?LOLNV,[KY%#S\BO@!(J@)@&A2^LN_MH4Q.P#H65UQ@RX70Q?G
+MHJ?QYC"PZU:!%M>2%QV@I>3P08MQ!\<9((_K.[FX;^YPNV-`*4&I`/@:]:'Q
+M$@A,K>QQ@[Z7_IST"0.4%0@)\@HU[@WX\WBOI4/P7/_/XG`+-PGF>W`7X^6<
+M="LC;M!SF=CWB!,I=81@OT/!RLRU)^J%GYMG8-0E+;!ZL*$/G/(+L[Y;*`.]
+M<!/Z(`Q7&5SEG^<.#C?"!1_7)'.;5G<*U;69DR&7G;&S<PW$[UR+P[P7`?8W
+>"U4@G0KWN$$_2W]:H!B`V?Z@0`,L_F-6J)F4!@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-ebr.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-ebr.vhd.gz.uu
new file mode 100644
index 0000000000..ef46cf7078
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-ebr.vhd.gz.uu
@@ -0,0 +1,18 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-ebr.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-1x1-512-ebr.vhd.gz
+M'XL("/0TQ%4``VEM9RTQ>#$M-3$R+65B<BYV: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1x1-512-ebr.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-1x1-512-ebr.vhdf.gz
+M'XL("%TEAE4``VEM9RTQ>#$M-3$R+65B<BYV:&1F+F]U=`"ME;%R@S`,AO<\
+MA7+=,G"VL`RLO<N>I>T,!'*Y7MJE0P<>OC;&Q,9`2,_@$.=D??EE288Q<P&H
+MS^Q8-G3)Y.IVAUU/X]73P+:=!1I<K;S4`C5*&B9J,.[@.`/DR_KV+NX<.]SV
+M.2`1E&4`?+/Z4'L)!%;./)<-W6OBWZ,^H8&4@2`@"3EN#?CC^#Z7#L%C[9_!
+MX2/<*)AOP:7:RUGI5L:RH;N7B?FV.+&F3B%8\U2P%+GV1#[Q<_,,3'5)#2P?
+M;.@#Q_S"75\1RD`OW!5]$(9;:ESFK^<.#A^$"SZN6LWMNKI]J*Z.G`R:=L;&
+MSM40OW,-#N,>!-B?+*H"U:KPN6SH3HE_&Z`8@-%VD(97D4Q!MB`;D*3GF0!9
+M0):[0/0KJ:N_OYKZY_KK9ECC^/CF"(?VQU1WB\P`2_TG\JSGCKZ7X^5PO5TL
+MSAY5]D12S::\4@19!>'2I-FN^-DC3W=U:;A)Y.Y>(8$)X-P+?%!W\LN9^G/>
+G!MNT4(E^?^SP?GB&V:-*XXA-O/Z;6X.3D4M%U=[N#X:PW+*_"```
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-ebr.vmdk.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-ebr.vmdk.gz.uu
new file mode 100644
index 0000000000..8f46a3204d
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-ebr.vmdk.gz.uu
@@ -0,0 +1,82 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-ebr.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-512-ebr.vmdk.gz
+M'XL(".C%'50``VEM9RTQ>#$M-3$R+65B<BYV;61K+F]U=`"M7%V/W,81?/>O
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;1+^(,-\VT2\BS+=-](L(\VT3
+M_2+"?-M$OX@PWS;1+R+,MTWTBPCS;1/](L)\VT2_B##?-M$O(LRW3?2+"/-M
+M$_TBPGS;1+^(,-\VT2\BS+=-](L(\VT3_2+"?-M$OX@PWS;1+R+,MTWTBPCS
+M;1/](L)\VT2_B##?-M$O(LRW3?2+"/-M$_TBPGS;1+^(,-\VT2^"\VT;_2(F
+M4_TB)E/](B93_2(F4_TB)E/](B93_2(F4_TB)E/](B93_2(F4_TB)E/](B93
+M_2(F4_TB)E/](B93_2+F/#?4+V(VU2]B-M4O8C;5+V(VU2]B-M4O8C;5+V(V
+MU2]B-M4O8C;5+V(VU2]B-M4O8C;5+V(VU2]B-M4O8C;5+Y[S/#?4+YYO/DMX
+M%Q5/=UOLI@\LT?_FA/,<[5X)]Z@L#LO15?YB.38AF?0-\?5]K>E&ZW+GWY:P
+MJK*NNTGX3ZYO_33A[;-5;_^.W[A^<]K_">M;/PZSJMW'Q%:7K#D?+?BG;W]\
+M5O"6SNQQV=+=?/3T\W1AP0<^R;HLUX^>%D]],N(WKD^/R79FNO)+J],IS[%B
+MC3]ZNBR;9W&ZS^N,8'A2,SQ#EK"_V=/ZVMMEG'?E?F%]-\A2ENY'D'[XJN[B
+M#NLBY6;[=/T7]_;+J_OZ=G6#\694S]\9!]^Y+LG^G;NE.]L"P65%EDTZ<?MW
+=_,;UN]/^SY:P]`G-.EBZ#T[+O_H__903[2]?````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-gpt.qcow.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-gpt.qcow.gz.uu
new file mode 100644
index 0000000000..adcced8273
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-gpt.qcow.gz.uu
@@ -0,0 +1,132 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-gpt.qcow.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-1x1-512-gpt.qcow.gz
+M'XL(",5Q+ED``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9>9J5L<-ZZ`P(RX>-D#U='7K^AW!X`5(I5U0+X
+M?<QO*+>^OLR[@=YN-30#!4S)"3?,5>WV\[O:7+.;\Z_?-.R'F^Y0;AK7Z(>E
+M*O.RX]1TK[X@]BE3;LO5'G&"PDW',@^GCQ=YO8+#+M;](7!R+6IZZ7"/>VMP
+M*IU'[;<M5BA6`,MVK*Y(W*\9+HMLGM3#VXSE.Y8U^GW2KM5_U)E^2F-%7R9F
+MVX;AC%6RG.NS6P_L[FZ3.P,[2WZ?VOPDMT9@%SU`K9Z$-2-T4H'ILCD.>XWT
+M7ZNG^_)615N]TLJ"7?0`N7J563U\D712:,ETXZJ-!3?BMI%7+]/#?7WT_7OY
+M2P]T-\G\:X#2`J-E*+-V%[$Z-"YB=6A<Q.K0N*C5H8$1JT/C(E:'QD6L#HV+
+M6AT]L$GC;>(:I]TK"Z9J5DK6UO,TR.VX2WZBTVU@;>M?V<3QF]%$W,0U;G43
+>SQMRLO;SUYMLQ$U<XZ)NXC+7Q^^C?SXHP2(5&@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-gpt.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-gpt.raw.gz.uu
new file mode 100644
index 0000000000..d6f0738da9
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-gpt.raw.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-gpt.raw.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-1x1-512-gpt.raw.gz
+M'XL(",9Q+ED``VEM9RTQ>#$M-3$R+6=P="YR87<N;W5T`*V52T_#,`S'[_L4
+MWA5$E*1)EIUX2"!Q&PAN7/I83V@2]_+=B9N&]1$7)CF-JDJN?[4=_VLIXP(P
+M&F29N=.&[D%,KVYSM>EIJKH,&+Z/(<R`(@`CK@Y&J?&=XQ':=MA2]5[161K0
+M*CT/.'%>6S'"-6>OQ:8-8YR(N)1N>QG06BC+!?`]Q:?[X[!@')@]Z/"^!*/`
+M:K#F%]?G:NMQ?(]/SW"X?WU#V,<Y7:V"4=5@)-0[:-I9=(I,]VZ>;L1I]%I4
+M.^$*$K?-XXIXMC0NMVF<6?.*/?2_LXTX*Z=>?NSE+7@-KH:F)'&?$YQC[CR#
+MYLK!K@9W!*N@;O&A<:!4B"_(Q/>04-\&Y!YV"G2%P.[T(DX1=B.^KH?XC!HZ
+M(K=I`U4]H]<Z`H/Z(UV8X@KNZGFLGF6KWGYHEMRF#63UREB]?)%(R72I:DDA
+M"5<Q5\^A.>@C_+^7=]K0'<3TBD`S`-DB#,WG&-6!.$9U((Y1'8AC50<"&=6!
+M.$9U((Y1'8AC54<`>LDWQ!'7#W$#NP::`HKY$*?&<2>^Q6TF7:_71O_*$,\?
+CAF<<XHA;'^(%F6Q:LV09ASCB6(=X`)92;GX`")Q24X@+````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-gpt.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-gpt.vhd.gz.uu
new file mode 100644
index 0000000000..e91c585138
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-gpt.vhd.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-gpt.vhd.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-1x1-512-gpt.vhd.gz
+M'XL(",9Q+ED``VEM9RTQ>#$M-3$R+6=P="YV:&0N;W5T`*V82W/3,!"`[_D5
+MV^%6!H_>=F[0F3)P*PP,%RY^I62`\&@//9C_CE:6;,NV#&G743U)E/V\+ZVV
+M8JR_`(P$<P#3@M'X/E=@]I`7`';2#^'NW'^$KOYQ:NO[XT/FKV[7PSB;2L7B
+M*"\D*/N0'$2)#S$-OH<N8+)GU[>7Q^^W`2<\3GB0SE%*"C#5XCG*?EOTVB'I
+MTU%\=<BK+X-V<JG=*&7_\@:8`LXGOY!!.XO)_L3&*BMU.+AAH&E1=AC1AVAB
+M-';F.\UF4A,UUYS*1F/7<&9+ZAS<Y<['HD\5FQBYO3,P''*![VW:!#\LADV5
+MA[N?Y>^[=J:?2*2*&?3CBSF9-E?X5!'AQUX#A>F\92XXROT<MY(J3_*>B>5"
+M=*T3F`X3PID?>V]$P50_P]F&S]/!2.I7HGYV,;!RY9Z>Z*ZR^#4`J^H\8/!@
+MC!L,KFKTGZL#;3M:U">)%Y82!$\&1%Y,_%<UQ/&M#N<!M8:R7``_!OUJ%PX-
+MRH#:8V+8XJ`X:`%Z3&=GJZZG^EV_?@LWK]Y_0-CGT=S:I4L#JL#BR0\S[98K
+M+9C[1JPMMAH7V]+;`2=3N#X$2QPN-LDW<&L#.I[`J2VI82_YC]CV.,UBJ6(J
+M56@H[!920U,F<=\B''5=;G&Z,I#7N(5K#K7;RQN#&QD4=IFX_<U:(.SV9C=V
+MZ^@*@=WI77;J82^R7\^]?BWW&;$VTA,I[[5B*R-0J7^8"S&.NBZW!7I/DWEO
+M[Y-E;:0GDMXK>^^M.PF56ETR85?+LHL85]%ZC[OVT:X/6[^7]_1$=Y/%KQXH
+M_#9$MJ\)7TC)-%0>2*:A\NN74$.N-H-Y;I25R`5AA4$<885!'&&%01QIA4$@
+M885!'&&%01QAA4$<:86Q0)?,1(T0XGS?;/U<V7]%9VHD6QK4[R6B9&RN$EOM
+M4[H12@1#$39"B-MLA&0ZMOX2,V,)&R'$D39"QA=2HK,,$QJAI0Z/.<LPH1%B
+FHP.?<)9AUANAQYYE(([P+`-QA&<9B"-.%>Q;=G\!II']:``3````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-gpt.vhdf.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-gpt.vhdf.gz.uu
new file mode 100644
index 0000000000..9a79e2944a
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-gpt.vhdf.gz.uu
@@ -0,0 +1,19 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-gpt.vhdf.gz.uu 319295 2017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<;5FU7YB_#D\=_I`Y<WA_6?!;`(@&8K
+M+/PM!>VN#@]G>'5X.,.KP\.97AT>T/#J\'"&5X>',[PZ/)SIU5'X&T;:?8A[
+M.'_N]5/-:W\/_W)]UJ0_CJ?U_?AV7MA7JW1GSC'YT?_,A_C3FS$8?HA[N&<_
+@Q,<AG6SX>9"LX8>XAS/]$"_\W3NS+_X/OKS-T+1E````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-mbr.qcow.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-mbr.qcow.gz.uu
new file mode 100644
index 0000000000..fdf3991433
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-mbr.qcow.gz.uu
@@ -0,0 +1,127 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-mbr.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-1x1-512-mbr.qcow.gz
+M'XL("*0S(E0``VEM9RTQ>#$M-3$R+6UB<BYQ8V]W+F]U=`"MG<N.&TF21??U
+M%=3[+=',@F2$WFA@!IA=SV)FML7GFA^@CQ^5%.&>:3Q75MU5JD1!@A07I.?1
+M$;KKR'.]_OEMM=K8:MBNAFEU.:R^_WC^L-6=']S_6'W[[__\K[=WOWW[[>>8
+MK7_Q5/KQX*N8Y^YM_6/=YOR/IXZK]?0GYKY_&,W=>77Q+[RZ.V_V=N[E;S_?
+M+#_G:O#^VUW-<\O;-7%ZPY][?5_3V[6?I_?WO5T7;W>C!K?W!O\YS_T^OSX7
+M;W>GYL9[<]?T=EV\W4G-[7\)BPM8#FKN6,P-^-1)S9V+N0T^=>$Y^\7G]N?<
+M%I\R-><XMVIS.WPJU-QP;V[]=@%ZF1OQ*<&=E=Q-^)3@SDKN]OB4X,Y*[@[X
+ME.#.2NZ.^)3@SDKN3OB4X,Y+[L[XE.#.2^XN^)3@SBONC)\2W'G%G9'O7''G
+M%7=&OG/%G5?<&?G.%7=><6?D.U?<><6=D>]<<1<5=T:^"\5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\E>N[G^<?
+M7X#^^__67OYS2KJ7M'U^5_WU4:)^[^W^XO6M;M_NCS\B=_=_O=V9\^+MKN[/
+M'7[YN?WUJWMP^^KH2[3_E4_&S5\<_I._<_\8N?\[]^><_[TBV/TPRQ]_BNWA
+AW_HGOOWS[?U_?@X.\^#?=H+#>OS^*G_[?V9WPD*PIP``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-mbr.qcow2.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-mbr.qcow2.gz.uu
new file mode 100644
index 0000000000..3502ca115a
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-mbr.qcow2.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-mbr.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-1x1-512-mbr.qcow2.gz
+M'XL(")<[(U0``VEM9RTQ>#$M-3$R+6UB<BYQ8V]W,BYO=70`K9C9LM,P#$#?
+M^Q4NRP4N4&+)3E.6"]R%&=[@`7A.EWQ%/YXD5N-$D>*VD]:3:<?1&=D^5I8L
+M"Q]CO#4N-VYCJJVI_U,#T_LS;.;X^\?/5?]S7`28S90HH<-AAQNP'B(.-%QF
+MQQU6QO6R0P$'IZ@Q*(5S:G93'0+N=M%.7;L8!8O`:X`!IR[&5?E!R(]'N"OS
+M@[GS0WG^_"F.=^33^6'(CT>M-5R1Q($0M=%P91*'0M16P^V2."=$[37<(8GS
+M0E2EX&Q"E1J7"U%6PT$2MQ:B4,.Y)*X0HC3O;-J[C1"E>6?3WI5"E.:=37NW
+M%:(T[VS:NYT0I7EGT][MA2C-.U"\,Q%W$*(T[X!YMR3<LXBKA"C-.V#>/2?<
+MBPYGI2C-.V#>O23<3<0)]0XT[X!Y]XIPKR-.J'>@>0?,NS>$NXTXH=Z!YATP
+M[]X2[EW$"?4.-.^`>?=^Y)T5ZAUHWB'S[@.QLH@3ZAUJWB'SSA(.(DZH=ZAY
+MA\P[))R+.*'>H>8=,N\\X?*($^H=:MXA\VY-N"+BA'J'FG?(O-L0[F/$"?4.
+M->^0>?>)<)\C3JAWJ'F'S+LOA+N+.*'>H>:=8]Y])=RWB!/JG=.\<\R[[X2[
+MCSBAWCG-.\>\>R#<8X<#*:KS+LOD1KBGT9Z%>>\_7;P_ML)1[Y@`%I<`IS(,
+MN,VL`_9AP(T&I7#4.X[WJ^&W`[:;[0)@/3]5-0+2@'W8;/4)=2L]_:A;F"\:
+MGNU=T84!+U<]W'[F^6OWQP5`[TU9CH!_3OG!W,OA&J!?-YO,YZ:`<P?\[^GO
+MV+\:-]N&"SC][0!U=`G;<W#MVX'>F7TS]([AO=XRXB;?#C2//`>I0\W.S^R>
+M*UA<?YW;9[5=?*AE=\K=^IJ8GU!;8##<B?S,>+C-1;Q[V&:KV"Y`8KAFB-M.
+MKNUT=LMQ=KN9%\/SG7'FSFT@PYT;<#!O(8"VLM0&UF>-CWK'\==J^`U`1\#9
+09M#ES:5H\1\W+X2OTA0`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-mbr.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-mbr.raw.gz.uu
new file mode 100644
index 0000000000..0eceedb4d7
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-mbr.raw.gz.uu
@@ -0,0 +1,11 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-mbr.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-512-mbr.raw.gz
+M'XL(".G%'50``VEM9RTQ>#$M-3$R+6UB<BYR87<N;W5T`*V4R[+"(`R&]WV*
+MN'7!A`C'NG7&O1MUC?7T*7AX@^D%BJWM#)!29@+?_"$$1&D`A@#=EW'>X<\J
+M[;[:5Q^:?FX#U@AMFP$5`P77,(X7L#G;3=A00Q#.'YM&(-W-Q<"KL>U4A'L-
+MNW*;=\0X);@^W'8;T%IP+@/>>GU4.ATF`.T1C`7[!S6M#?AQN4\"%IPN=7Z"
+MHU^X0;!>@SN$7='*^&;,._QX3>3?X\R2.D;@_Z9@;>&[9^K)OCC/@%PE#6#=
+M^2@%#OF%4=\IET%)N`OZ(`_7!=PQ7:\C'/T(%U+<<S&WR^IVN;JF<#+LM#)6
+K5FZ`I)4K."K[$-#G9>$;R*OR<=[AKRKM`C0=L-@)&@K`Z@UK>@7\E`8`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-mbr.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-mbr.vhd.gz.uu
new file mode 100644
index 0000000000..12ab83d9f9
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-mbr.vhd.gz.uu
@@ -0,0 +1,18 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-mbr.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-1x1-512-mbr.vhd.gz
+M'XL("/LTQ%4``VEM9RTQ>#$M-3$R+6UB<BYV:&0N;W5T`*U7SW.<(!2^[U_Q
+M,KWEX,`3GN::F=Q[:7-65].=3MM,DD,.]G\O""B(F#5%6187WL?W?LHR9BX`
+M*H$&H!Y(ZG$E@.Z@J@'4I&TX]=P^PMC]^=UW;Y?WPE[CR8!QYDN%XEH>2Q!J
+MDPJPT9O068]A=##%EX>GV\NO)P>'%@XMD*RT5(E`;;2/4+_6AIU&>KS@SPGR
+M_L?,KHS9+5+J4YV!">#<6U$Z=@JF^!LJ*Y34,$RM`M9/]G$M>`@F%F57MI-L
+M)>71W#(J6Y3=@J,]J2-PMR?K"Q,J*C`JU3,@#A7JL0H;9X>HJ5!Y?WUN7E[[
+M%3],A`K-_'@T5Z;511LJZ!9;!D*'\YZZ,*&\K>$V0N6_K$>AG+`#900FW01.
+MZH?66Z#`YT><[=@\[8PDOT;S4\G`FHT^/3'>%^$]`[;M,<":&88AW*QPV\T*
+M-W+1R`3)8DSD:8?<>/9KSYG]VP['`*6$IHD`OSE^76YW]!I0E4]5?25!C=<J
+M_/CP?2O=^D3V?K)8]?@1W$R87P-7VE+J5OJ1D9X8ES`QWPY.[+'3*=P?4E9F
+MCKV^7LGY?@:FLJ0#5GM%Q@.<_0L+O[N8!@;J[O"#6-U&PU7A>N[!X0?J0@C7
+M[OIVG]U-S*[+[(QAG1E79JX&"3/7P&'>0H!395$1J%;%?7IB_%J$MP%$^^;(
+M]BI"6_NR,106,!M#X8II/H8EVPVVHU%(EF&F<SVER_UGSO7DE?L,YWIRY3XE
+CQ0Z=Z\F6^TSG>G+E/L^Y7L-E/=>3^L?&V.D?^S1@R`P.````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-mbr.vhdf.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-mbr.vhdf.gz.uu
new file mode 100644
index 0000000000..07c18eadb8
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-mbr.vhdf.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-mbr.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-1x1-512-mbr.vhdf.gz
+M'XL("&4EAE4``VEM9RTQ>#$M-3$R+6UB<BYV:&1F+F]U=`"ME;UR@S`,@/<\
+MA7+=,G"VL`Q9>Y<]2]L9".1RO;1+APX\?&6,P<:!)#U`(<[)^B)9/PAA+P"%
+M((H;SWE%^YJ$=[O9;3J:+)\#Y@*:)@(F#+2XBG&\@:6@?L$B)!C'^<,B!:#L
+MUU:@3<9KFWBXTV`5R[S"QR46Y\)MG@,205%$P#?G'ZZ=#F6`E($B(`TY/AKP
+MQ^%]$K#%R;7.S^+P'FYP6#Z"2XV5M].OC'E%.Y:)_78XM>0=(T3]5+"T<NVI
+M?&+GYQD$=TD%(N]U&`*'_,+HWSYV`X-P%_R#.-S"X+)PO_1P>"=<"''E8FZ7
+MO=O&WE4K)X.FG?%@YQI(V+D6A^L.`NPF"U<@[XJ?\XKVF(2W!:H>N-H)4O\J
+MTBGH!G0-FLPZ4Z#WD.4^$,-*:JOOK[KZN?SZ&38X.;PY8C'VF)INT1E@8?Y$
+MG\S:\^_E<-Y=KF>'<Z/*321N-K9*$709A4N39KO@9X<\CMZE\2&1?WI[#4*!
+ME$'@O7?'L)RIF_,NV+J!4G7GXR3X$2ANCBJ#(S&Q^F]N+4ZO7"I<>YL_P54P
+%QK\(````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-mbr.vmdk.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-mbr.vmdk.gz.uu
new file mode 100644
index 0000000000..b433374ee4
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-mbr.vmdk.gz.uu
@@ -0,0 +1,82 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-mbr.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-512-mbr.vmdk.gz
+M'XL(".K%'50``VEM9RTQ>#$M-3$R+6UB<BYV;61K+F]U=`"M7%V/W,81?/>O
+MH*67(`\+UI)<D@\"$N<<(`@"&)9COX:?T2&V))P.00SLC\\,.357O!4UM*_E
+M/9&C[:Z=[MFK.U<7-L_7/UE6]EE99N6859<L1^;^:7UD>?&T<(]SPR>N?[_[
+MQX\G_OG#Z73]:@6#SY(4Y`HGB\WK7$_/_A#N_*6LS1/N<4["%3ZKOTD,<.>=
+M)W;A2O?D^7,IW%VW/#WZ&X'+(E"V@:L^4]-NL5_:W1^_"LWS^RO\'MSQ7MJL
+M+K)+'Y;9I5K615:?E^?RK'9!LP-\G=W=?_I/=C=]&A[N/SY^"/L[^[-UP>7%
+MQU\&C^`*JR_^QC_AX5H/<9FR8LP*^*>SZ\-?[W^>3O^='C[=?WC_!BSW[,^V
+M++*R]=OQ\?G38[/P+Y)G%_C7R*Y_^=O=F_#.S4\?NP?"^2RW$??:K@[%O5PR
+M_W7[6'8WO7_TB'/X$W?GSS8TIUI>N_0W59G5;;9LI_+89_?T&$I>>C<\3-WC
+M],.O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.Y?,UJ]I_[FQUR9KS
+MT8)_^O;'9P6O<&;OOQ7NYK.LG\/%#1_X:.RR7#[+6B+UG;'_Q/7I;;)>"5=^
+M:7<Z-CI6K/%G69=E\RQ/SWD9.@Q/]HAG5!7/-WO:7WN[C?.FW"_L[X:JRM+_
+M3--/<]53W)#G3KG9%J[_XME^>7=?W^YN,#Z,ZOEWQL'O7`^R_<Y=X<ZV1'!9
+DF&7U8MS^O?_$];O3]K\5L`R`9ATL_2>QY5_]']#X]&&`7P``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-vtoc8.qcow.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.qcow.gz.uu
new file mode 100644
index 0000000000..64c33ecff3
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.qcow.gz.uu
@@ -0,0 +1,125 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-vtoc8.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-1x1-512-vtoc8.qcow.gz
+M'XL("*@S(E0``VEM9RTQ>#$M-3$R+79T;V,X+G%C;W<N;W5T`*V=VZX;QY(%
+MW_T5U/TN,3.;9+?N.!@<8!X&.(/Y`?/Z3,RS/GXD[>XJ[60LY1G8LF!($&J!
+MNQ0.&':@M%[??5NM-K8:MJMA6ET.J^\_G[_;ZI>?W/^^^O;?__S/M[]^^_;'
+MW9BM?W,J_7SPE<US][;^T>?\QZGC:CW]&W/?O^/<+Y\N_A^?[I<O]G;NY1]W
+M7RR?<S48]P97\]QZ_GPF;F_X]S[?U_3EVMWM_7U?KHLO=Z,&M_<&_S7/_3E_
+M/A=?[D[-C??FKNG+=?'E3FIN_UM87,!R4'/'8F[`4R<U=R[F-GCJPG/VF]_;
+MN[DMGC(UYSBW:G,[/!5J;K@WMWZ[`+W,C7A*<&<E=Q.>$MQ9R=T>3PGNK.3N
+M@*<$=U9R=\13@CLKN3OA*<&=E]R=\93@SDON+GA*<.<5=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]O!8[UX(-?!N_F?GRY=X?S[["IN>^_\.W!S>>[F^M?KO]R
+MQ._-&7VZ'X\;KF[FNJ;R9RQN[P%^.M#47T"%GG'BN=-^=3C_?-+N<C/W\,L\
+I]_,9IQ]2VL/?]2]\^]?;^W_=H3+,@W\;>\-Z^_U3_O%_AAM3=G^E````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-vtoc8.qcow2.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.qcow2.gz.uu
new file mode 100644
index 0000000000..a440456c0a
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.qcow2.gz.uu
@@ -0,0 +1,21 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-vtoc8.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-1x1-512-vtoc8.qcow2.gz
+M'XL(")L[(U0``VEM9RTQ>#$M-3$R+79T;V,X+G%C;W<R+F]U=`"MF-N.TS`0
+MAN_[%.YR7F")9^PTX;#`[K(2%T@@7H"F<1^`ZSX\3NS6R60F+E7:M%)E_9_&
+M]M>ITZ((#Z6L5J94IE;[1OG/\0(U^#"^U.'7X_>;X>.P"C!=""EFP.`)-V+=
+M)QQ(N$)/!S2/&U2'#`Z.J2DHAS-B=7,##.YZU2]=OQD52>`EP(`3-^.B^B#4
+M1Q/FPOI@Z?J07S][S-&!<KX^#/71U$;"55D<,*E:PFVS.&12C83;97&&2;42
+MSF5QEDGM!9S.J.)Q)9/2$@ZRN`V30@EGLKB*24G>Z;QW-9.2O--Y[[9,2O).
+MY[UKF)3DG<Y[MV-2DG<Z[UW+I"3O0/!.)9QC4I)W0+Q;1]Q5PNV9E.0=$.^>
+M1-S3$TYS*<D[(-X]B[CG"<?T.Y"\`^+=BXA[F7!,OP/).R#>O8JXZX1C^AU(
+MW@'Q[G7$O4DXIM^!Y!T0[]Y.O--,OP/).R3>O8NL(N&8?H>2=TB\TQ$'"<?T
+M.Y2\0^(=1IQ).*;?H>0=$N]LQ)4)Q_0[E+Q#XMTFXJJ$8_H=2MXA\:Z.N/<)
+MQ_0[E+Q#XMV'B/N8<$R_0\D[)-Y]BKC;A&/Z'4K>&>+=YXC[DG!,OS.2=X9X
+M]S7B[A*.Z7=&\LX0[^XC[N&$`RYU\JXH^"OBODV^L[#L^=.D\[%FWN6!&6#U
+M/\"Y"@.N7G3"-DS8WSIN0)6VN[P2%KN=]$U$F58"/OYU[N[W@_DQK,\N?4-@
+MT_H5W#)15-4?QT%:/SM:OSJ+RVR'#0>S1:8;<,VY./_CXH_VK5/.$=R?`6ZW
+M\&;HR71==_+WQZGJ#.!Z``RX;KHA3'>8^6_@.*P.ZTE]`9>F"X,(C'":J\Z?
+M%OO7&-<FG*8]:W:R:[8ZMZ@J?5\^"]=N5>.ZDVVSF>"NCKB^+_L#D+]IG;[+
+:`X>?-^-G4,5$X&+NF;)K5*M_;'%=NO`2````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-vtoc8.raw.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.raw.gz.uu
new file mode 100644
index 0000000000..48acdfbca4
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.raw.gz.uu
@@ -0,0 +1,10 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-vtoc8.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-512-vtoc8.raw.gz
+M'XL(".S%'50``VEM9RTQ>#$M-3$R+79T;V,X+G)A=RYO=70`K9)-#H(P$(7W
+MG.+AT@5IAU)E:XP[$Q,O(-AZ`-<]O&V&!`KEQX2A=/-X7^8Q(P07H#1.!%V%
+MHPA5":50*B\8>'UZX&Y?:R_/J[H77"YCF/1BTB*6!%>,RF7'#GB.?'(9>(:H
+M(2@)9%S=N^I5W%)_C&OVBLNX=BM.^]O`6%@[PKT&N/?.PY"3N!9^X"3#GUP%
+MYN.X,L1E\WC"LS@ON'S2'^/ZN#2P4(23J>Y0\!OC3(^3?ZU*GNS.[KHJ\K,5
+L9QJT%D0H]01WT!V.@JORWS>)>UYPCR)^>%54!]QM]Q0%8/8#T8E)O;($````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vhd.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vhd.gz.uu
new file mode 100644
index 0000000000..402114c116
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vhd.gz.uu
@@ -0,0 +1,17 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-1x1-512-vtoc8.vhd.gz
+M'XL("`(UQ%4``VEM9RTQ>#$M-3$R+79T;V,X+G9H9"YO=70`K99-3\,P#(;O
+M^Q4&;CM,B9NFVQ4!-R0D#EQ)UVQ,B`\!AQW&?\=ND[5IFVU`NBQ*E_KI:\?.
+M(D1S`>@,]`JT!9WSN%"@%U#,`6C2-:Q[Z6YAMWQ[M<NOS7;FKMVD@4G1M0K-
+MV1XS4/22`M#P2W3%8]AYS.SB>CW=O*P]#AT.'2@OV"I#T.7@/8I^G3?JF/2P
+MP><:>?FT5Y<-U;56]"TJ$`JD[#R1>76$F7V'SBJR6JWJ5H"P=7Q\"VZ"B=;9
+M7NQRT;/JR!P+JFB='</I0U:_P4TG;BV:5*'$**@7H"44R&-*&Q^'0:-4V7Z^
+MFX]/V].'D531>WUR,)?%W467*N@?=@H4I_,A=Z&F?/5Q(ZGRK^CIT$ZY`05!
+MY'X":_?#Z+4HZ.K34AR(>7PQHOH,ZU.:5Y1W@9P+(Z=B59!1_%05<_CFP]K+
+M^RMU&\;/1%;WS_$S\\#N2'5012]XUXBFBUFT5HO_%YLQJ=QM<.6I."IR44%E
+MP=H>[K&#6R9>C'+@KN5,1EDGRS'@F>JY6[*[C7%_A64,QQMI"PIQK;O8,<$`
+M-]A<6!WLRZR+JUI<3^.1Z(7Z/,XF395R=2JN,E!:0!S;1L\];LE6]$<DS$@?
+MG]C=S<)/DRKH]I5D&Q6F5J@<,)E"`MK$"J4XF!F_K5_M%"8Z]3$NX:F/<0E/
+@?8Q+>.IC7,)3'^,2GOH8E_34I^O<F_P`@FX48"H,````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vhdf.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vhdf.gz.uu
new file mode 100644
index 0000000000..b0ef21d3bf
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vhdf.gz.uu
@@ -0,0 +1,14 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-1x1-512-vtoc8.vhdf.gz
+M'XL("&TEAE4``VEM9RTQ>#$M-3$R+79T;V,X+G9H9&8N;W5T`*V43TO#,!C&
+M[_L4#W@9$TK^M[V*>A,&'KS:KND80P7QX"$?WF3);--D=4C3M+2\?7YYG^3E
+M)<0/0"B4#$JZ*1@DAQ#@T@8ZV'@Z81X_M;Y[OI=/A1]FY6'4!K,2,A<PQ628
+MU28`JTA'YX$52`W"LD"/JP=5_2=N+C^/:Y:RZW'MM3AEGQTZ#:TGN-<1;K?P
+M8=#$KH8]<%9=!5Q/[5)GUXNG)TPOX6S`K)/\/&ZPRT82%N%H+CL4_HYQW8"K
+M$M6<V74V.[UHJ=#^6ES7H-5@+;A*<+<JX)A32?M_DWE>#IAM$5^^5$0`+E9[
+M,C0JQ:%Z*'WJ51RE@*I15F,@BXX99O?QKG=?A^_Q_LG0J/H^/YV>V29H%RG!
+M&K>(ZMS[*+^;A_WF\+8_XUAPQ<+"LG0J;KMJF]B5L=V7`SN>D-LA.YYNDASO
+M7JU`!"B-C(?LMG&Q.)SX-:M[M.*T/^<9?42!;.TYG"03U?]+V>'4PJ5B:V_U
+)`_KO!\'=!@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vmdk.gz.uu b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vmdk.gz.uu
new file mode 100644
index 0000000000..f8512936d9
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vmdk.gz.uu
@@ -0,0 +1,81 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-1x1-512-vtoc8.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-1x1-512-vtoc8.vmdk.gz
+M'XL(".W%'50``VEM9RTQ>#$M-3$R+79T;V,X+G9M9&LN;W5T`*U<76_DQA%\
+M]Z\8G%\."2"PEM\/!R2.;"`(#!@^(WDU/V,A]MU!)P0QL#\^'')J5)3$&\)J
+M965R;KMKIWM6):6ZL%FV?3E7]*XH7#&ZLG(9W/)/V\-E^>-B>5P:/G']Q^WW
+M_[SAU]N;F^M7&QA\EJ0@4SA9[%[G>O/DBW"7+V7MGE@>ER1<[K/Z9XD![G+P
+MQ"%<L3QY>2F%N^O6IT=_(W`N`KD=7/E"38?%?FEW?_HJ-,_O+_=[6(ZW:EV=
+MNZH/2U>5ZSIW]65]+G/U$C0O@%^[V[O/_W&WT^?A_N[3P\>POXL_VR6XJ'Q\
+M-7B$I;"Z\C?^"0_7>HAJ<OGH<OBGW?7^N[M?IYO_3O>?[SY^>`>6>_%G6^2N
+M:/UV?'SV^-@M_(MDKH)_#7?]V]]OWX5W;G;SJ;LGG,]:-K*\]E*'XE:5\]_/
+M'^ONI@\/'G$.7W%W_FQ#<\KUM0M_4Q:N;MVZG=)C7Y:GQU#RVKOA?NH>II]^
+M_S2]>_/;QP^Q=_YL?<O:%:A9&Y6[,O=0H33?OM(C^K?->FKN^NO=PR]WP_NE
+MS,_3FYNO'>$JW[OE`)NPKZWJ):4Z/-EEV]=O__>PU.O&<+)WA%LWL1:QO'9Y
+M<67ML98#7(_BXO+"WRW_M&QXJ:2`#W+7CQ]N?OS7\B/NF_7^A[_^2+A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]6.QM4O_\O\=/7'^XV?]O>ZL4
+4`=#LO5?XSV'-OOH_FA1I)IY=````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-apm.qcow.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-apm.qcow.gz.uu
new file mode 100644
index 0000000000..5a533532e3
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-apm.qcow.gz.uu
@@ -0,0 +1,127 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-apm.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-63x255-4096-apm.qcow.gz
+M'XL(",$S(E0``VEM9RTV,W@R-34M-#`Y-BUA<&TN<6-O=RYO=70`K9W9CAW9
+M<47?^RLN9[(XW8C(D;,$N0$_&&A;T+.4(R!`MA.R`+_PXUW%.D-5W+T9E+NI
+M0H-$(3>R3BTN":W%P_/Y]L?IU,JIZ4[->-KGT_6OTX><[OSB_L?IZ[___*]O
+M[O[X^M/MF)R_\Y3[=:,G27/WMGY?Y_3FJ>5T'G]@[OH#SMUY._LGWN[.%WLY
+M=_73[1>+GU,V:/<&3VGNG-Y/R.DU/_9^7]R7*[>G]]M]N4J^W)8-=O<&?TES
+M?TGOI^3+[=G<<&_N<%^NDB]W9'/3=V%1`LO,YI9@KH%/K6QN"^9:^-2.Y^0[
+MW]O;N0X^)6Q.X=RIS/7P*6-SS;VY\YL,=)X;X%.$.PFY&^%3A#L)N9O@4X0[
+M";F;X5.$.PFY6^!3A#L)N5OA4X0[#;G;X%.$.PVYV^%3A#N-N!/\%.%.(^X$
+M^4X9=QIQ)\AWRKC3B#M!OE/&G4;<"?*=,NXTXDZ0[Y1Q9Q%W@GQGC#N+N!/D
+M.V/<6<@=\ITQ[BSD#OG.&'<6<H=\9XP["[E#OC/&G87<(=\9X\Y"[I#OC''7
+MA-PAWS6,NR;D#OFN8=PU$7>*GR+<-1%WBGS7,.Z:B#M%OFL8=TW$G2+?-8R[
+M)N).D>\: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TH'/+ZRNOC+]L[4P_N/@IZF_W$PY^Z#Z3I?+GR6#DT^WNQ^G/`Z[
+MU=G%^G\O2PXJ-\H5].P6RI75,E5WLYS<W=_>W_[Y?=/@JANDFU?A?)?J?DV6
+M;'5VX+TU#]S;YGX!!-S>6]749X9VSZRWPU6-]QOA+S\N+593SG_-4-96:Q:[
+MP/%=69Y=7QS_&%^W^V>&_;'!^A-5NG_0ZE_](6GW3[7K<T/WS_7V+T>5YXR;
+MH7]__]4B-O4-W#^=4?_\2;W[+"^LKDZV_VJ@(>!@%1I73>>#_Z4*H1'E$P``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-apm.raw.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-apm.raw.gz.uu
new file mode 100644
index 0000000000..a5073b3d6a
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-apm.raw.gz.uu
@@ -0,0 +1,12 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-apm.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-63x255-4096-apm.raw.gz
+M'XL("/[%'50``VEM9RTV,W@R-34M-#`Y-BUA<&TN<F%W+F]U=`"MD\UJPS`0
+MA.]^BNFU4"/)*RD]MK2Y%4)#S\'4#@3:Q*2!7O3PE2*)R#\)+FB]"(ME/\:S
+M:\9\`"0A!9A-%E)PL`4N]T'"O+Z7-N[*&*;P,,YN=%W'E8,PQ;T'"E>6#-2,
+M^JH4R/L%LWH;`CW.Z2,.S5RJ3R@Y2]]3UWVU$SB1ZW,]KAJKD]OS.P>T@":H
+MQW"J+53KRD'=IJN/I]UI=]AO(HXL3C6N6?]'W7?=3:J3F6=+,V>[B$L9@/W9
+M(NJCW+M'YW$H9[P=A$T2D!6((!HK7+J:O8^`RV/;/J]?'CZ6Z]0_HLSZU`S_
+M1.*?_TE2_Y#J4[G]4S?]TQ6TGMC-BW\_OWX1H[[,_G$6_&/UQ'F]8%9E__%`
+1"L!L"DDX8/$'F8$ZXZ<%````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-apm.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-apm.vhd.gz.uu
new file mode 100644
index 0000000000..740932d5fa
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-apm.vhd.gz.uu
@@ -0,0 +1,18 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-apm.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-63x255-4096-apm.vhd.gz
+M'XL("#0UQ%4``VEM9RTV,W@R-34M-#`Y-BUA<&TN=FAD+F]U=`"M5DMKW#`0
+MON^O&.@MD$4:2_+FDI+2Y%8(#:7'X'CE8)K'DEU(#LY_KT8/)#_9)-H5PD:>
+M3]]\\Y`8<S\`58!J0&E0DIY+`>H,R@V`6?0#[<S]*W3U\Y.N#^W;VO^ZE0/C
+M++7JFY,]%B#,)B5@19NH+3U#%V#6WR[O3]K'^P"''@X]D"S)JD!0=Z-]RBUL
+MW#X6[F^+_RSD>V17C-E%*^=@TT#1)%\4@=V[G;^GS@IC9;ZG(>&NM/J$T7OI
+M+41G!]I)-K!*:$Z)RJ*S4W!JR>HC<"<K'PN7*B8Q2C,S4!Q*I&>3-D&'T3"I
+M\K;?52][/>"',ZFBDF`,U\2\N^A3!</'GH$@@DON@D79#^$F4N5+ZJF^G?`/
+M1@0FPP):]_OJ12A(^2G.%C2?#\8LOXKXF=*4&*O-C$)#S9<<OOQ-,.?#<%0S
+MT?VT?C4MFPH1VY%=+[Z\O]!=_YI,EYKX"4YI3)E<4PX?P^]BMWO0$W"8RUT'
+M5XS9R<;7G"TZUZ+M[%JW;`*[6U-MA_;0/C_=!CAJ5-1J+>+Q[!ZKW20[F3FV
+M^LC8;I(Z8:/80N"G<^>>MN%0)#R=D!($@C0'F0#<&N*2ULS["/#J1>L?-S]/
+M_US=I/IID9<?9T?HAXE^KDA2_=+>PN<.\<_S6]2/#I-R(C>C?OM7EXB!7V[]
+M*J\?JR;F^87N>MW_.T#TS31;=\;8_?(P%!XP&T,1:S@70ZX7@_G1*"O<6)<S
+K774)+N-5E^`R7G4)+N-5E^`R7G4)+N-5E^"R7G4-H,F]U7^P3V5T'PT`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-apm.vhdf.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-apm.vhdf.gz.uu
new file mode 100644
index 0000000000..0141acf677
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-apm.vhdf.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-apm.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-63x255-4096-apm.vhdf.gz
+M'XL("*DEAE4``VEM9RTV,W@R-34M-#`Y-BUA<&TN=FAD9BYO=70`K57+:L,P
+M$+SG*Q9Z"]3(>KJG/FAR*X2&TF-P;3F8-HE)`^W!'U_)DAK)=D):)"]"8KW#
+M[*RT0L@,`,J`84#*D#7:S<=]SZ"=/2=JW"5NM!,#EIZ+.@V7]$8[F1I`K-U,
+M$2H'<<0'3$-'NWCJ`QHXS8^F()`V7@!G%_&[;YH/.0*'8Z5KX,B0':NZ=0H@
+M,`@*_,;.O`(NM=NR6S7Y_E`?ZMUVY>!4%8&7.EC\A=TF;T;9L<BUI1?6-K,+
+M;`'#VH+C1V.?/=J5@VOA52&440R,`*6`2T6<:9_:#P#G>RD?EH_7+_.EKQ^E
+MD?GQ"_3#GG[FDOCZ@<^/Q]:/G]5/$!!BY&P>]?O\,@?1\8NL7XJL?B@?F4\[
+MVD42?@:06L!H##/;G3FQ=UV+2%P/R'Q`?"QO!UCLMK(XU-_^#<YL=ZZJ<=/Q
+MF.BW@`O`>==B2KWV^%W-UM-ZLW9PKONYAX,)'454N=\&Z69ANJ\U?N^S(T.1
+MLD"]5/,D59!XH-ZM#T=_DY42"J./LV`3.$9[LX;KNI__\W]K:^!XY*.B'LK)
+)#UU>%[W2!P``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-apm.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-apm.vmdk.gz.uu
new file mode 100644
index 0000000000..0a36699f49
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-apm.vmdk.gz.uu
@@ -0,0 +1,83 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-apm.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-63x255-4096-apm.vmdk.gz
+M'XL("/_%'50``VEM9RTV,W@R-34M-#`Y-BUA<&TN=FUD:RYO=70`K9Q;;^3&
+M$87?_2L(^<4(D`'/\/ZP0.S(!H+`P,+K)(\.K[&0]4J0A"0+S(\/F^S3.I3$
+M;<*J]<@SM5-5TUU-E;1?'3!-US])DG=)GB?YD!1EDB*9_VI])&GV9,R/<\TW
+M+G^]_O'O)_[YYG2Z?+4F@XN2$*2:3HS-YUQ.S_XPW?E+49LWYL<YFBYS4=V+
+M0)_NO//&;KI\?O/\6@A7URYO#^Z%I$M"HF23KGAE3[N;_=+J_O"5+YY;7^;6
+M,!]OV215EI2=-Y.R6.PLJ<[+>VE2S4[3G/#KY/KFX=_)]?C0W]_</=[Z]9W=
+MV<[.>>G\R]YEF#=6E>Z%>\.E:UR*<DRR(<G@WDXN]S_<?!Q/_QGO'VYN/[T#
+MMWMV9YMG2=ZXY3C_].FQ,=R'I$D)]QG)Y<]_N7[GK]ST=-?>,YV+FA<R?_:\
+M#\U;EHG[>OE85C=^>G09)_\GK,Z=K2].L7QV[EX4>5(UR;*<PN4^SV\/?LM+
+M[?K[L7T<?_Y\-[Z[^NWV4ZB=.UM7LF9)5"^%RI(B<ZG\UESY"I?173;+J267
+MCS>/O][T'^9M/HQ7IZ\3IBM=[>8#K/VZUEW/(>7NR<[+OGS_O\=YO\G@3_:&
+MZ99%+)N8/[LX)T7E<LT'N!S%.<ER]VK^JWG!\TY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CYK[7%>?K%^
+M5994U2O7YE/]'OZ[7HA<GW']BM37S]W?^<7_]]^XO#]M_UL3YCZAV0IS=_/9
+,]*O_`W*E&0&37@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-bsd.qcow.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-bsd.qcow.gz.uu
new file mode 100644
index 0000000000..7356f38a0b
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-bsd.qcow.gz.uu
@@ -0,0 +1,126 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-bsd.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-63x255-4096-bsd.qcow.gz
+M'XL(",,S(E0``VEM9RTV,W@R-34M-#`Y-BUB<V0N<6-O=RYO=70`K9W)CAM)
+MLD7W]174/$LTLR`9H1D-O`?TKGOSWK8XKOD!ZG]O#1'NF<9SRZK1I1*$%%)Q
+M07H>'0&J`]=Z_>O;:K6QU;!=#=/J<EA]__G\W59W?G+_^^K;/__W[V_O?OOV
+MVZ\Q6__!4^GGN]-JFN?N;?VKS_F/IXZK]?0GYKY_-YJ[\^KB/WAU=][L[=S+
+MWWZ]67[.U6#<&US-<^OY]9DXO>'/O;ZOZ>W:K]/[Z]ZNB[>[48/;>X/_F.=^
+MGU^?B[>[4W/CO;EK>KLNWNZDYO9_"(L+6`YJ[EC,#?C42<V=B[D-/G7A.?N#
+MK^VON2T^96K.<6[5YG;X5*BYX=[<^NT"]#(WXE.".RNYF_`IP9V5W.WQ*<&=
+ME=P=\"G!G97<'?$IP9V5W)WP*<&=E]R=\2G!G9?<7?`IP9U7W!D_);CSBCLC
+MW[GBSBONC'SGBCNON#/RG2ONO.+.R'>NN/.*.R/?N>(N*NZ,?!>*NZBX,_)=
+M*.ZBY(Y\%XJ[*+DCWX7B+DKNR'>AN(N2._)=*.ZBY(Y\%XJ[*+DCWX7B;BBY
+M(]\-BKNAY(Y\-RCNAHH[YZ<$=T/%G9/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.qcow2.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-bsd.qcow2.gz.uu
new file mode 100644
index 0000000000..2c252d956e
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-bsd.qcow2.gz.uu
@@ -0,0 +1,21 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-bsd.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-63x255-4096-bsd.qcow2.gz
+M'XL("+H[(U0``VEM9RTV,W@R-34M-#`Y-BUB<V0N<6-O=S(N;W5T`*V8VY+3
+M,`R&[_L4Y@P+E%AR3ARVL+#,<`<W<-UVVZ?H\.RL:R5*%"E>.FD[F>FX_S=R
+M_%E)6A3IY5SI7:A<:-UQY^Z_TP?<X,OXXTZ_OO]8#U^G58+YPD@I`_6AQXU8
+M?QD'%J[PTP&OXP;5H8*#+C4%Y7#!K&YN0,%=K<ZG[KP8C4C@)<"$,Q?CHOH@
+MU2<3X<+Z8.GZ4#]_99>3`]5\?9CJDZG:PC59'"BIUL)MLSA44CL+M\_B@I*Z
+MLW#&SAW@2B5U-'`^H\H]KE)2WL)!%E<K*;1P(8MKE)3EG<][URHIRSN?]VZK
+MI"SO?-Z[G9*RO/-Y[_9*RO+.Y[V[4U*6=V!XYQAW4%*6=R"\>T2XQXP[*BG+
+M.Q#>/2'<TQ[GM93E'0COGA'N.>.4?@>6=R"\>T&XEXQ3^AU8WH'P[A7AKABG
+M]#NPO`/AW6O"O6&<TN_`\@Z$=V\GWGFEWX'E'0KOWA&K8)S2[]#R#H5WGG#`
+M.*7?H>4="N^0<(%Q2K]#RSL4WI6$JQBG]#NTO$/A74VXAG%*OT/+.Q3>M81[
+MSSBEWZ'E'0KO/A#N(^.4?H>6=RB\^T2X:\8I_0XM[X+P;D.XSXQ3^EVPO`O"
+MNR^$NV&<TN^"Y5T0WGTEW+<>!UJJ]ZXH]`_A;B=[%I:]_PQ\?^R5HSTP`VS^
+M!SA78<*UBTZX3!..&FR5HSUPNEF/WSWPO,)E'5>UK%P##ZWPS^WOZ83+!5<X
+MX>S'41KH"NZWX`2W&>#B%>TX^.5P'=W>\_8?$@>XZ\3K<+./H_$>^Z`-F),M
+M%Y8%&I$;KG.\M8MWX%UW%[=F_?HZKD^1&4;3G:G/3:<;KQK]TYU8CXB#S'3=
+M&!>O&F)?\A)FSMYF6MU^X<5`N3,>N',C9+QS$PZ6;020_I<JXJ^F1WO@]',]
+6?B=@(.!B9S!4L?>M_@&MW,<Y0Q,`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-bsd.raw.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-bsd.raw.gz.uu
new file mode 100644
index 0000000000..af455ec7d3
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-bsd.raw.gz.uu
@@ -0,0 +1,11 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-bsd.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-63x255-4096-bsd.raw.gz
+M'XL("`#&'50``VEM9RTV,W@R-34M-#`Y-BUB<V0N<F%W+F]U=`"ME#L.@S`,
+M0'=.X;E#E&])%RI5ZMZIG2F%4^3P38`4FQ#H$`<B(MM/_N!P/@F`EL#;C3VO
+M<#=&EZM.U4B3`6AJT`;,&:PWY\M##D3A7O<GP^)FG-CSRN/82B).'N%BP&K(
+MX:X(I[QR0)9<(*].@.KG`_Y&N&9Z(T[O1><KP?LM13994ZIVL;=VY8?[#*('
+MH8#;62<I\-=?6.*[I&%(DNY.?)"FVP9<3>T%PLF#=('BW@&'^DE:>%"])HVN
+M*]P,M9Z,/R<W0.CD3CA9]B*0X\WB_T!OE>YYA7LPNB:@GH'%*EA_K"=67[CE
+&;;$%!0``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-bsd.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-bsd.vhd.gz.uu
new file mode 100644
index 0000000000..f60d234715
--- /dev/null
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/tests/img-63x255-4096-bsd.vhdf.gz.uu
new file mode 100644
index 0000000000..75e96e471c
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-bsd.vhdf.gz.uu
@@ -0,0 +1,14 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-bsd.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-63x255-4096-bsd.vhdf.gz
+M'XL("*PEAE4``VEM9RTV,W@R-34M-#`Y-BUB<V0N=FAD9BYO=70`K90[;\,@
+M$(!W_XJ3NF6PX'B8+$U4*7NG=G9<'$55VZ5#!WY\(38Q9_RH*@.VC([[?`_N
+M&.L&@$1@]<1[7N">2CI=L2MN-`Q`58%4H#08?YP-BVR(P+V>7LITN!['E[3F
+M<>5H1!RNX:+!HIW#'1*<\,(V.<EXHM5P$';8RPG<HW^.`TXN6><CP>R48-99
+MM57L8F[-2"_-,W`+7``SO0PI\)Y?&.S;YV8@<7?!/LC=K0.NHN=Y@L,5=X'B
+MS@''R>$AA2O1.^;6-1LG0XPKXX^5&R"T<CL<;ML(\-99_`WTI_+WO,`]EW1V
+M0-D#-XN@Z7N?%J!;T!:T"M^5!+V'RJ1`I#?)-5^?MOF^_J09#CC>-8/)%?11
+MA&K1%6`=?J+?PG=BW\/ILKM^7"(NMJK8D7RQ>2V!H,^9NV94;%=\'ULG\B`9
+M$CT>[$S;GO\SB=XAQ<F[L]9"T\4G+K(A@LE6%7"*C;3^F]L.IS>^*O[R%;]:
+',:4),`<`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-bsd.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-bsd.vmdk.gz.uu
new file mode 100644
index 0000000000..809221a5bd
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-bsd.vmdk.gz.uu
@@ -0,0 +1,81 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-bsd.vmdk.gz.uu 271911 2014-09-20 21:02:54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'S;1K^(.-^FYYOTBXCS;7J^
+M2;^(.-^FYYOTBXCS;7J^2;^(.-\VT2\BSK=-](N(\VT3_2+B?-M$OX@XWS;1
+M+R+.MTWTBXCS;1/](N)\VT2_B#C?-M$O(LZW3?2+B/-M$_TBXGS;1+^(.-\V
+MT2\BSK=-](N(\VT3_2+B?-M$OX@XWS;1+R+.MTWTBXCS;1/](N)\VT2_B#C?
+M-M$O(LZW3?2+B/-M$_TBXGS;1+^(.-\VT2\BSK=-](N(\VT3_2+B?-M$OPC.
+MMVWTBQA-]8L83?6+&$WUBQA-]8L83?6+&$WUBQA-]8L83?6+&$WUBQA-]8L8
+M3?6+&$WUBQA-]8L83?6+&$WUBYBRS%"_B,E4OXC)5+^(R52_B,E4OXC)5+^(
+MR52_B,E4OXC)5+^(R52_B,E4OXC)5+^(R52_B,E4OXC)5+^(R52_>,ZRS%"_
+M>+[Y+N&#Z6XWN^H#BV5]Z[>#WOZ]_\3UZ]/VOYAP^8+=LO9?=%I6KCD?7>%/
+MW_SXRH:+L]F&UW0W7Y[\,EWD7=->NK](.M_@)_'<?!=S#Y>/SW;Q2KH_G^2;
+MHHOE"W9W5Z=SBF.;-?[RY&+Y$EOUU7/V'<:#'WZ>?_'>B.?KGM?7WB[CO-GN
+M[ZS/W6[7-U']^E`]C\V[=6>[;IO.-U$]S\T1)JKWU>WJ>N/#N/DJUH/O7)]D
+G^\Y=TYUM&T&U=)9U^'_[]_X3UV]/V__6A,62\(O_`X=39<Z@70``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-ebr.qcow.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-ebr.qcow.gz.uu
new file mode 100644
index 0000000000..482cf28472
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-ebr.qcow.gz.uu
@@ -0,0 +1,128 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-ebr.qcow.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-4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72?NK@MWZ/X[8_V=N?[N^G(X.^0[UM^9Z^_*V=4YY#O6WYGK[\`<
+M\AWK[\SU=V`.^8[U=^;ZNSQW4^>0[UA_9ZZ_N\ESE3OD.];?F>OO;A)W-Y4[
+MY#O6WYGK[VX2=S>5.^0[UM^9Z^]N+H>S0[YC_9VY_JZ<79U#OF/]G;G^#LPA
+MW['^SEQ_=YAKSO@IS%V3?^#F;NL<\%W#^KO&]7>W>>Y4YH#OOCV%N6M<?W>;
+MN+N]+7/`=PWK[QK7W]TF[FY_*W/`=PWK[QK7W]U>#F>'_KSM<N+T%[Z^=]^^
+M/KKZ,=BB:XBB08&#=W,_/F8_4KBI39Q\^^F=C-+SB]3?%.^_OIL[5J[OSZ$_
+MYOD/O5WT)S/_9+!M3]-T&/Q7?GWHYJ`_\OJZ'_]3JM'3>0)_Y[_P]2_O'_Z5
+M!_L?G]VV/S7MJ>U.@_[J*_S/7_\-OKX]^NS^?V_X;@Y\=A_.Y1=<?CL[S-W<
+MF_O^V=WO_9-GN??4?>[N__C>W/7[>[_?]NBS6^>^^VI#OT#?[)_\V>T/]T/>
+M_SK_N$+93N?\GU/<O:3EZWNJKP_U^`_>[D]>W^GX=G_\^T#_\)^7>W,:O-W3
+MP[FYF`5\"8/3NSZ^.O3GT?^1+\;AEL-?_.1^'WGXR;V;TS]7!,,/LWS_76P"
+A?^>_\/4?[Q_^=3?8I,$_[02;;_2=SX_^!PM'3SM0J```
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-ebr.qcow2.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-ebr.qcow2.gz.uu
new file mode 100644
index 0000000000..d711f03ba7
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-ebr.qcow2.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-ebr.qcow2.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-4096-ebr.qcow2.gz
+M'XL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YGIFB%NTW<680DS9V\UKFX[\V)8OC,>N',]9+AS`P[F;03-
+DN;.<##Q]:WS4!XX_%\-G`#H"SG8&7>5_>V_^`UMI__/2%```
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-ebr.raw.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-ebr.raw.gz.uu
new file mode 100644
index 0000000000..bd2392fe80
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-ebr.raw.gz.uu
@@ -0,0 +1,12 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-ebr.raw.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-4096-ebr.raw.gz
+M'XL("%[N+50``VEM9RTV,W@R-34M-#`Y-BUE8G(N<F%W+F]U=`"ME,T.@R`,
+MQ^\^1<\[&$"9[*+)DMUWV79&IT_APZ\5=2#XE4"%2`J__$L+C)D&@#WXK3OZ
+M=-'ZY)(,-%Z?!_(@T.`:VL5IF98T9AU-:9QQ#<[;@+X*#5MIX[ZQP^W.`:4$
+MK3W@:](G(J>C:,F="V`Z,*X[^GOJV@140\'(`G()\@I*'%7X>;P#^56,QPK8
+MX,0>;A)L*BB$JRQ<AL[.6FDJ<=QEUYW];^%*TR=<OJ4.3X*U(<=JL#)NL2@T
+M=Y^=9^`M\`R8&GW"!<[YA;^^FR]#..%NZ`,_7$VXPEW/+9S8"1=<7#V_+($4
+M[IQ>Z:MK(B>#+V_&P9M+$/?F&IR(^Q#<AI<%*Q!7^>.ZHW^FKAE@/@*CG2"]
+,?(PE/\L2J-?E!@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-ebr.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-ebr.vhd.gz.uu
new file mode 100644
index 0000000000..5fc6d2bdeb
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-ebr.vhd.gz.uu
@@ -0,0 +1,18 @@
+# $FreeBSD: head/usr.bin/mkimg/t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new file mode 100644
index 0000000000..20a35c554c
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-ebr.vhdf.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-ebr.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-63x255-4096-ebr.vhdf.gz
+M'XL("+$EAE4``VEM9RTV,W@R-34M-#`Y-BUE8G(N=FAD9BYO=70`K94[;\,@
+M$(#W_(J3NF6(X##861RI4O8N;6;;P5%4M5TZ=/"/+V>""QCG46$P@AQ\N1=G
+MQNP#8-YD7Q8,F^@95NO52./MXT">!%I<1Z<X;6LDC:*G)8T3KC-KG=!O9YIY
+M:A]WS&UN_QA02FB:&?#5Z8>9PU%J$A<(K$F,RX+A>1,V!ZS&A)$E%!*D@@KO
+MU?"P?TO$MV(\E\$6A[=P3F&;02G<SL,)(^R]G383+Z?\O//G'JZVK\,5U[0S
+MGF`Z)5@T5N9-ELJT\)P?9^`:N`!67608`J?XPI]^V[D:&)A[13^8F]L0K@SW
+M<P^'-\R%$-=.E241PAO>J^?:=9F#P>.;<>?-)4AX<RT.\Q:"[5A93`::7?-Q
+M63"\;,)F@<4%F,N#W'W;E`#5@]*@),W+`M06RLH'8IA)0_?UJ;OO\X\7X1''
+M;3%(=CJ/@FZ+*@$;^A-UI+FGW]/^M#Y_G!S.E2I7D<QE,Z<$@FHC<WEL[N&,
+M[[%V(G82C[R'I*=?]LPO@?=V/JZ8C-4]M,<1YWJP"`2I4C7B)(M._3>V%J<R
+/IXKY[JY^`1U?D=P0"0``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-ebr.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-ebr.vmdk.gz.uu
new file mode 100644
index 0000000000..7703e2eb47
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-ebr.vmdk.gz.uu
@@ -0,0 +1,84 @@
+# $FreeBSD: head/usr.bin/mkim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6";!A_M%=X,+H_XU7&>
+M>\2OCO/<(WYUG.<>]:OC//B(7QWGN4?\ZCC//>)7QWGN4;\Z;@9O_YWC(WV(
+MG^?D[F-R7YM!F\W<ZV,?Q_7U/7R[=__.D7WT_^1#'/]D;(_X(7Z>^_F'^/9'
+;W^PC?HB?YQ[U0[P]'&^\]]M_`$CJT>#UK```
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-gpt.qcow2.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-gpt.qcow2.gz.uu
new file mode 100644
index 0000000000..8ebf7ba1f4
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-gpt.qcow2.gz.uu
@@ -0,0 +1,26 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-gpt.qcow2.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-63x255-4096-gpt.qcow2.gz
+M'XL(".1Q+ED``VEM9RTV,W@R-34M-#`Y-BUG<'0N<6-O=S(N;W5T`*V92V_<
+M(!"`[_D5I.\FS=8,8'O[2)JD62FWI&IOO?AYC-1KY?:WUQALUGC&)%MVD945
+MFD^`OQFPDR3FPYCB3*9,;EE;LOZW;<#V?LP;Z^YWMYO]3W=D8#PAHI`.*2;<
+MC'7M<$#A$K[LX#AN;W0"P<$8M02%<)(<W5H'@CLY&I9NN!FY%R$.`1H<>3,.
+M&A^8\?D1\L#Q0>SQ"7S]U!CG=Z3KXQ-F?'Y41N'R(`Z0J"V%*X(X@425%*X*
+MXB0255.X)HA32%1+X'A`E1Z7(E&<PD$0ER%1@L+)("Y'HBCO>-B[+1)%><?#
+MWA5(%.4=#WM7(E&4=SSL785$4=[QL'<U$D5Y!X1WS.$:)(KR#CSOCBWNF<.U
+M2!3E'7C>/;>X%Q..8U&4=^!Y]]+B7CD<4N^`\@X\[UY;W!N'0^H=4-Z!Y]U;
+MBSMQ.*3>`>4=>-Z=6MP[AT/J'5#>@>?=V<([CM0[H+P3GG?O+2MQ.*3>"<H[
+MX7G'+0X<#JEW@O).>-X)BY,.A]0[07DG/.^4Q:4.A]0[07DG/.\RB\L=#JEW
+M@O).>-YM+>Z#PR'U3E#>"<^[CQ;WR>&0>B<H[X3GW6>+.W<XI-X)RCOI>7=A
+M<5\<#JEWDO).>MY=6MR5PR'U3E+>2<^[:XO[.N$`BYJ\2Q*\6=S-(F<!J7<R
+M?21NM\31#RN''&>E.VYSY$IWK`#SIP/)O5::<TJ\"2LS86U5@5SICNYJ,_].
+MP"%WGP`<1SC'V0DKD[OF@;%I6-O:9E;*!F>M.R`@$S[>[.'JR.LWI-L3@$JQ
+MHE@`?XSC&]*MSR_S;J"W6PW%0`%3<L(-<U75_OAN=K?L[O+;=PW[Z:8[I%M6
+ML(JS(F>%/SI.3?<W9I\RZ;9<[1$G*-QT+/-P^GB1U2LXK+'N#X&3:U'32X='
+MW%N#4\D\:K]LZ6VB%*PM6%$3N',/ET8V3^KN,F59Q=)&OT^J6OU'G>JG-);W
+M:6*V;1C.6%N6<7UVZX'=P_WFP<#.-K].[?@DMT9@C>Z@5D\.E3FGIINY!P%B
+MNFR.PUXC_=?JZ;I<JFBKM[6R8(WN(%>O,*N'+Y)>/31ENG'5QH0;<67<U>/F
+M%6:BZ_?R2G=T=YOYUP"E!48;H4S;*F)V:%S$[-"XB-FA<5&S0P,C9H?&1<P.
+MC8N8'1H7-3MZ8)/$V\0U3KM79*P&_9PX^W_!VG;<#8^/R^DVL+;UKVSB^,UH
+E(F[B&K>ZB6<-/5GS^>M--N(FKG%1-W&9Z>/WT3]QQ=U%%1H`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-gpt.raw.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-gpt.raw.gz.uu
new file mode 100644
index 0000000000..2a7a503905
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-gpt.raw.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-gpt.raw.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-63x255-4096-gpt.raw.gz
+M'XL(".1Q+ED``VEM9RTV,W@R-34M-#`Y-BUG<'0N<F%W+F]U=`"MEDU/A#`0
+MAN_[*UZO&INVM"Q[,=%$$V^KT9L>^"C'3;SSX^U0D*^6N,E`0TB&>7;FI2^S
+M4H8#,!JRC%S3@>Y)+,_N<'OH::JZ#NA_GTI8`84'!ESM@U+3,\ZA;8<E59\5
+MDF4+K<;[`2>FXT;,<,V4M5GIP!PG`FYLM[T.:"W*<@/\'.O3_>NP,#G,"=H_
+M+V$4K(8U?[B^5UO/ZWM^><7Y\?V#8%]3NUKY8.7S&Y09W$HDJ9+M?J_;#3A-
+M61NU1UR6Q-W$<1EE-3NXV$KCS%Y6V$/_>[<!9^4RJYAG90Y5AK9$V21P#RM<
+MSKSS#(6K',<:N8-5J%NZ:7(H!13>)D4/T="^Q!.."KHB8'=Y$Y<`NQ<_=T-]
+M1@T[(K;2@91ZIM\J1:K=(^WMW7:QQ&7<ZA6DGF53[S1LEMA*!Y+JE4&]N$BD
+M7M0RW:C:Z)`15_&JI_JIX?WAO]_;:SK0G<7R#$`S`-DJ--J/#3YW$([1'81C
+M=`?A6-U!0$9W$([1'81C=`?A6-WA@4[R#7'"J3`FVP:%ALM6]:7&\53?LEVG
+H]T;_SA"/OPS'.,0)MS_$W;7-,@YQPK$.<>/_3TEY^`7C-"Q#B`L`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-gpt.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-gpt.vhd.gz.uu
new file mode 100644
index 0000000000..0069c75279
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-gpt.vhd.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-gpt.vhd.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-63x255-4096-gpt.vhd.gz
+M'XL(".5Q+ED``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'.M6+?=]
+JC^FTA7",IRV$8SQM(1SC:0OA&$];",=XVD(X[E3!K<ON+T20T[RB$P``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-gpt.vhdf.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-gpt.vhdf.gz.uu
new file mode 100644
index 0000000000..b1822d3878
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-gpt.vhdf.gz.uu
@@ -0,0 +1,19 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-gpt.vhdf.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-63x255-4096-gpt.vhdf.gz
+M'XL(".5Q+ED``VEM9RTV,W@R-34M-#`Y-BUG<'0N=FAD9BYO=70`K9=+B]PP
+M#(#O\RM4>MO2X'<\EPXM[$)OV]+2RU[R7(9EIY3=PQ[FQU>RDTF<V*%3G)C@
+MH.B+)$M6PI@_`)0`5D6N:<'Y2Q&>Y]W-SM%X?1T0WT\F+(`%`CVN02$3]$S7
+M0=\/@W&GY97Q7O;#?,05TW$H9KCVHK4>:<$<5WC<Z&Y_'5!KJ*H5\.=HGW#+
+MH4$94'L0^#P#Q4$+T.J"<[[K9F[?[=U7N/_\_0?!'B9W!4=AS:$V4&DHY<(Z
+MON'N2^BNQZ%!D6B/.)G$'9;1\SA)N'8#%QMIG-K2\CGT;VOK<9J%6G:N)3NH
+M)?055&T"]VF!,YDS3Y$8%[9LP'2@.30]35H#G`-8+!/K(`($FKB'DH.H"7@^
+M?2M.'O:Q^/-AL$_Q(2-B(RU(14]1JC";<K>DW-YT%T*<S!T]2]'3V:*W'Y(E
+M-M*"9/0J'[UXD"AZL=)%W!"UXEV(J_-&C[NN@?6!^_?ZFA:<[XOP]$`U`+-9
+M6/9]D[$Z")>Q.@B7L3H(E[4Z")BQ.@B7L3H(E[$Z")>U.A#8L7Q-G'"4>\T>
+M&HQY#768->EV/-EW"-SMQ%;KWVCB\<7H,C9QPFTV\;Z[UMF,39QP69NX'3Z_
+MC03CZLMHFI<*#):4G0/%E#,.V/P^=<WK\6T>/>MV9I@^DA>#](6DQ#18(A6]
+MQ+0TG]GW_O;QYOC\..+$X-480%V2EA1@ZI6[-G3WUU$\+:V+;%,VB!Y?I?-B
+M&SC,<>KB+/X:X!;#U#2"FT`0363"N529/_R_:^MQN5,%?PUV?P&M?`V+LPT`
+!````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-gpt.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-gpt.vmdk.gz.uu
new file mode 100644
index 0000000000..271ff8154a
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-gpt.vmdk.gz.uu
@@ -0,0 +1,88 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-gpt.vmdk.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-63x255-4096-gpt.vmdk.gz
+M'XL(".5Q+ED``VEM9RTV,W@R-34M-#`Y-BUG<'0N=FUD:RYO=70`K5Q=C]S&
+M$7SWKYB<'QPDR(*U_%H^*(B=LP,C"*#(3O*2ARR_XD-L23D=C`C8'Q\..357
+MO+LY4KX^\42.V%T[W4,V5]4%9MGRXUS1NJ)P1>_*RF5PTS\MF\OR^\&T'4\\
+M<?GS]5_^?N#/KP^'RV<+&+R7N"!3.!FL/N=R>/!#N.-S7JL3TW;<A,N]5_O(
+M,<`=$R>2<,5T\OB4"V=WGD_W_D#@7`1R*[CRB9B2P3XWN]]\%I+GYY?[.4S+
+M6S6NSEW5AJ&KRGF<N_HXG\M</1F-$^#G[OKFPW_<]?"AN[UY?_<NS._HUW8R
+M+BIO7W4>80JLKOR!/^'A&@]1#2[O70Y_VEUNO[GY<3C\/-Q^N'GW]A48[M&O
+M;9&[HO'3\?;9_;8:^`_)7`7_&>[RQV^O7X4K-SN\/]\2SGM-$YD^>XI#<:O*
+M^=_'VSR[X>V=1QS#3YR=7]N0G'+^[,(?E(6K&S=/I_38Q^ET'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
+M\\MY^6;>LHAP<^QEI_/[^IMOW>LOWWSOP?YY'^[\>N<N]V1;47N4]>R0#O=/
+M;Q[?'<7\>N?'V29<GH3[XJF;K9A?[SSVS\`]M:7ABN>\/O5-X,7\>F?U4O6M
+MRP?7YFX\NW.?@/O]`[C*^,J;WSS;5J[N_/N#2[AN?MES7WE:VIVFVV3YG]_1
+M'7NO1*CACOZ-S(?+V[\>WBY@OSO\][=A?LN;9_'TECZ1REXQO^7]E`JW3A3L
+M=9D7N-PZ>_[[2EN:9:\)%\M36_I$,GOG)7N)I]J4O:=NW0F.3[5?K>%:V^R5
+M\U-C$9X\_CM]XO+ZL/ZS`!8!T&R&A7^EH-W=X>$,[PX/9WAW>#C3N\,#&MX=
+M'L[P[O!PAG>'AS.].PK_PDB[A[B'P_*-N:[<6/LO$*MI)!_'E\//T_<*__/%
+M*MR9<TP^^I]YB#^]&(/A0]S#/?L0'X=DL/QY$*SA0]S#F3[$"__VSNRS_P-?
+'I$_:M&4`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-mbr.qcow.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-mbr.qcow.gz.uu
new file mode 100644
index 0000000000..550dcb49e5
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-mbr.qcow.gz.uu
@@ -0,0 +1,128 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-mbr.qcow.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-4096-mbr.qcow.gz
+M'XL("&'N+50``VEM9RTV,W@R-34M-#`Y-BUM8G(N<6-O=RYO=70`K9W)CE79
+M$47G]16/'I+N1<1M:3)3EFS),WM@>UJW';\/0/YV`WF:S+A[$Y0+0*5$67?K
+MO9.+1:E8.IS/=]].IU9.37=JQM,^G[[^//V0T[V?//QQ^O+/O_W]W?UO7WZ[
+M&Y/S#YYR/^^W,O=@Z[]U3K\]M9S.XT_,??TA:.[>J[,_\.KNO=GCW-5O=V\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ZN]O$W>WO90[XKF']7>/ZN]O+X>S0W[==3IQ^XLL[]^W+
+M;U??!]OO7]M&3^<)_)-_XLM?WCW\7@:_WVOT!P:_O6$Y#.8WW-[=:_2]K9O:
+M!-[7G][9+;V]1>KOLO??\,T=?-?O[LVAOS?ZSYP?NHKH1X-M>YJFP^"_\NM#
+M5Q']F=?7;;_XZ]M_!Z;M3TU[:KO3H#_["O_SUW^[5W@W!V3P_[WANSD@@X=S
+M^067WQ\/<S?WYK[)8+_W;Y[EWE/WN;O_\;VYZW?W?@/OD0SJW#<!;N@3],W^
+M8AGTAPLG[W^=O]_);*=S_O,9=]%I^?J>ZNM#@?^#M_N#UW<ZOMWO_X'1/_SW
+MY=Z<!F_W]'!N+F8!7\+@]*Z/KP[]!?=_YHMQN#;Q)W_E?AMY^"OW;DY_K0B&
+H[V;Y]MOB!/[)/_'E'^\>?K\;;-+@+SO!YBM]Y_-O_P.[1]$3H:@`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-mbr.qcow2.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-mbr.qcow2.gz.uu
new file mode 100644
index 0000000000..b0fa81cee3
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-mbr.qcow2.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-mbr.qcow2.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-4096-mbr.qcow2.gz
+M'XL("&+N+50``VEM9RTV,W@R-34M-#`Y-BUM8G(N<6-O=S(N;W5T`*V8VY+3
+M,`Q`W_<KS!T6*+'DW+BTL+#,\`8/P'-Z^XH.WTY2*[&C2/&VDS:3:<?5&=D^
+M4I-DF7\9DUOC"N-J<]R:]CL=8*(OX\.<?GW_L8I?IQL/LYD2)0R4AP$W8OT+
+M.-!PF9T.6!D798<"#OJH*2B%<VIV<P,"[O;FO'3GS:A8!%X#]#AU,Z[*#WQ^
+M/,)=F1\LG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.gz.uu
@@ -0,0 +1,12 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-mbr.raw.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-4096-mbr.raw.gz
+M'XL("&+N+50``VEM9RTV,W@R-34M-#`Y-BUM8G(N<F%W+F]U=`"ME,V.A"`,
+MQ^\^1<][(`5E92Y.LLG>][(S9\;5I_#AMUAURN#'F$"18`J__$L+B-P`*@/H
+M5\9MQ_"E8AN*CV*DZ<<YH$-`G0`5`1G7$HX6D$QOPUCVX3>,P8&AM_3?37/N
+M,!!!7<FH-4K@_I9=:=]VC#C9GN'VYX#6@O<)\'?69W9EG-=7=YGSZ\:"L354
+M%NPG./.NPOOW[44AXW2N@!EGCG"S8*Z@-=Q5X$IR]F(E5^*T2]:=G`M<P]^,
+MJ_;4T4E@M^;8#-;F+19'%N^3>0;=@2X!W>0S,7#)+SSU75(9)@IW1Q^DX?J`
+MJ^/U6N#,0;@0XQ[+R[*2PH/3:U)U;>9DZ->;\>;-#9#XYC+.Y'T(+N/+0A5(
+<J])QVS'\J-@86$W`;"<87C[$XA^HPB9UY08`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-mbr.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-mbr.vhd.gz.uu
new file mode 100644
index 0000000000..2927077010
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-mbr.vhd.gz.uu
@@ -0,0 +1,19 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-mbr.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-63x255-4096-mbr.vhd.gz
+M'XL("$$UQ%4``VEM9RTV,W@R-34M-#`Y-BUM8G(N=FAD+F]U=`"MESUOI#`0
+MAOO]%2-=EP*9P39.LRM%2G_-);5-(%J=+HF2*U+PX\^##=@8V&S."VN!S#R\
+MGB]DQMP/0%8@.Y`M2$'7-0=Y"[4"L)/^Q&$L_2WTS>M+V_P]?Q;^UQ\<K&2A
+M56Q.]E@!MR^I`36]1#[1-?0CIOAQ_WQS_O,\XM#CT(-$3585@C3)>SH#C#MU
+M1'H\X^^ENBI5-UNY]W0=5%WP1!6J*XI3B./6RCY/IP`C!_^,9W03382X2)U@
+M"ZM`YII3V;S8-9S<L[H&=W/PL7"I8A.CMB,#64*-=&W39O1#<MI4^?QXT^\?
+M[4(?;J2*G/25R9S:7B[Z5,$IL$X!I]3>6RX,E-<E;B55_LM[,K;C_L(Z@8EQ
+M`H?EQ]Z;41#JDR7;\?EV,#;U:=+';9WIE7%[HK\KXF,"&G,=4#%7'3%N6K!I
+M?'4PT()&JM+2UZKW7V/OVY6`G%S9'@/_F:?,\37==4`A0.L$^&O4U^S*N%Z?
+M4IGCJX:$L?W8MG,A0>%7%3[>/ZS4K](;[>![W4]IO(0;!8?=/L:=`ESERFVF
+M!,TIRKOP.L`=W7_$\3UUU!/:M8G-Q8K,R:+5PBZ,,Y0ME!4U8S9UK0`XQ1=F
+M?;>I#(R6NZ,/TN5JPM7Q\V6`PPO+A1AGILZR$L(+WCNFZIK,P3#+ROABY1(D
+MKER'P[R-0`^=Q6:@?2H=MR?ZGT5\."#Z3U&V;QOZ9II-(??`;`HML,VL4.?]
+M?DCA@I)IHT"XC!L%PF7<*!`NXT:!<!DW"H3+N%$@7-:-@@7:W#O\`W7?LJE=
+##@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-mbr.vhdf.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-mbr.vhdf.gz.uu
new file mode 100644
index 0000000000..d010e94ca3
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-mbr.vhdf.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-mbr.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-63x255-4096-mbr.vhdf.gz
+M'XL("+HEAE4``VEM9RTV,W@R-34M-#`Y-BUM8G(N=FAD9BYO=70`K94[;\,@
+M$,?W?(J3NF6P>!CL+(E4*7N7-K/MX"B*VBX=.OC#]P#C\+#SJ#`$X1S\\C_N
+MN!!B'X"2`6EFQF7#\%J$;5BM5X9&V^>`-0%"$V"!0(OK$(<+4&8C],A[_:I'
+M;2"Z=_BNQKGM,""AV&'#9UMXN..T*^W+!H/SGZN[_7-`(:!I$N"[T\=NRGA>
+M7Z4RQ[<V"2,J*`4("35[5.%A_Q$IM#B:RV&+8_=P3K#-H#G<SL-Q-/;>2IN)
+MXRX_[_RYA]O:C\.5M]3A21`U9UAT5N1-EAI;N,^/,U`%E`.I1QL+@5-\X:IO
+MD\I@@;LW]$'J;J-Q5;B>>CAVQUT(<>U4669">.?TMJFZ+G,P:'PS'KRY&A+>
+M7(MC>0O!QE06S$!<E8[+AN&M")L%EB,PUPE2]]\F.<@>I`(I]+PJ06Z@JGT@
+M"S-IZ+Z_5/=S_O4B;'#4%H/9KO<SKF^+K(`U^D?D4<\]?2_[T_K\>7(X5ZI<
+M1<++AKLX`]E&[M+8W<.976)U/#XD&IT>TSK]LH??!*>W\W'EY*SJH3T:G.O!
+>2V"8*U4&)TBTZ[^QM3B9.57P?W?U!^R^27D0"0``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-mbr.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-mbr.vmdk.gz.uu
new file mode 100644
index 0000000000..f7ffeae7c4
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-mbr.vmdk.gz.uu
@@ -0,0 +1,84 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-mbr.vmdk.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-4096-mbr.vmdk.gz
+M'XL("&/N+50``VEM9RTV,W@R-34M-#`Y-BUM8G(N=FUD:RYO=70`K5S1;N3&
+M$7SW5PSDMSPL6,LEN7PX.W'.`8(@@!$[]FO(Y3`68M\==$*0`_3Q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I76XBAT1:EYO((9'6Y29R2*1UN8D<$FE=;B*'1%J7F\@A
+MD=;E)G)(I'6YB1P2:5UN(H=$6I>;R"&1UN4F<DBD=;F)'!)I76XBAT1:EYO(
+M(9'6Y29R2*1UN8D<$FE=;B*'1%J7F\@AD=;E)G)(I'6YB1P2:5UN(H=$6I>;
+MR"&1UN4F<DBD=;F)'!)<E]O((<%UN8T<$MY4#@EO*H>$-Y5#PIO*(>%-Y9#P
+MIG)(>%,Y)+RI'!+>5`X);RJ'A#>50\*;RB'A3>60\*9R2/199BB'1&\JAT1O
+M*H=$;RJ'1&\JAT1O*H=$;RJ'1&\JAT1O*H=$;RJ'1&\JAT1O*H=$;RJ'1&\J
+MAT1O*H=$;RJ'/&=99BB'/&>F<LCSRU]-?`SN9;&3W/`RECO][M*7?V_?>/KF
+M-/^3`-'^-L!)$+<$9,$7C(_RR'XUX_\)\SZ8>2\%WP;;KQ3\]?!G^/CJ)'"=
+M<?_0_S;`HG!-\P+PG\SO_-DT?GM^E3<^W^OXP!15^#6[1>FNYZ,9_O3MCXL,
+M)S@S_>P$M_OUD5C0?@ON:X$+/P_TXCG[3>#ZW.FUP'TU?1+N\KGL=$%UK%CC
+M7]U]S:Z+.#WG\'TGT('\7]YY#IC.USWG5[],XSPK]S/YN9?EAN^Y^LMK]3QF
+M8WJC7#>':]-D63G"G>Y]]3*[F_%A8/F5<?`K-X#,OW(GN+/M(*C'R3*I/E[^
+>O7WCZ;O3_,\$>(F`9AV\A%],DGWQ?Q6YC7-O8```
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.qcow.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.qcow.gz.uu
new file mode 100644
index 0000000000..7cd89e997c
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.qcow.gz.uu
@@ -0,0 +1,127 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.qcow.gz.uu 272073 2014-09-24 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PU[I#O6']GKK_[F+G[V+A#OF/]G;G^[F/F[F/C
+M#OF.]7?F^KN/^^'LD.]8?V>NOZMGU^:0[UA_9ZZ_`W/(=ZR_,]??'>?0_7?&
+M^CMS_5V9^]3FD.]8?V>NO_M4YBIWZ/X[8_V=N?[N4^;N4^4.W7]GK+\SU]]]
+MRMQ]JMRA^^^,]7?F^KM/^^'LD.]8?V>NOZMGU^:0[UA_9ZZ_`W/(=ZR_,]??
+M@3GD.];?I?*.F[MM<\!WB?5WR?5WMV6N<0=\=_<4YBZY_NXV<W?;N`.^2ZR_
+M2ZZ_N\W<W3;N@.\2Z^_J6YD[],;H_KOV5##WS8]??[CY,MB?/W\X]:=!3WWW
+M^2WIJ;-32I_+CR\9Q08'?_KOY?*W__Q#[5_?OKX>W;GTYU[???;D^X/CZ3R=
+MS@H'O\Y]P]X4SGWO]7V=0]_K_4_,H>_U#N<^4W?W!YB[WS(N;NZ7;^;0]WK_
+M,[\8QZLYRA]3SO8'/MUZ-8>U?_CZY;>M.[N0.6ESG_Q<^W35/:6G]CQX=2?X
+MZMJ7VG+W;X5V_ZGO?K)_1W/H6]O_<530U1QX;IM/RQTG<KJN?`Y=S?%G4!F^
+F#'Z6Y@S^SC_PZ\\_WO_KZV#*@W_9*TQW7CF??_@_"8E_G;^F````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.qcow2.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.qcow2.gz.uu
new file mode 100644
index 0000000000..0ec443be75
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.qcow2.gz.uu
@@ -0,0 +1,21 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-63x255-4096-vtoc8.qcow2.gz
+M'XL(",0[(U0``VEM9RTV,W@R-34M-#`Y-BUV=&]C."YQ8V]W,BYO=70`K9C;
+M;M-`$(;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63x255-4096-vtoc8.raw.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.raw.gz.uu
new file mode 100644
index 0000000000..838d73d372
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.raw.gz.uu
@@ -0,0 +1,11 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-63x255-4096-vtoc8.raw.gz
+M'XL("`;&'50``VEM9RTV,W@R-34M-#`Y-BUV=&]C."YR87<N;W5T`*V206[#
+M(!!%]S[%7W=A,8!MO*J45ME5JM0+U#9P@*PY?$AP0HRQXT0>T`AIYC_-%\-8
+M"$#6:#CJZG(E1R4@)00'A']I^);DPAU/QAS^OKGX*:_AB@`C7YSWCZK%@BN3
+M<,7'"%03':T#%5@+QK/`@&NCJGV*6YLOX+J][`9<OQ57^ZRA#8Q)</\/N&'G
+MSZ"970,*#_&&7;K9%;'9VDL6=@E'$?>9XJ)=GJ@XHCXS';+3Z3NN'R#%5+5J
+M]BN',[NN"MFM.-VA]WM"L,,RCJ\.\>JJ-%I=@97OZC)YN>!^R^D)P'X$[C4A
+.-4K5C!5GC7NA2P,%````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vhd.gz.uu
new file mode 100644
index 0000000000..d0d28ddd1e
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vhd.gz.uu
@@ -0,0 +1,18 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-63x255-4096-vtoc8.vhd.gz
+M'XL("$DUQ%4``VEM9RTV,W@R-34M-#`Y-BUV=&]C."YV:&0N;W5T`*V62V_D
+M(`S'[_,I+.VMAQ$QA"2G2GWL;:65]K#7DH14HZH/M3W,83[\VH$TD-=V6C(H
+M`H%_^=L8#T*X!T!+T!UH"SKG?J%`5U"4`#3I&_;OS`_AU#P_V>;]<-S[Y[1S
+ML$R$5K$YVZ,$11\I``U_1+?<A].`V?^XO;\X/-X/./0X]*"\8"N)H.O)=S(6
+M7&JGCDE_#_C0(X^C.CE5%UKQ6$+7@>R"%7)0YUR]#)U59$7KN>50YWU\AA8-
+MHHG1V4GL<C&Q"I0N!56,SB[A]);5.;B+G=\+ERH4L8+>`C1%#[E/:3/$8=8H
+M58YO+^;US4[TX4JJC)N1S>::=7?1IPH.B[T"-4^5V%WH*0]3W"Q5OAD]'=NI
+M.$CAP*V@Z(A\W5T]1@^'H%$CU:+8VHQ][Z^8X5!L6&WA5MPU[*[2G"!<5')0
+M"#F=?<6'%R3UVL7X_7RU]NK/#<I?D3ZSDBQ?W@Y31G;_.6PEB(J+T.IVF&JT
+MJKY_=HU)Y:[#U9_%4<T0+;06K)W@[@)<DW@SZIF[ML]_T9??L]VM!W?EN-B=
+M*ZKL*[B@+E].<4UTU,*&,-HOJ(-%=>T'KFY`R=AJT]GK)9Q-FBIU]UE<:Z"F
+M/,F@VZC*S::(<U,%?5U)5J@PM4+9EI:GZ:]<F(7W^L3I]S[^.:#R"I.Y3,"T
+M"K4')E.HZ1*95&'15IATE\NB[/,PT;V9<0GOS8Q+>&]F7,)[,^,2WIL9E_#>
+3S+BD]V8"TOG=_0-Y#+@L;`T`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vhdf.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vhdf.gz.uu
new file mode 100644
index 0000000000..b9858fa55e
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vhdf.gz.uu
@@ -0,0 +1,14 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-63x255-4096-vtoc8.vhdf.gz
+M'XL(",0EAE4``VEM9RTV,W@R-34M-#`Y-BUV=&]C."YV:&1F+F]U=`"ME#MO
+MPR`4A??\BB-URQ"9A[$]1>IKJU2I0]?:!J(H:BM5'3KXQQ>,$P/!;AH9(T0$
+MY^,><KE9YAK`!0H*D=O.*7(&SL$HP,Q,PFR).KK'+Z5N7^XI>]KTK5LY&#&+
+MY_L'U>1"MXE:MUH/P#+0D7E@B:Q"1I-`AZM&5?4G;BX^AZN7LNMPS:4X848)
+MJ:!4A'OS<.W"?P8YLZM`W(1=89<<[;)QL]9V9'H*1T;<-L:-=FFDHACUB>B0
+MC$Z><$T+SD+5K-F[%$XMFBI$7XJ3-1J3)P2ZG<;1V2#^FRJ%+'M@;G;5B7%Z
+MH7O>A)\#-@-PJ0A).50^P2`TA.J+'T/!(2H4I0^D0=Z@:S\_5/N]__%NL,?9
+MRF>R-]FMGII::@XI0&M[B)!V[L5W\[!;[]]W1QP=7-'AX+RP*E.411/9)2A#
+MNZ][>HBC8_$E^2KW!DV<3(>/QK^]K8_C)[.F`)GG8>_GV(,?P4(J^WI<GD6J
+4J]]&CQ,+IXK)O=4O0#"/42X'````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vmdk.gz.uu
new file mode 100644
index 0000000000..2e60546bbd
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vmdk.gz.uu
@@ -0,0 +1,83 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-4096-vtoc8.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-63x255-4096-vtoc8.vmdk.gz
+M'XL("`?&'50``VEM9RTV,W@R-34M-#`Y-BUV=&]C."YV;61K+F]U=`"M7%UO
+MW<81?<^O(.P^%$4A<,BY).^#43=1`A1%@"`.VM?P8]D(36Q#%HH:T(_O+KEG
+M=:A[Z66C<:A`XSMSM#/D/9+/'*@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+M179-3>M\9+[(KJEIG8_,%]DU-:WS3>R:FM;Y)G9-3>M\$[NFIG6^B5U3TSK?
+MQ*ZI:9UO8M?4M,XWL6MJ6N>;V#4UK?--[)J:UODF=DU-ZWP3NZ:F=;Z)75/3
+M.M_$KJEIG6]BU]2TSC>Q:VI:YYO8-36M\TWLFIK6^29V34WK?!.[IJ9UOHE=
+M4],ZW\2NJ6F=;V+7U+3.-[%K:EKGF]@U-:WS3>R:FM;Y)G9-3>M\$[NFIG6^
+MB5U3L<ZWL6LJUODV=DV=3.V:.IG:-74RM6OJ9&K75%>6AG9-=:9V376F=DUU
+MIG9-=:9V376F=DUUIG9-=:9V376F=DUUIG9-=:9V376F=DUUIG9-=:9V376F
+M=DUUIG9-G<O2T*ZILZE=4V=3NZ;.IG9-G4WMFCJ;VC5U-K5KZFQJU]39U*ZI
+MLZE=4V=3NZ;.IG9-G8WMFET97M8&O['W%'X/[&GYG;!U^.V?=?C]UM<`O[MW
+M[NMWMU7]/9^ON_A-UB\^7[>IDR\#=LM2M-I]6+KR_%1USL)]Z7PK7&_5[@HW
+M'(5;-S>3*YQ[!O<SP5D_+'+1KH/"6_^.=@7MDN`T+V_6>MZ#DR>XOSR'>VKW
+M^;NM*I[JKYRNN'JZ*<$-8_C5V,>G]\TU.&?ZJ,A\%&[JB\$_)U+,XSY<]<5#
+H_/^/2K\`KOZ`R__OO^"_9VS_6P$U`IJ=4/U[HRR_^A][EZ;PS5\`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-apm.qcow.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-apm.qcow.gz.uu
new file mode 100644
index 0000000000..0d3e9da677
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-apm.qcow.gz.uu
@@ -0,0 +1,127 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-apm.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-63x255-512-apm.qcow.gz
+M'XL("+4S(E0``V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]7?F^CLPAWS'^CMS_5V>^USGD.]8?V>N
+MO_N<YPIWZ/X[8_V=N?[N<^+N<^4.^8[U=^;ZN\^)N\^5.^0[UM^9Z^\^'Q=G
+MAWS'^CMS_5TYNSJ'?,?Z.W/]'9A#OF/]G;G^#LPAW['^KLD_<7-?ZASP7</Z
+MN\;U=U_R7.4.^.[Z*<Q=X_J[+XF[+YF[YHR?(G_OL?MBO^3>^$V90W_?=GDJ
+MF+OSX^M/5]\&VV_OU[2G5D]GK4_<7/\V?&_P7_[C9N:!>[_V-W^_;_?+7)]6
+MLUX\9W<'Y?XGOO[R;W[P=N[F_9IOX=CU1W?]WZ?;'WJ_WQW'WS8PA_Z^\O_7
+MEWL[9Y=OUWZS2B>G4Z^GOCEU8_IG=RVI[>;3Z>W^?$Q__\=?__'7__ZO/^>Y
+MFW]?=.O-P_T_\W;_.1WP[=#?5_YKOK?-#WYO<Z*1?^?>_][FW[DM^K/EO^[]
+MOGT[NIN#O_Y&7'\T>FKMU#0W?SSBU+8WGVOM<O#GOV_;[__XA]=_^OF/=\\/
+M_7'P7_5^W0^<G]XYO]O?)'?/[W3W_="?W?IU[_?=\^OMU/>`S7I^__._MR#F
+K]_NMSV](YW>>P#_Y)[[^\N;^?VX'FS3XF[UA<[[^!I]_^C_<Q@LX=*8`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-apm.qcow2.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-apm.qcow2.gz.uu
new file mode 100644
index 0000000000..44b9ed800d
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-apm.qcow2.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-apm.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-63x255-512-apm.qcow2.gz
+M'XL("*H[(U0``VEM9RTV,W@R-34M-3$R+6%P;2YQ8V]W,BYO=70`K9A);]LP
+M$$;O^15,]Z9-*LZ0E-P]FX$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+*`W"Y1,`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-apm.raw.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-apm.raw.gz.uu
new file mode 100644
index 0000000000..9d92868989
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-apm.raw.gz.uu
@@ -0,0 +1,12 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-apm.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-63x255-512-apm.raw.gz
+M'XL("/7%'50``VEM9RTV,W@R-34M-3$R+6%P;2YR87<N;W5T`*V3S6K#,!"$
+M[WZ*Z;50(\DKJ3FFM+D50D//P=0.!-K4I(%>]/"5(HG(/PDN:+T(BV4_QK-K
+MQGP`)"$%F$T64G`PPN4^2)B7M]+&71G#%![&V8VNZ[AR$*:X]T#ARI*!FE%?
+ME0)YOV#6KT.@QSE]Q*&92_4!)6?I6W;=9SN!$[D^U^.JL3JY.[]S0`MH@EJ$
+M4^V@6E<.ZK9=?3SM3_OOPS;BR.)4XYKU?]1]U=VD.IEYMC1SMA27,@#[LT74
+M1[EWC\[C4,YX.PB;)"`K$$$T5KAT-7L?`5?'MGW:/#^\KS:I?T29]:D9_HG$
+M/_^3I/XAU:=R^Z=N^J<K:#VQFQ?_?G[](D9]N?U[#/ZQ>N*\7C#KLO]X(`5@
+/-H4D'+#X`^%)]I"G!0``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-apm.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-apm.vhd.gz.uu
new file mode 100644
index 0000000000..33445c89fe
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-apm.vhd.gz.uu
@@ -0,0 +1,18 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-apm.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-63x255-512-apm.vhd.gz
+M'XL("!LUQ%4``VEM9RTV,W@R-34M-3$R+6%P;2YV:&0N;W5T`*U62VO<,!"^
+M[Z\8Z"V011I+\N:2DM+D5@@-I<?@>.5@FL>274@.SG^O1@\D/]DDVA7"1IY/
+MWWSSD!AS/P!5@&I`:5"2GDL!Z@S*#8!9]`/MS/TK=/7SDZX/[=O:_[J5`^,L
+MM>J;DST6(,PF)6!%FZ@M/4,78-;?+N]/VL?[`(<>#CV0+,FJ0%!WHWW*+6S<
+M/A;N;XO_+.1[9%>,V44KYV#30-$D7Q2!W;N=OZ?."F-EOJ<AX:ZT^H31>^DM
+M1&<'VDDVL$IH3HG*HK-3<&K)ZB-P)RL?"Y<J)C%*,S-0'$JD9Y,V08?1,*GR
+MMM]5+WL]X(<SJ:*28`S7Q+R[Z%,%P\>>@2""2^Z"1=D/X292Y4OJJ;Z=\`]&
+M!";#`EKW^^I%*$CY*<X6-)\/QBR_BOB9TI08J\V,0D/-EQR^_$TPY\-P5#/1
+M_;1^-2V;"A';D5TOOKR_T%W_FDR7FO@)3FE,F5Q3#A_#[V*W>]`3<)C+70=7
+MC-G)QM><+3K7HNWL6K=L`KM;4VV']M`^/]T&.&I4U&HMXO'L'JO=)#N9.;;Z
+MR-B&HD$/V(\M!'XZ=^YI&PY%PM,)*4$@2'.0"<"M(2YIS;R/`*]>M/YQ\_/T
+MS]5-JI\6>?EQ=H1^F.CGBB35+^TM?.X0_SR_1?WH,"DG<C/JMW]UB1CXY=8/
+MO7ZLFICG%[KK=?_O`-$WTVS=&6/WR\-0>,!L#$6LX5P,N5H,YD>CK'!C7<YT
+KU26XC%==@LMXU26XC%==@LMXU26XC%==@LMZU36`)IE7_P%G#2J)'PT`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-apm.vhdf.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-apm.vhdf.gz.uu
new file mode 100644
index 0000000000..ca2fccf138
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-apm.vhdf.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-apm.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-63x255-512-apm.vhdf.gz
+M'XL("(LEAE4``VEM9RTV,W@R-34M-3$R+6%P;2YV:&1F+F]U=`"M54UKPS`,
+MO?=7"'8K+"2V;&>G?;#V-B@K8\>2Y:.$K6WH"MLA/WYV;*]VDI9NV!'&1M'C
+MZ<F6XU@/`&3`",328F/8S<=]SZ"=/4=RW$5VM!,-EIR+.@T7]48[F6I`HMQ,
+M$BH&<=0%3'Q'NWCJ`VHXQ0\3$+$RG@-G%_&[;YJ/<@2.A$I7P]$A.U9UZP1`
+M$!`(_,;,O`)>*K=AMVJR_:$^U+OMRL+)*@(O5+#X"[M-UHRR8X%KBQ?6%LV"
+M&$"_MF#Y8>BSAUTYN!)>%D(:$F`4$($4DCA3/KD?`,[W9?FP?+Q^F2]=_1`#
+M\^,7Z$<<_?0E<?4#EQ\/K1\_JY^@(,3(V3SJ]_FE#Z+E%UJ_U.@79R/S:4>[
+MB/Q/`Z(!#,8P-=V94W/7E8C4]H#4!23'\G:`^6Y;YH?ZV[W!J>G.535N*IY0
+M]19P`23K6DRAU@Z_J]EZ6F_6%LYV/_MP,*&BJ"SWVR#=U$_WM2;O?79T*%+J
+MJ9<HGK3R$O?4NW7A\#?9LH1<ZV/-VWB.T=ZLX+KNY_[\W]IJ.![XJ,B'<O(#
+(T:JTQ-('````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-apm.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-apm.vmdk.gz.uu
new file mode 100644
index 0000000000..ed79e4b6c7
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-apm.vmdk.gz.uu
@@ -0,0 +1,83 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-apm.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-63x255-512-apm.vmdk.gz
+M'XL("/;%'50``VEM9RTV,W@R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^;:)?A%AOFVB7T28;YOH
+M%Q'FVR;Z183YMHE^$6&^;:)?1)AOF^@7$>;;)OI%A/FVB7X18;YMHE]$F&^;
+MZ!<1YMLF^D6$^;:)?A%AOFVB7T28;YOH%Q'FVR;Z183YMHE^$6&^;:)?1)AO
+MF^@7$>;;)OI%A/FVB7X18;YMHE]$F&^;Z!<1YMLF^D6$^;:)?A%AOFVB7P3G
+MVS;Z18RF^D6,IOI%C*;Z18RF^D6,IOI%C*;Z18RF^D6,IOI%C*;Z18RF^D6,
+MIOI%C*;Z18RF^D6,IOI%C*;Z14QI:JA?Q&2J7\1DJE_$9*I?Q&2J7\1DJE_$
+M9*I?Q&2J7\1DJE_$9*I?Q&2J7\1DJE_$9*I?Q&2J7\1DJE_$9*I?/*=I:JA?
+M/+^XE_#!="\WN^H#\V5]>>'N7:KW^EWO:OR%A-__Y-)\\VQ]N?GZEOOUNMNK
+M#B_B,DV([1N7]S^^5K]\N5]OOMS6U-W&=+U?[X'U?7MW]W%\)=V+>S'_WNVN
+MZ;*7JRLF?Z/?Y?Z=.>^6RWL*%Q-7]\M=>_]X\WAS^^D7IEONUSOXV[@>7]UO
+M[=VKJS.^%W.>'SQ;$I&S3[@]VX3KL[[W9YXOQU'R?L>%NXMNL=Q1]SS,"R_<
+M>T7V,N$/]^/XW8?K/_[MAP]:OSPW7E]YH'XJA5M_2+1^B:[/6GN<EU^L7Y4E
+M5?7*M?E4OX?_KA<BUV==O]K7S]W?^<5_]]^XO#]M_[<FS'U"LQ7F[N:SZ5?_
+)!]R'M=*37@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-bsd.qcow.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-bsd.qcow.gz.uu
new file mode 100644
index 0000000000..7f7c1eef38
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-bsd.qcow.gz.uu
@@ -0,0 +1,126 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-bsd.qcow.gz.uu 272073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>IO_N\S'7NR'>JOXO4WWV>N?O<
+MN*/[[T+U=Y'ZN\\S=Y\;=W3_7:C^+E)_]_F:SX[NOPO5WT7J[]K9]3GRG>KO
+M(O5W,$>^4_U=I/X.YLAWJK^+U-\M<U_Z'/E.]7>1^KLORUSCCNZ_"]7?1>KO
+MOLS<?>G<D>]4?Q>IO_LR<_>E<T>^4_U=I/[NR_7F[,AWJK^+U-^UL^MSY#O5
+MWT7J[V".?*?ZNTC]'<R1[U1_-RP?I+FO?0Y\-ZC^;DC]W==EKG,'OOO^%',W
+MI/[NZ\S=UX6[8<U/,7=#ZN^^SMQ]_;W-T;^WW8Y(?N+;V_3MVV\O?PYN?KZ^
+MP5?K/?RH/_'M;V_O_]<&?UX(L]FMALUJLUV-_F=?X?__S_^E5_AK[B][P[_F
+MZ!\8OS>WO.`FO)NY+W?F?@C^<N=7KNW.4T?K?UP?QYL_NG]\^_SVCI$W="%,
+MG_M!])D^(=\L_0/C_PTL-Y>NW/TZ_[QD-U;KY2_<T\V5[>N[ZJ^/(N9[;_</
+M7M_J]NW^E.CN_J^W.W->O-W5_;F?$KWS];SW)2Q.[_/MJZ-_Q/N_^6+<7!WR
+M)W_G_ABY_SOWUYS_M2+8_33+#\_MX4?]B6__>'O_OU^#P\_!W_X-BB07FH&E
+"````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-bsd.qcow2.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-bsd.qcow2.gz.uu
new file mode 100644
index 0000000000..0a66a1c4c9
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-bsd.qcow2.gz.uu
@@ -0,0 +1,21 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-bsd.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-63x255-512-bsd.qcow2.gz
+M'XL("*P[(U0``VEM9RTV,W@R-34M-3$R+6)S9"YQ8V]W,BYO=70`K9C;DM,P
+M#(;O^Q3F#`N46').'+:PL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d.raw.gz.uu
new file mode 100644
index 0000000000..136e51eb49
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-bsd.raw.gz.uu
@@ -0,0 +1,11 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-bsd.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-63x255-512-bsd.raw.gz
+M'XL("/;%'50``VEM9RTV,W@R-34M-3$R+6)S9"YR87<N;W5T`*V4.PZ#,`Q`
+M=T[AN4.4;TD7*E7JWJF=*853Y/!-@!2;$.@0!R(BVT_^X'`^"8"6P-N-/:]P
+M-T:7JT[52),!:&K0!LP9K#?GRT,.1.%>]R?#XF:<V//*X]A*(DX>X6+`:LCA
+MK@BGO')`EEP@KTZ`ZN<#_D:X9GHC3N]%YRO!^RU%-EE3JG:QMW;EA_L,H@>A
+M@-M9)RGPUU]8XKND84B2[DY\D*;;!EQ-[07"R8-T@>+>`8?Z25IX4+TFC:XK
+MW`RUGHP_)S=`Z.1..%GV(I#CS>+_0&^5[GF%>S"Z)J">@<4J6'^L)U9?N.5M
+%L04%````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-bsd.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-bsd.vhd.gz.uu
new file mode 100644
index 0000000000..a1a76ec7c8
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-bsd.vhd.gz.uu
@@ -0,0 +1,17 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-bsd.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-63x255-512-bsd.vhd.gz
+M'XL("!XUQ%4``VEM9RTV,W@R-34M-3$R+6)S9"YV:&0N;W5T`*V6R4[#,!"&
+M[WV*D;AQJ)RQ8X<+2$C<.<$Y35-4(191#CVD[\Z,%V)G*XN;U')DS^=_%EL6
+MPOT`M`2]`]V"+KEO%.@K,!4`#?H7;5OX3^B:M]>V^=P?U_[7K1RL$+%5:L[V
+M*$'1(@:PYD7TEOO0!<SZXN[I<O_R%'#H<>A!I6$KB:`WHW7,%BJWCL4][O'9
+M(D^].CE6UULY!W<[D+MHA@SJ3K:]B9U59$7S^2UA8VQ\PIM\)`.]LX/8E6)@
+M%<F<"JKHG9W"Z26KW^`N5SX7KE2H,`RU`G0!!KE/91/B,'JI5(Z']_KCT`[T
+MX4RIZ"@9PS$U[R[Z4L$PV2M0+'#)7;"4PQ`W42K_BIY.[93O4!!$&0;0NI]&
+MKT=!K$\78B'F\\F8U5>S/D4[H9YHYP>ZVW7Z?`,;!M)^I>U>:K_'?A+!Q[N'
+MJ?PV,^7RQ]W1X#E<$!R?!BGN)L))EXZ>$A4O-`7(UG_$_0AW[?X!IY;4<<VT
+M4P.SSI:9B[FI!G9QGJ%HH9`@JJBJ(^!W?J'7=S66@8F["_I@[&[-.)/.+R(<
+MGG$74MS&G\MA9I+",]&['JMK,B=C.]P9/]RY#$EWKL-AWH,`[<E"%4BSQNW\
+M0'>_3A\'1']493O[,!Q5N10J#\RFD(!M9H78+A;;;ZM08V5=SG219%S&BR3C
+B,EXD&9?Q(LFXC!=)QF6\2#(NZT62@%1[JR_1)]26?0P`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-bsd.vhdf.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-bsd.vhdf.gz.uu
new file mode 100644
index 0000000000..21864efdce
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-bsd.vhdf.gz.uu
@@ -0,0 +1,14 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-bsd.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-63x255-512-bsd.vhdf.gz
+M'XL("(XEAE4``VEM9RTV,W@R-34M-3$R+6)S9"YV:&1F+F]U=`"ME#MOPR`0
+M@'?_BI.Z9;#@>)@L350I>Z=V=EP<157;I4,'?GPA-C%G_*@J`[:,COM\#^X8
+MZP:`1&#UQ'M>X)Y*.EVQ*VXT#$!5@52@-!A_G`V+;(C`O9Y>RG2X'L>7M.9Q
+MY6A$'*[AHL&BG<,=$ISPPC8YR7BBU7`0=MC+"=RC?XX#3BY9YR/![)1@UEFU
+M5>QB;LU(+\TS<`M<`#.]#"GPGE\8[-OG9B!Q=\$^R-VM`ZZBYWF"PQ5W@>+.
+M`<?)X2&%*]$[YM8U&R=#C"OCCY4;(+1R.QQNVPCPUEG\#?2G\O>\P#V7='9`
+MV0,WBZ#I>Y\6H%O0%K0*WY4$O8?*I$"D-\DU7Y^V^;[^I!D..-XU@\D5]%&$
+M:M$58!U^HM_"=V+?P^FRNWY<(BZVJMB1?+%Y+8&@SYF[9E1L5WP?6R?R(!D2
+M/1[L3-N>_S.)WB'%R;NSUD+3Q2<NLB&"R585<(J-M/Z;VPZG-[XJ_O(5OUHQ
+&I0DP!P``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-bsd.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-bsd.vmdk.gz.uu
new file mode 100644
index 0000000000..bb75998dba
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-bsd.vmdk.gz.uu
@@ -0,0 +1,81 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-bsd.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-63x255-512-bsd.vmdk.gz
+M'XL("/?%'50``VEM9RTV,W@R-34M-3$R+6)S9"YV;61K+F]U=`"MG%MO(\<1
+MA=_]*QKR6QZ(.9S[PR:.(P<(@@"&;=BOYMQB(?;N0BL$68`_/M,S?5IG1(U[
+M8)7,7;*65<7NZF&)_NJ`6;;^.%=TKBA<,;BR<AG<_$_KS67YLS'?BOC$]9_W
+M__KQQ)^O3J?K%VLR^"@)0:;IQ-B\SO7TXH?ISK\7M7EBOIV3Z7(?U=T$AG3G
+MG2=VT\WU<.?70KBZR_+TX!](.A<3N4VZ\I4][6[V]U;WIR]"\?SZ<K^&^7BK
+MUM6YJ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R52_B,E4OXC)5+^(R52_B,E4OXC)
+M5+^(R52_B,E4OXC)5+^(R52_B,E4OXC)5+^(R52_B,E4OXC)5+]XSK+,4+]X
+MOODNX8/I;C>[Z@.+97WKMX/>_KW_Q/7KT_:_F'#Y@MVR]E]T6E:N.1]=X4_?
+M_/C*AHNSV8;7=#=?GOPR7>1=TUZZOT@ZW^`G\=Q\%W,/EX_/=O%*NC^?Y)NB
+MB^4+=G=7IW.*8YLU_O+D8OD26_75<_8=QH,??IY_\=Z(Y^N>U]?>+N.\V>[O
+MK,_=;M<W4?WZ4#V/S;MU9[MNF\XW43W/S1$FJO?5[>IZX\.X^2K6@^]<GV3[
+FSEW3G6T;0;5TEG7X?_OW_A/7;T_;_]:$Q9+PB_\#AU-ESJ!=````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-ebr.qcow.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-ebr.qcow.gz.uu
new file mode 100644
index 0000000000..10943b7245
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-ebr.qcow.gz.uu
@@ -0,0 +1,128 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-ebr.qcow.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-512-ebr.qcow.gz
+M'XL("%+N+50``VEM9RTV,W@R-34M-3$R+65B<BYQ8V]W+F]U=`"MG=F.5-D1
+M1=_YBF2&8LJ(N"-#5<F2+?G-?K#]VG=\S@]`_G8#=8:JN'L3M+MIU`+1=ROS
+MU,I%V[UT.)_OOIU.K9R:[M2,IWT^??MY^BZG>S]Y^/WT]9]_^_O[^]^^/KH;
+MD_-/GG(_[[<R]V#KOW5.OS^UG,[C+\Q]^RYH[MZKL]_QZNZ]V>/<U:.[-XN?
+M4S9H#P9/:>Z<7I^0TVM^[?7=NK<K=Z?WY[U=)6^W_;7!?[C7I[\+EE]Z?;_S
+MZ]O!P=_*ZVO@4SV;&Q[,70YOMX5/C6QN^BG,>N[@4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/H3_F
+M^0^]7?0G,_]DL&U/TW08_%=^?>CFH#_R^KH?_U.JT=-Y`G_GO_#U+^\?_I4'
+M^Q^?W;8_->VI[4Z#_NHK_,]?_PV^OCWZ[/Y_;_AN#GQV'\[E%UQ^.SO,W=R;
+M^_[9W>_]DV>Y]]1][N[_^-[<]?M[O]_VZ+-;Y[[[:D._0-_LG_S9[0_W0][_
+M.O^X0ME.Y_R?4]R]I.7K>ZJO#_7X#][N3U[?Z?AV?_S[0/_PGY=[<QJ\W=/#
+MN;F8!7P)@].[/KXZ].?1_Y$OQN&6PU_\Y'X?>?C)O9O3/U<$PP^S?/]=;`)_
+@Y[_P]1_O'_YU-]BDP3_M!)MO])W/C_X'"T=/.U"H````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-ebr.qcow2.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-ebr.qcow2.gz.uu
new file mode 100644
index 0000000000..e8ed0d6bb2
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-ebr.qcow2.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-ebr.qcow2.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-512-ebr.qcow2.gz
+M'XL("%+N+50``VEM9RTV,W@R-34M-3$R+65B<BYQ8V]W,BYO=70`K9C;DM,P
+M#(;O]RG,&18HL>2D"8<6%I89[N`"N$Y/3]'AV:EK)784*=YVTG8R[;C_-W+\
+M64U:%.%A3&F-JXQKS&%C3I_I!2;Y,'R9XZ_O/Q;IXW@38+904L+`<M_C!JQ_
+M$0<:KK#C`2OCDNI0P$&7&H-R.*=6-S4@X&YOSJ?NO!@U2^`UP(!3%^.J^B#4
+MQQ/NROI@[OI0/G]EE^,#U71]&.KCJ:6&J[,X$%*-AFNS.!12&PVWS>*<D-II
+M.&7G)KA22!T4G,VH<L)50LIJ.,CBED(*-9S+XFHAI7EG\]XU0DKSSN:]:X64
+MYIW->[<14IIW-N_=5DAIWMF\=SLAI7D'BG<FXO9"2O,.F'>/"/<XX@Y"2O,.
+MF'=/"/>TQUDII7D'S+MGA'L><4*_`\T[8-Z](-S+B!/Z'6C>`?/N%>%N(T[H
+M=Z!Y!\R[UX1[$W%"OP/-.V#>O1UY9X5^!YIWR+Q[1ZPBXH1^AYIWR+RSA(.(
+M$_H=:MXA\PX)YR).Z'>H>8?,NY)P5<0)_0XU[Y!YMR1<'7%"OT/-.V3>-81[
+M'W%"OT/-.V3>?2#<QX@3^AUJWB'S[A/A5A$G]#O4O'/,NS7A/D><T.^<YIUC
+MWGTAW%W$"?W.:=XYYMU7PGWK<2"E>N^*0GX1[GZT9V'>ZT\7KX^M<-0')H#U
+M)<"I"@.NF77"9=@;%P+E"0><WQMA,FW9F6S)9\IO;=P5:7WK8/,JQ>WFGN[A
+M,F!9FK8=`7]W]<%D&9?7M]S[8;\K6^&H#QSO%L-G!ZS#OP-+O\G*RM3PT`K_
+MWO\1UK>>[X8OX/1_!VB@*[COB"/<.L'Y"XQ#\LUT6PV\2]\GN-4B=N83;O+?
+M`7_+LY<&U,F6\\I2][VEMS599W^E[6^(NA];=J7<KZ^)]0F]!0;3G:C/C*?K
+M?\3[FVVV'AX'F>F:(6[3=Q9A"3-G;S6N;COS8EB^,QZX<SUDN',##N9M!,VY
+CLYP,/'UK?-0'CC\7PV<`.@+.=@9=Y7][;_X#6VG_\](4````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-ebr.raw.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-ebr.raw.gz.uu
new file mode 100644
index 0000000000..923685a35d
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-ebr.raw.gz.uu
@@ -0,0 +1,12 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-ebr.raw.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-512-ebr.raw.gz
+M'XL("%+N+50``VEM9RTV,W@R-34M-3$R+65B<BYR87<N;W5T`*V4S0Z#(`S'
+M[SY%SSL80)GLHLF2W7?9=D:G3^'#KQ5U(/B50(5("K_\2PN,F0:`/?BM._IT
+MT?KDD@PT7I\'\B#0X!K:Q6F9EC1F'4UIG'$-SMN`O@H-6VGCOK'#[<X!I02M
+M/>!KTB<BIZ-HR9T+8#HPKCOZ>^K:!%1#P<@"<@GR"DH<5?AYO`/Y58S'"MC@
+MQ!YN$FPJ*(2K+%R&SLY::2IQW&77G?UOX4K3)UR^I0Y/@K4AQVJP,FZQ*#1W
+MGYUGX"WP#)@:?<(%SOF%O[Z;+T,XX6[H`S]<3;C"7<\MG-@)%UQ</;\L@13N
+MG%[IJVLB)X,O;\;!FTL0]^8:G(C[$-R&EP4K$%?YX[JC?Z:N&6`^`J.=(+U\
++C"4_RQ*HU^4&````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-ebr.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-ebr.vhd.gz.uu
new file mode 100644
index 0000000000..d6ae3bce60
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-ebr.vhd.gz.uu
@@ -0,0 +1,18 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-ebr.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-63x255-512-ebr.vhd.gz
+M'XL(""$UQ%4``VEM9RTV,W@R-34M-3$R+65B<BYV:&0N;W5T`*V7P6ZD,`R&
+M[_,4EO;6`PHF"?0R(U7J?2_;G@.%:K3:MFKWT`,/OS8)D!!@.MT,3!24^.-W
+M[!A%"/L#T`7H#G0+6G&_E*!OH:P`:-#=.+2Y>X2^>7UIF[_GS\S]^H.%Y<*W
+M"LW9'@N0])(2T/!+]!/WH1\QV8_[YYOSG^<1APZ'#J1*MBH0=!V]IZM!2*N.
+M28]G_+U45\3J9BO[GJZ#HO-F%+ZZ+#OY.$E6-)]O!;4>UF>\@X=@P,<%ZI18
+M6'DRUQ95S,ZNX?2>U36XFX.+A4T52HR26@$ZAQ*Y3VDSKD-T4ZI\?KR9]X]V
+MH0\W4D5/^O)HK-IV%UVJX!18JT!R:N^Y"P/E=8E;297_6CT=VDG7H440:AS`
+MP?UP]684^/IT+G;6?#L8F_K,KE_?<+BNKP?N[(ZZ<;M#@%'<\B[-W5YU]@T]
+MMROZ3G;;'GW<4VIWN^N`2H$Q$?#7J*])'(ZJXF%)==2LM-L#_5T67A-P2!BJ
+MQU3.E88*OZKP\?YA);Z5V2@'USML<7@)-PKVJWV(.WFXPFXW/U5G*S_O_+Z'
+M.]K_B)-[ZK@FM&L#F\ZJQ,EBJH6='V?(6\@++L9V#$/@%%^8]=W&,C!P=T<?
+MQ.X:QI7A_-S#X05W(<354V59">&%U3O&ZIK$P:B7.^.+.Y<AX<ZU.$Q;",Q0
+M62@#:5;<;@_T/[/PLD!TGZ)DWS9TQ3290NF`R102L$VLT*3]?FAE@Y+HH,"X
+GA`<%QB4\*#`NX4&!<0D/"HQ+>%!@7-*#`@$I]P[_`"()@=A=#@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-ebr.vhdf.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-ebr.vhdf.gz.uu
new file mode 100644
index 0000000000..cb787e36df
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-ebr.vhdf.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-ebr.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-63x255-512-ebr.vhdf.gz
+M'XL("),EAE4``VEM9RTV,W@R-34M-3$R+65B<BYV:&1F+F]U=`"ME3MOPR`0
+M@/?\BI.Z98C@,-A9'*E2]BYM9MO!452U73IT\(\O9X(+&.=183""''RY%V?&
+M[`-@WF1?%@R;Z!E6Z]5(X^WC0)X$6EQ'ISAM:R2-HJ<EC1.N,VN=T&]GFGEJ
+M'W?,;6[_&%!*:)H9\-7IAYG#46H2%PBL28S+@N%Y$S8'K,:$D244$J2""N_5
+M\+!_2\2W8CR7P1:'MW!.89M!*=S.PPDC[+V=-A,OI_R\\^<>KK:OPQ77M#.>
+M8#HE6#16YDV6RK3PG!]GX!JX`%9=9!@"I_C"GW[;N1H8F'M%/YB;VQ"N#/=S
+M#X<WS(40UTZ5)1'"&]ZKY]IUF8/!XYMQY\TE2'AS+0[S%H+M6%E,!II=\W%9
+M,+QLPF:!Q068RX/<?=N4`-6#TJ`DS<L"U!;*R@=BF$E#]_6IN^_SCQ?A$<=M
+M,4AV.H^";HLJ`1OZ$W6DN:??T_ZT/G^<',Z5*E>1S&4SIP2":B-S>6SNX8SO
+ML78B=A*/O(>DIU_VS"^!]W8^KIB,U3VTQQ'G>K`(!*E2->(DBT[]-[86IS*G
+.BOGNKGX!'5^1W!`)````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-ebr.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-ebr.vmdk.gz.uu
new file mode 100644
index 0000000000..f078e7fac6
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-ebr.vmdk.gz.uu
@@ -0,0 +1,84 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-ebr.vmdk.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-512-ebr.vmdk.gz
+M'XL("%/N+50``VEM9RTV,W@R-34M-3$R+65B<BYV;61K+F]U=`"M7-%NY,81
+M?/=7#.2W/"Q8RR6Y?#@[<<X!@B"`$3OV:\CE,!9BWQUT0I`#]/'AD%.C(D4>
+M::MUJP/[V%W;W4.U=-4%9=GTX=RE=9>+NW2N*%T&-_S3]')9_FP,KTNZ\?2W
+MMW__\<2//YY.3U],8`A1$H),X<28O<_3:?%!N//GHF8WAM=Y%RX/4>V+P`AW
+MWKBQ"3?TPYW70IA=,][NPH7`N03D9G#%2DV;Q7XNNS]\$9L7\LM##L/QEK6K
+M<E>VT71E,=JYJ\[CO<Q5@U,_`'[IWMY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DDO*D<$MY4#@EO*H>$-Y5#PIO*(>%-Y9#PIG)(]%EF*(=$;RJ'1&\J
+MAT1O*H=$;RJ'1&\JAT1O*H=$;RJ'1&\JAT1O*H=$;RJ'1&\JAT1O*H=$;RJ'
+M1&\JAT1O*H<\9UEF*(<\9Z9RR//+7TU\#.YEL9/<\(+VMP-BLWL7C$_>2%8U
+MXW_A\CZ8>2]PM\'V*_E]/?P9/KY2N,ZZW/ZW`1:%:YH7@/]D?N?/IO';\ZO&
+M_UU,OTKVY=_;-YZ^.<W_$/`Z/LY%%7XK;E&ZZ_EHAC]]^^,BPPG.3.XZP>T^
+MSHFT[+?@OA:X\.V[%\_9+^[6YTZO!>ZKZ9-PE\]EI_ND8\4:_Z;M:W9=Q.DY
+MAV\3@;WC?\K.<\!TONXYO_IE&N=9N9_)S[TL-WR+U-\UJ^<QFZH;Y;HY7)LF
+MR\H1[G3OJY?9W8P/`\NOC(-?N0%D_I4[P9UM!T$]3I9)I/'R[^T;3]^=YG\F
+6P$L$-.O@)?P>D>R+_P-J-:`0'F``````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-gpt.qcow.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-gpt.qcow.gz.uu
new file mode 100644
index 0000000000..e7c6971b40
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-gpt.qcow.gz.uu
@@ -0,0 +1,132 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-gpt.qcow.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-63x255-512-gpt.qcow.gz
+M'XL("-EQ+ED``VEM9RTV,W@R-34M-3$R+6=P="YQ8V]W+F]U=`"MG<MN7-F1
+M1>?U%5=OB9*HC(C[U-MNM`'/RH9[UH.ZKQQU&]ES?7PSR?,@(_=6V!!51$$%
+MX6YD'BTNJE2KC@Z'NV]-TTG3]DT[-<>EN?GG]"'-O7]X^-'\^-M?_GI]_]N/
+MW^[&Y/"3I]P_M]I(FGN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V@-^BORYQ^[-?L^]\7690W_>
+M=GDJF+OW[<=O5W>#Z+ZJMF2`T>O[P[\^=%_5K[R^[O;\6FT.,_@[_X$??[Y^
+M^%<9O+T[Z-\8S*_PX5Q^P]W=W4&WT=1^X\YC^CC(_3<\U.OTP!M^<GUO#OW9
+MS+]R?NBZGY\-=ETSSQ>#_Y5?W^UU/VW7M'W33NDBQU::3INN+7.W[[5;[[^^
+M__S+7YO?__3W?YS'_KN^W=OK?G9MAO7V#Q_8W*L3^G9_^+=[-W?[Y?OBM/.<
+MT;DG>.[VRW?WDSGTP>?:GSUU4/KJ+GYN[^:ZP\.GQOM/C5TS:M/?_-O03.?^
+MY\$<^N/C?X6\VYL#EO[\<]O?_`)/FO5X_L[6G__PW6:\^32Y^T\S>OO_,DW-
+M(.?_R^[\<_O/OUW_\V[L_?7_O4VO[^[F`,$?_`?8Z=W=',"(..1LD;_=YN$<
+M^)7>KYW>^=<K2_=HIS<E6-`'_P%Z>O/=Z>%#.K\H^"GSX_XUHO?GP*]7?NGT
+M;O^OQO/7V!G\G?_`C]^O'_YU-]BFP4=[A>VA7Q_QL^,\]XB?'>>Y1_SL.,\]
+MZF?'>?`1/SO.<X_XV7&>>\3/CO/<HWYVW`S>_I[C(WT1/\^=V6NMF==F'9K>
+M?Q%G7XY__,?U]?^"MWOW>X[L2_]/OHCCGXS]$;^(G^=^_D6\IS^W^9M[LX_X
+71?P\]ZA?Q-O#<"/3W_X?EY=\._6L````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-gpt.qcow2.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-gpt.qcow2.gz.uu
new file mode 100644
index 0000000000..be62b472f4
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-gpt.qcow2.gz.uu
@@ -0,0 +1,26 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-gpt.qcow2.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-63x255-512-gpt.qcow2.gz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\9+HMLGM3#VXSE.Y8U^GW2KM5_U)E^2F-%
+M7R9FVX;AC%6RG.NS6P_L[FZ3.P,[2WZ?VOPDMT9@%SU`K9Z$-2-T4H'ILCD.
+M>XWT7ZNG^_)615N]TLJ"7?0`N7J563U\D712:,ETXZJ-!3?BMI%7+]/#?7WT
+M_7OY2P]T-\G\:X#2`J-E*+-V%[$Z-"YB=6A<Q.K0N*C5H8$1JT/C(E:'QD6L
+M#HV+6AT]L$GC;>(:I]TK"Z9J5DK6UO,TR.VX2WZBTVU@;>M?V<3QF]%$W,0U
+A;G43SQMRLO;SUYMLQ$U<XZ)NXC+7Q^^C?SXHP2(5&@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-gpt.raw.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-gpt.raw.gz.uu
new file mode 100644
index 0000000000..b1a6df5544
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-gpt.raw.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-gpt.raw.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-63x255-512-gpt.raw.gz
+M'XL("-IQ+ED``VEM9RTV,W@R-34M-3$R+6=P="YR87<N;W5T`*V52T_#,`S'
+M[_L4WA5$E*1)EIUX2"!Q&PAN7/I83V@2]_+=B9N&]1$7)CF-JDJN?[4=_VLI
+MXP(P&F29N=.&[D%,KVYSM>EIJKH,&+Z/(<R`(@`CK@Y&J?&=XQ':=MA2]5[1
+M61K0*CT/.'%>6S'"-6>OQ:8-8YR(N)1N>QG06BC+!?`]Q:?[X[!@')@]Z/"^
+M!*/`:K#F%]?G:NMQ?(]/SW"X?WU#V,<Y7:V"4=5@)-0[:-I9=(I,]VZ>;L1I
+M]%I4.^$*$K?-XXIXMC0NMVF<6?.*/?2_LXTX*Z=>?NSE+7@-KH:F)'&?$YQC
+M[CR#YLK!K@9W!*N@;O&A<:!4B"_(Q/>04-\&Y!YV"G2%P.[T(DX1=B.^KH?X
+MC!HZ(K=I`U4]H]<Z`H/Z(UV8X@KNZGFLGF6KWGYHEMRF#63UREB]?)%(R72I
+M:DDA"5<Q5\^A.>@C_+^7=]K0'<3TBD`S`-DB#,WG&-6!.$9U((Y1'8AC50<"
+M&=6!.$9U((Y1'8AC54<`>LDWQ!'7#W$#NP::`HKY$*?&<2>^Q6TF7:_71O_*
+F$,\?AF<<XHA;'^(%F6Q:LV09ASCB6(=X`)92;GX`")Q24X@+````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-gpt.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-gpt.vhd.gz.uu
new file mode 100644
index 0000000000..16b71c4d6f
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-gpt.vhd.gz.uu
@@ -0,0 +1,23 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-gpt.vhd.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-63x255-512-gpt.vhd.gz
+M'XL("-IQ+ED``VEM9RTV,W@R-34M-3$R+6=P="YV:&0N;W5T`*V8S8^4,!3`
+M[_M7/&/B88VDE+;`98PF:^)M-9J]>*%\;";J^#$>-I']W^TK+5"@Z,0WTQ`F
+MY?UXW^V4L>$#H#)0':@6E,3[7(`J(2\`S*0;W%Y3]Q/Z^MNIK7\='Q+WZ:\&
+M6,KF4J$XRO,,A'E)#KS"EZ@&[Z'WF.3IS?WU\>N]QW&'XPXD<Y3*."B]>D_>
+M0#&\Q^+NCORS13Y.VF5K[2:IP<"N@ZR;/9%Y[1[M]>7<6&&DS/,X)!0Y,#&-
+MX$<P,1F[\)UD"ZF9FEM.99.Q6SBU)W4)[OK*Q6)(%9,8N;DR4"GD'.]-VG@_
+MK(9)E8?S]^KGN5WHQR.IHF;!6,[M>(^[5.'^8:>!0`7WS`5+.2]Q&ZGR7]Y3
+MH9R/KG$"DWZ">_/-,.]G065819G73Z5LQ^?Q8$3UJU`_82JAVKC&)_K72?@=
+M@5I?!O0>#'%C0'2-_K.5VK:314.2.&'S2-;&`W*8Q5<WQ/'5W65`*:&J5L"/
+M7K_:AD."4"!*3`S3'$0*DH,4(\[:+NNY?C=OWL+MJ_<?$/9I,K?&=#%MT^2:
+M4I#KA7;K2G,XGG2_-XJMQF);>]OCLJCW#INU6V.QZ78'MS7B.+$G-:XE_Q#;
+M`2=9*%7,I0J)ZX>JH:FBN"\!CKHOMSBM351K7,)E"K5=RQL%:6KT,V526`@'
+MW@`S"[M9A34"^].[Y#3`7B0_GCO]VM1EQ-:(3\2\U_*]C$"E_F(NA#CJOMP6
+MZ#U)YKW2)<O6B$]$O5<-WMMV$BJU5;KCJI8D3T*<IO5>:K>/ICY,_UY?XQ/]
+M;1)^!R!WRQ#9NL9=(R734#@@F8;"U2^AAJG8#>:E459.0S*3E4L;,@WSIJ#L
+M@8@C[(&((^R!B"/M@0@D[(&((^R!B"/L@8@C[8%Y4]ID)MJJ(0YSCRLH-?[;
+M+>I0C>BFJW^6W`V*'>;FEL-?Z-@&;V>KMAF,DA%NU1"WNU737<S8D;,PEG"K
+MACC2K5KA^A[1:0OB"$];$$=XVH(XPM,6Q!&>MB".\+0%<=2I8K8N5W\`!A+Z
+%KZ(3````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-gpt.vhdf.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-gpt.vhdf.gz.uu
new file mode 100644
index 0000000000..df5b86c876
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-gpt.vhdf.gz.uu
@@ -0,0 +1,19 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-gpt.vhdf.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+begin 644 img-63x255-512-gpt.vhdf.gz
+M'XL("-IQ+ED``VEM9RTV,W@R-34M-3$R+6=P="YV:&1F+F]U=`"MET^/U2`0
+MP._O4XSQMD8"%"@]O:S):KRM1N-E+_T#FY?59TPT\=`/+U/H>Z6%ZAI:TM!,
+MY]>9889I*?4'@.!`V\0U+QC?D/@<#S>'B<:ZYP'=^]&$%9`XH,?U3D@Y/F,,
+M6!L&99.65W;WE0WS&4>NQY$L<,-%:SOR@B6.>-SLKGT>4$IHVPWP\VP?GY9#
+M@E`@&N#N>0J"@>0@Q04W^2[[I7UW;]_#_>W'3PA[N+K+F1-J`U4#5$(M5]:Q
+MK+L-^16[ZW'.H$2T9UR5Q1W7T?.X"G'##BXU\CBQI^5SZ-_6UN,DC;7T4DM+
+MT!Q4#T.;Q7V-<*IPY@D4=PKJ'I0!R:"W.!D4,.;L<V6B)P@'/@!MH&;`.P2.
+MYP_D[&&OR8]7P3[!0D:D1EZ0BY[@>QF!1OW%78AQ5>GH:8R>+!:])B1+:N0%
+MV>BU/GKI(*%1J=)UN!`U\B+&=86CIU#LZL/MW]MK7C#>D_CT0!&`Q2RLK>T+
+M5@?B"E8'X@I6!^**5@<""U8'X@I6!^(*5@?BBE:'`QI:KHDC#G//.E8-;0>=
+MB<W(MN.1O`N&'2-W#=]K_3M-/+T8IF`31]QN$[<FZ^Q\K)PMV,015[2)Z_#Y
+MK2I04WTIB?-:@'(EI9=`?LV9"=A_/YO^Y^GW,GJ(8SXCD@/U>86)J6K@+;Y$
+M#3A?V/?R[O'F].UQQO'@U1Q`6:-6Y6+6;=S5L;M?3OQI;5UBF])1]-@FG5?;
+MP'&)$Q=GW:^!VV*HN([H)A(D$QEQ4ZHL'_[?M?6XTJGB?@T.?P"E;4<,LPT`
+!````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-gpt.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-gpt.vmdk.gz.uu
new file mode 100644
index 0000000000..b300cd01f4
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-gpt.vmdk.gz.uu
@@ -0,0 +1,88 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-gpt.vmdk.gz.uu 319295 2017-05-31 08:01:12Z ngie $
+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>_9#?!S2R8:?!\D:?HA[.-,/\<+?O3/[ZO]>I(A+
+$M&4`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-mbr.qcow.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-mbr.qcow.gz.uu
new file mode 100644
index 0000000000..39fb10fbcb
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-mbr.qcow.gz.uu
@@ -0,0 +1,128 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-mbr.qcow.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-512-mbr.qcow.gz
+M'XL("%7N+50``VEM9RTV,W@R-34M-3$R+6UB<BYQ8V]W+F]U=`"MG<F.5=D1
+M1>?U%8\>DNY%Q&UI,E.6;,DS>V![6K<=OP]`_G8#>9K,N'L3E`M`I419=^N]
+MDXM%J5@ZG,]WWTZG5DY-=VK&TSZ?OOX\_9#3O9\\_''Z\L^__?W=_6]??KL;
+MD_,/GG(_[[<R]V#KOW5.OSVUG,[C3\Q]_2%H[MZKLS_PZNZ]V>/<U6]W;Q8_
+MIVS0'@R>TMPYO3XAI]?\W.N[=6]7[D[OU[U=)6^W_;G!?[C7IW\(EI]Z?7_P
+MZ]O!P=_+ZVO@4SV;&Q[,70YOMX5/C6QN^B',>N[@4S.;6X*Y'CZULKDMF!O@
+M4SN>DQ]\;>_F1OB4L#F%<Z<R-\&GC,TU#^;.:>ZVS,WP*?+K0AQW^==%Y6Z!
+M3Q'N).1NA4\1[B3D;H-/$>XDY&Z'3Q'N).).\%.$.XVX$Z0H9=QIQ)T@(ROC
+M3B/N!/E.&7<:<2?(=\JXTX@[0;Y3QIU&W`GRG3+N-.).D.^4<:<A=\AWRKBS
+MD#OD.V/<6<@=\ITQ[BSD#OG.&'<6<H=\9XP["[E#OC/&G87<(=\9X\Y"[I#O
+MC'%G$7>*GR+<-1%WBGS7,.Z:B#M%OFL8=TW$G2+?-8R[)N).D>\:QET3<:?(
+M=PWCK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^OQMLTN`O.\'F*WWG\V__`[M'T1.AJ```
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-mbr.qcow2.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-mbr.qcow2.gz.uu
new file mode 100644
index 0000000000..848eaf3c82
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-mbr.qcow2.gz.uu
@@ -0,0 +1,22 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-mbr.qcow2.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-512-mbr.qcow2.gz
+M'XL("%7N+50``VEM9RTV,W@R-34M-3$R+6UB<BYQ8V]W,BYO=70`K9C;DM,P
+M#$#?]RO,'18HL>3<N+2PL,SP!@_`<WK[B@[?3E(KL:-(\;:3-I-IQ]49V3Y2
+MDV29?QF36^,*XVISW)KV.QU@HB_CPYQ^??^QBE^G&P^SF1(E#)2'`3=B_0LX
+MT'"9G0Y8&1=EAP(.^J@I*(5S:G9S`P+N]N:\=.?-J%@$7@/T.'4SKLH/?'X\
+MPEV9'RR='\KKE_=Q?*"8SP]]?CRJU'!5$@="5*WAFB0.A:BMAMLE<4Z(VFLX
+MI7(C7"Y$'16<3:C2X@HARFHX2.)*(0HUG$OB*B%*\\ZFO:N%*,T[F_:N$:(T
+M[VS:NZT0I7EGT][MA"C-.YOV;B]$:=Z!XIT)N(,0I7D'S+M'A'L<<$<A2O,.
+MF'=/"/=TP%DI2O,.F'?/"/<\X(1^!YIWP+Q[0;B7`2?T.]"\`^;=*\+=!IS0
+M[T#S#IAWKPGW)N"$?@>:=\"\>SOQS@K]#C3OD'GWCEA9P`G]#C7OD'EG"0<!
+M)_0[U+Q#YAT2S@6<T.]0\PZ9=SGABH`3^AUJWB'SKB1<%7!"OT/-.V3>U81[
+M'W!"OT/-.V3>?2#<QX`3^AUJWB'S[A/AU@$G]#O4O'/,NPWA/@><T.^<YIUC
+MWGTAW%W`"?W.:=XYYMU7PGT;<"!%#=YEF7P0[GY2L[#L]:<+U\=6..L#,\#J
+M$N!<AAY7+SKAW$^XTZ`1SOK`Z6XU?@_`<[%=`*QH!<<XFG#NB\VO3I/WI6&I
+M0&AZ.QO*+)[PQI?'>A7A]@NOW[D^+@#FN6F:"?!WGQ_,IG%Y?N5AX?VM_..&
+MLJO:O#`5/#3#O_=_ID*WN,4JV./TQPTTT"<\M-@);A/ANBN68_3+N$Y'WL6?
+M(]QZ%5I]BYM]W-#=0QVD`76R^;*R5$.S&FR-]KF[=._NL/I_;W;I/>RO"?D)
+MS0I&TYW)STRGVUT5#'?O;#\Z'"2F:\:X[=!9A"U,K-YZFMUNX<VPO#(>6+D=
+L9%RY'@?+-H+ZW%E:`]M?3<_ZP.GG:OSV0$?`Q5;0%=U_V\U_7_5L5B,5````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-mbr.raw.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-mbr.raw.gz.uu
new file mode 100644
index 0000000000..38b4cc0ca4
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-mbr.raw.gz.uu
@@ -0,0 +1,12 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-mbr.raw.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-512-mbr.raw.gz
+M'XL("%;N+50``VEM9RTV,W@R-34M-3$R+6UB<BYR87<N;W5T`*V4S8Z$(`S'
+M[SY%SWL@!65E+DZRR=[WLC-GQM6G\.&W6'7*X,>80)%@"K_\2PN(W``J`^A7
+MQFW'\*5B&XJ/8J3IQSF@0T"=`!4!&=<2CA:03&_#6/;A-XS!@:&W]-]-<^XP
+M$$%=R:@U2N#^EEUIWW:,.-F>X?;G@-:"]PGP=]9G=F6<UU=WF?/KQH*Q-506
+M["<X\Z["^_?M12'C=*Z`&6>.<+-@KJ`UW%7@2G+V8B57XK1+UIV<"US#WXRK
+M]M3126"WYM@,UN8M%D<6[Y-Y!MV!+@'=Y#,Q<,DO//5=4ADF"G=''Z3A^H"K
+MX_5:X,Q!N!#C'LO+LI+"@]-K4G5MYF3HUYOQYLT-D/CF,L[D?0@NX\M"%4BK
+;TG';,?RHV!A83<!L)QA>/L3B'ZC")G7E!@``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-mbr.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-mbr.vhd.gz.uu
new file mode 100644
index 0000000000..b11e047592
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-mbr.vhd.gz.uu
@@ -0,0 +1,19 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-mbr.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-63x255-512-mbr.vhd.gz
+M'XL(""DUQ%4``VEM9RTV,W@R-34M-3$R+6UB<BYV:&0N;W5T`*V7/6^D,!"&
+M^_T5(UV7`IG!-DZS*T5*?\TEM4T@6ITNB9(K4O#CSX,-V!C8;,X+:X',/+R>
+M+V3&W`]`5B`[D"U(0=<U!WD+M0*PD_[$82S]+?3-ZTO;_#U_%O[7'QRL9*%5
+M;$[V6`&W+ZD!-;U$/M$U]".F^''_?'/^\SSBT./0@T1-5A6"-,E[.@.,.W5$
+M>CSC[Z6Z*E4W6[GW=!U47?!$%:HKBE.(X];*/D^G`",'_XQG=!--A+A(G6`+
+MJT#FFE/9O-@UG-RSN@9W<_"Q<*EB$Z.V(P-90HUT;=-F]$-RVE3Y_'C3[Q_M
+M0A]NI(J<])7)G-I>+OI4P2FP3@&GU-Y;+@R4UR5N)57^RWLRMN/^PCJ!B7$"
+MA^7'WIM1$.J3)=OQ^78P-O5ITL=MG>F5<7NBOROB8P(:<QU0,5<=,6Y:L&E\
+M=3#0@D:JTM+7JO=?8^_;E8"<7-D>`_^9I\SQ-=UU0"%`ZP3X:]37[,JX7I]2
+MF>.KAH2Q_=BV<R%!X5<5/MX_K-2OTAOMX'O=3VF\A!L%A]T^QIT"7.7*;:8$
+MS2G*N_`ZP!W=?\3Q/774$]JUB<W%BLS)HM7"+HPSE"V4%35C-G6M`#C%%V9]
+MMZD,C):[HP_2Y6K"U?'S98##"\N%&&>FSK(2P@O>.Z;JFLS!,,O*^&+E$B2N
+M7(?#O(U`#YW%9J!]*AVW)_J?17PX(/I/4;9O&_IFFDTA]\!L"BVPS:Q0Y_U^
+M2.&"DFFC0+B,&P7"9=PH$"[C1H%P&3<*A,NX42!<UHV"!=K<._P#==^RJ5T.
+"````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-mbr.vhdf.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-mbr.vhdf.gz.uu
new file mode 100644
index 0000000000..c1737901ed
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-mbr.vhdf.gz.uu
@@ -0,0 +1,15 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-mbr.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-63x255-512-mbr.vhdf.gz
+M'XL(")PEAE4``VEM9RTV,W@R-34M-3$R+6UB<BYV:&1F+F]U=`"ME3MOPR`0
+MQ_=\BI.Z9;!X&.PLB50I>Y<VL^W@*(K:+ATZ^,/W`./PL/.H,`3A'/SR/^ZX
+M$&(?@)(!:6;&9</P6H1M6*U7AD;;YX`U`4(38(%`B^L0APM09B/TR'O]JD=M
+M(+IW^*[&N>TP(*'88<-G6WBXX[0K[<L&@_.?J[O]<T`AH&D2X+O3QV[*>%Y?
+MI3+'MS8)(RHH!0@)-7M4X6'_$2FT.)K+88MC]W!.L,V@.=S.PW$T]MY*FXGC
+M+C_O_+F'V]J/PY6WU.%)$#5G6'16Y$V6&ENXSX\S4`64`ZE'&PN!4WSAJF^3
+MRF"!NS?T0>INHW%5N)YZ.';'70AQ[5199D)XY_2VJ;HN<S!H?#,>O+D:$MY<
+MBV-Y"\'&5!;,0%R5CLN&X:T(FP66(S#7"5+WWR8YR!ZD`BGTO"I!;J"J?2`+
+M,VGHOK]4]W/^]2)L<-06@]FN]S.N;XNL@#7Z1^11SSU]+_O3^OQY<CA7JEQ%
+MPLN&NS@#V4;NTMC=PYE=8G4\/B0:G1[3.OVRA]\$I[?S<>7DK.JA/1J<Z\%+
+=8)@K508G2+3KO[&U.)DY5?!_=_4'[+Y)>1`)````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-mbr.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-mbr.vmdk.gz.uu
new file mode 100644
index 0000000000..38593ed97a
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-mbr.vmdk.gz.uu
@@ -0,0 +1,84 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-mbr.vmdk.gz.uu 272486 2014-10-03 20:54:35Z marcel $
+begin 644 img-63x255-512-mbr.vmdk.gz
+M'XL("%?N+50``VEM9RTV,W@R-34M-3$R+6UB<BYV;61K+F]U=`"M7-%NY,81
+M?/=7#.2W/"Q8RR6Y?#@[<<X!@B"`$3OV:\CE,!9BWQUT0I`#]/'AD%.C(D4>
+M::MUJP/[V%W;W4.U=-4%9=GTX=RE=9>+NW2N*%T&-_S3]')9_FP,KTNZ\?2W
+MMW__\<2//YY.3U],8`A1$H),X<28O<_3:?%!N//GHF8WAM=Y%RX/4>V+P`AW
+MWKBQ"3?TPYW70IA=,][NPH7`N03D9G#%2DV;Q7XNNS]\$9L7\LM##L/QEK6K
+M<E>VT71E,=JYJ\[CO<Q5@U,_`'[IWMY__(][ZS_>'NX_/+Z/^9W#V0[.ES+X
+ME[>`,!16E>$BW`AP=8`HO<L[ER/<=D\/?[G_Q9_^ZQ\^WK]_]P8L]QS.]I*[
+M2QW2"?[9\VMFA#?)7(GP'N[ISW]]^R8^N=GI0_-`N!`U)#*\]U"'XI:E"Y\O
+M7V-V_MUC0.SC1\HNG&UL3C&^]R5<%!=7U6Y,IPC8Y^%V%TL>>W=[\,VC_^'3
+M!__F[M?W[U+OPMF&EM4CT'5L5.Z*/$#%TD+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B<$WS`O"?S._\V31^>WZ5-S[?Z_C`%%7X-;M%Z:[GHQG^].V/BPPG
+M.#/][`2W^_616-!^"^YK@0L_#_3B.?M-X/K<Z;7`?35]$N[RN>QT076L6.-?
+MW7W-KHLX/>?P?2?0@?Q?WGD.F,[7/>=7OTSC/"OW,_FYE^6&[[GZRVOU/&9C
+M>J-<-X=KTV19.<*=[GWU,KN;\6%@^95Q\"LW@,R_<B>XL^T@J,?),JD^7OZ]
+=?>/IN]/\SP1XB8!F';R$7TR2??%_%;F-<V]@````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-vtoc8.qcow.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.qcow.gz.uu
new file mode 100644
index 0000000000..c5970c72e5
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.qcow.gz.uu
@@ -0,0 +1,127 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-vtoc8.qcow.gz.uu 272073 2014-09-24 15:15:14Z marcel $
+begin 644 img-63x255-512-vtoc8.qcow.gz
+M'XL("+\S(E0``VEM9RTV,W@R-34M-3$R+79T;V,X+G%C;W<N;W5T`*V=R6X<
+M5Q)%]_Z*TBQ1DE41\7+22'0W#/2B`3?Z!YQ#U3K1JU[XXYN2WB!&WJOP)!,&
+M!3HOBD^'1[)]\'@^?_UQ.G5R2OTI3:?K<KK[>7Z3TS<_N?]V^O7?/_WSQV]_
+M_/K#US$Y?^>I>S^7TS">ICQW;^M_;4X_/[6>SE,X]^5-T-PWK\Y^\ZN[]\D>
+MYVY^^/K)XN?TMPV>W.N3WW%Z7]X,OKYSG5/X5&)SW;VYVSSW<YW[BT]/R>GU
+MOVWP%W=Z^GM/+WI]=EGA<P,;'.\-[N[UV66#3TUL;OXNS':YP*<6-K<&<U?X
+MU,;F+M^?N^*GKGA.OO.+\74._=I*^7H_?D#AW*G.H:\,*5]/QP^D>W/G/'=;
+MY]!7AI2OI^,'^GMS/_]8@"YS"3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O\S
+MOQC'JSG*'U/.]@<^W7HUA[5_^/KEMZT[NY`Y:7.?_%S[=-4]I:?V/'AU)_CJ
+MVI?:<O=OA7;_J>]^LG]'<^A;V_]Q5-#5''ANFT_+'2=RNJY\#EW-\6=0&;X,
+E?I;F#/[./_#KSS_>_^OK8,J#?]DK3'=>.9]_^#\)B7^=OZ8`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-vtoc8.qcow2.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.qcow2.gz.uu
new file mode 100644
index 0000000000..069deb3b93
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.qcow2.gz.uu
@@ -0,0 +1,21 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-vtoc8.qcow2.gz.uu 272088 2014-09-24 22:58:10Z marcel $
+begin 644 img-63x255-512-vtoc8.qcow2.gz
+M'XL("+8[(U0``VEM9RTV,W@R-34M-3$R+79T;V,X+G%C;W<R+F]U=`"MF-MN
+MTT`0AN_S%,NI0(&2G=EU;$Z%'B)Q@03B!8AC^P&X0\K#L[$W&7L\XTTBIU:D
+MU/T_S:Z__K6[7'8O8[PU+C.N,$UIPN=X@.E]&!YF]VO]_:;_VBTZF%TJJ=$)
+M:U;%$3=@_2,<:+@0%[XEXGK3H8"#0VH,2N&<.MW4"0%WO6BWKKT8.4O@)<`.
+MIUZ,B^:#;CZ><!?.!W//A_+^^0OGP_GGPWHJQP?/4O-A(Z16&BY/X9R4*C3<
+M)HFS0JK4<-LD#H14I>'J)`Z%5*/@;%(5YX24U7"0Q'DAA1K.)7&9D/(:+NF=
+M6PDIS3N;]BX74IIW-NU=(:0T[VS:NXV0TKRS:>]*(:5Y!XIWAG!;(:5Y!\R[
+M)Q'WE'"5D-*\`^;=LXA[3KA:2&G>`?/N1<1=$4[H.]"\`^;=RXA[=<1Y*:5Y
+M!\R[UQ%W33BA[T#S#IAW;R+N+>&$O@/-.V#>O1MYYX6^`\T[9-Z]CZPEX82^
+M0\T[9-[9B`/""7V'FG?(O,.(<X03^@XU[Y!YYR,N(YS0=ZAYA\R[5<3EA!/Z
+M#C7OD'E71-P'P@E]AYIWR+S[&'&?""?T'6K>(?/N<\1](9S0=ZAYYYAWMQ'W
+ME7!"WSG-.\>\^Q9Q=X03^LYIWCGFW7W$/1!.Z#NG>>>8=X\1MR9<,^O]IZ/[
+M=RN\ZR<F@/GY0/6/8\`5LR[8=PL.&[T"D_G]$93PN+^2H9/V#>,J$;C^6]=W
+MOQ\`?_3F\W,_$'C:O^5@@Q1@WMZ.@[9_?K!_11(W-5^'V\RUW`Y7GHH+]1UN
+M[:O:U#7#_>GAMC-?##M:;GVX\\<+EFL/RT7ZX:9MOM!_"J[WRW;+<;1<8"GZ
+M1XV5IC/B=-415VZI\T[9O7L)-_ED>_[>G=Q\U<:4P1-KFJV.@\DASE8ERUM@
+BN&<)3\'C=_W$[N?-\*L#N@B<;<+P@!9>B_]NV1VQX1,`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-vtoc8.raw.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.raw.gz.uu
new file mode 100644
index 0000000000..d3629b2603
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.raw.gz.uu
@@ -0,0 +1,11 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-vtoc8.raw.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-63x255-512-vtoc8.raw.gz
+M'XL("/W%'50``VEM9RTV,W@R-34M-3$R+79T;V,X+G)A=RYO=70`K9)!;L,@
+M$$7W/L5?=V$Q@&V\JI16V56JU`O4-G"`K#E\2'!"C+'C1![0"&GF/\T7PU@(
+M0-9H..KJ<B5')2`E!`>$?VGXEN3"'4_&'/Z^N?@IK^&*`"-?G/>/JL6"*Y-P
+MQ<<(5!,=K0,56`O&L\"`:Z.J?8I;FR_@NKWL!ER_%5?[K*$-C$EP_P^X8>?/
+MH)E=`PH/\89=NMD5L=G:2Q9V"4<1]YGBHEV>J#BB/C,=LM/I.ZX?(,54M6KV
+M*X<SNZX*V:TXW:'W>T*PPS*.KP[QZJHT6EV!E>_J,GFYX'[+Z0G`?@3N-2$U
+-2M6,%6>->Z%+`P4`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vhd.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vhd.gz.uu
new file mode 100644
index 0000000000..03f31d1213
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vhd.gz.uu
@@ -0,0 +1,18 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vhd.gz.uu 286398 2015-08-07 04:35:43Z marcel $
+begin 644 img-63x255-512-vtoc8.vhd.gz
+M'XL("#$UQ%4``VEM9RTV,W@R-34M-3$R+79T;V,X+G9H9"YO=70`K99+;^0@
+M#,?O\RDL[:V'$3&$)*=*?>QMI97VL->2A%2CJ@^U/<QA/OS:@320UW9:,B@"
+M@7_YVQ@/0K@'0$O0'6@+.N=^H4!74)0`-.D;]N_,#^'4/#_9YOUPW/OGM'.P
+M3(16L3G;HP1%'RD`#7]$M]R'TX#9_[B]OS@\W@\X]#CTH+Q@*XF@Z\EW,A9<
+M:J>.27\/^-`CCZ,Z.5476O%80M>![((5<E#G7+T,G55D1>NYY5#G?7R&%@VB
+MB='92>QR,;$*E"X%58S.+N'TEM4YN(N=WPN7*A2Q@MX"-$4/N4]I,\1AUBA5
+MCF\OYO7-3O3A2JJ,FY'-YIIU=]&G"@Z+O0(U3Y787>@I#U/<+%6^&3T=VZDX
+M2.'`K:#HB'S=73U&#X>@42/5HMC:C'WOKYCA4&Q8;>%6W#7LKM*<(%Q4<E`(
+M.9U]Q8<7)/7:Q?C]?+7VZL\-RE^1/K.2+%_>#E-&=O\Y;"6(BHO0ZG:8:K2J
+MOG]VC4GEKL/5G\51S1`MM!:LG>#N`ER3>#/JF;NVSW_1E]^SW:T'=^6XV)TK
+MJNPKN*`N7TYQ3734PH8PVB^H@T5U[0>N;D#)V&K3V>LEG$V:*G7W65QKH*8\
+MR:#;J,K-IHAS4P5]74E6J#"U0MF6EJ?IKUR8A??ZQ.GW/OXYH/(*D[E,P+0*
+MM0<F4ZCI$IE48=%6F'27RZ+L\S#1O9EQ">_-C$MX;V9<PGLSXQ+>FQF7\-[,
+2N*3W9@+2^=W]`WD,N"QL#0``
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vhdf.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vhdf.gz.uu
new file mode 100644
index 0000000000..1f7fd82b74
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vhdf.gz.uu
@@ -0,0 +1,14 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vhdf.gz.uu 284659 2015-06-21 02:55:25Z marcel $
+begin 644 img-63x255-512-vtoc8.vhdf.gz
+M'XL("*8EAE4``VEM9RTV,W@R-34M-3$R+79T;V,X+G9H9&8N;W5T`*V4.V_#
+M(!2%]_R*(W7+$)F'L3U%ZFNK5*E#U]H&HBAJ*U4=.OC'%XP3`\%N&ADC1`3G
+MXQYRN5GF&L`%"@J1V\XI<@;.P2C`S$S";(DZNL<OI6Y?[BE[VO2M6SD8,8OG
+M^P?5Y$*WB5JW6@_`,M"1>6")K$)&DT"'JT95]2=N+CZ'JY>RZW#-I3AA1@FI
+MH%2$>_-P[<)_!CFSJT#<A%UAEQSMLG&SUG9D>@I'1MPVQHUV::2B&/6)Z)",
+M3IYP30O.0M6LV;L43BV:*D1?BI,U&I,G!+J=QM'9(/Z;*H4L>V!N=M6)<7JA
+M>]Z$GP,V`W"I"$DY5#[!(#2$ZHL?0\$A*A2E#Z1!WJ!K/S]4^[W_\6ZPQ]G*
+M9[(WV:V>FEIJ#BE`:WN(D';NQ7?SL%OOWW=''!U<T>'@O+`J4Y1%$]DE*$.[
+MKWMZB*-C\27Y*O<&39Q,AX_&O[VMC^,GLZ8`F>=A[^?8@Q_!0BK[>ER>1:JK
+3WT:/$PNGBLF]U2]`,(]1+@<`````
+`
+end
diff --git a/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vmdk.gz.uu b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vmdk.gz.uu
new file mode 100644
index 0000000000..c558e122fa
--- /dev/null
+++ b/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vmdk.gz.uu
@@ -0,0 +1,83 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/img-63x255-512-vtoc8.vmdk.gz.uu 271911 2014-09-20 21:02:54Z marcel $
+begin 644 img-63x255-512-vtoc8.vmdk.gz
+M'XL("/[%'50``VEM9RTV,W@R-34M-3$R+79T;V,X+G9M9&LN;W5T`*U<76_=
+MQA%]SZ\@[#X412%PR+DD[X-1-U$"%$6`(`[:U_!CV0A-;$,6BAK0C^\NN6=U
+MJ'OI9:-QJ$#C.W.T,^0]DL\<J"S7/T6A0Z%:Z%2<FJ*4PO_5>A5E_13X:TPO
+M//[]]OM_W-"?QZ]6,`E55"(EPU&P^3J/-\_^`*[Z4M7F!7]56;C:ORC#16&$
+MJW9>V(73,+MK)3A=7_@&RBE\0G!O$U"Q@3M=Z6FWV2^=[D]?Q>'YEZLZG,'?
+MWN9<M'71##$LFM,2UT5;+:^51>N39@_XNKB]^_3OXM9]&N_O/CY\B.>KPKWU
+MR=J$_&8,"+ZQM@F?A!<"W#E`-*ZHIZ*6\'+Q>/_=W:_NYC_N_M/=A_=O!.U6
+MX=YJ7>@Y'"?DET_7)@A?I"P:"5^C>/SF;[=OXI-;WGSL[P$7JOQ!_-?V?3!N
+MTQ3AX_):3N?>/P3$.?Y)IPOW-@[GM'QM#9^<M&C/Q7*<4\"N_,M3;'F9W7CO
+M^@?WT^>/[LVKWSZ\3[,+]S:,[+P`=<N@ZN)4!ZC86AC?*2"&QV:Y:\7CKW</
+MO]R-[WR;G]RKF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[9]U^/W6UP"_NW?N
+MZW>W5?T]GZ^[^$W6+SY?MZF3+P-VRU*TVGU8NO+\5'7.PGWI?"M<;]7N"C<<
+MA5LW-Y,KG'L&]S/!63\L<M&N@\);_XYV!>V2X#0O;]9ZWH.3)[B_/(=[:O?Y
+MNZTJGNJOG*ZX>KHIP0UC^-78QZ?WS34X9_JHR'P4;NJ+P3\G4LSC/ESUQ4/\
+G_X]*OP"N_H#+_^^_X+]G;/];`34"FIU0_7NC++_Z'WN7IO#-7P``
+`
+end
diff --git a/usr.bin/mkimg/tests/mkimg_test.sh b/usr.bin/mkimg/tests/mkimg_test.sh
new file mode 100755
index 0000000000..f818fce381
--- /dev/null
+++ b/usr.bin/mkimg/tests/mkimg_test.sh
@@ -0,0 +1,164 @@
+# $FreeBSD: head/usr.bin/mkimg/tests/mkimg_test.sh 315776 2017-03-23 03:28:24Z ngie $
+
+mkimg_blksz_list="512 4096"
+mkimg_format_list="qcow qcow2 raw vhd vhdf vmdk"
+mkimg_geom_list="1x1 63x255"
+mkimg_scheme_list="apm bsd ebr gpt mbr vtoc8"
+
+bootcode()
+{
+    case $1 in
+      bsd)	echo 8192 ;;
+      gpt|mbr)	echo 512 ;;
+      *)	echo 0 ;;
+    esac
+    return 0
+}
+
+mkcontents()
+{
+    local byte count name
+
+    byte=$1
+    count=$2
+
+    name=_tmp-$byte-$count.bin
+    jot -b $byte $(($count/2)) > $name
+    echo $name
+    return 0
+}
+
+makeimage()
+{
+    local blksz bootarg bootsz format geom nhds nsecs partarg pfx scheme
+
+    format=$1
+    scheme=$2
+    blksz=$3
+    geom=$4
+    pfx=$5
+    shift 5
+
+    nsecs=${geom%x*}
+    nhds=${geom#*x}
+
+    bootsz=`bootcode $scheme`
+    if test $bootsz -gt 0; then
+	bootarg="-b `mkcontents B $bootsz`"
+    else
+	bootarg=""
+    fi
+
+    partarg=""
+    for P in $*; do
+	partarg="$partarg -p $P"
+    done
+    if test -z "$partarg"; then
+	local swap ufs
+	swap="-p freebsd-swap::128K"
+	ufs="-p freebsd-ufs:=`mkcontents P 4194304`"
+	partarg="$ufs $swap"
+    fi
+
+    imagename=$pfx-$geom-$blksz-$scheme.$format
+
+    mkimg -y -f $format -o $imagename -s $scheme -P $blksz -H $nhds -T $nsecs \
+	    $bootarg $partarg
+    echo $imagename
+    return 0
+}
+
+mkimg_rebase()
+{
+    local baseline image result tmpfile update
+
+    image=$1
+    result=$2
+
+    baseline=$image.gz.uu
+    update=yes
+
+    if test -f $baseline; then
+	tmpfile=_tmp-baseline
+	uudecode -p $baseline | gunzip -c > $tmpfile
+	if cmp -s $tmpfile $result; then
+	    update=no
+	fi
+    fi
+
+    if test $update = yes; then
+	# Prevent keyword expansion when writing the keyword.
+	(echo -n '# $'; echo -n FreeBSD; echo '$') > $baseline
+	gzip -c $result | uuencode $image.gz >> $baseline
+    fi
+
+    rm $image $result _tmp-*
+    return 0
+}
+
+mkimg_test()
+{
+    local blksz format geom scheme
+
+    geom=$1
+    blksz=$2
+    scheme=$3
+    format=$4
+
+    case $scheme in
+      ebr|mbr)
+	bsd=`makeimage raw bsd $blksz $geom _tmp`
+	partinfo="freebsd:=$bsd"
+	;;
+      *)
+	partinfo=""
+	;;
+    esac
+    image=`makeimage $format $scheme $blksz $geom img $partinfo`
+    result=$image.out
+    hexdump -C $image > $result
+    if test "x$mkimg_update_baseline" = "xyes"; then
+	mkimg_rebase $image $result
+    else
+	baseline=`atf_get_srcdir`/$image
+	atf_check -s exit:0 cmp -s $baseline $result
+    fi
+    return 0
+}
+
+atf_test_case rebase
+rebase_body()
+{
+    local nm
+
+    mkimg_update_baseline=yes
+    for nm in $mkimg_tests; do
+	${nm}_body
+    done
+    return 0
+}
+
+atf_init_test_cases()
+{
+    local B F G S nm
+
+    for G in $mkimg_geom_list; do
+	for B in $mkimg_blksz_list; do
+	    for S in $mkimg_scheme_list; do
+		for F in $mkimg_format_list; do
+		    nm="${S}_${G}_${B}_${F}"
+		    atf_test_case $nm
+		    eval "${nm}_body() { mkimg_test $G $B $S $F; }"
+		    mkimg_tests="${mkimg_tests} ${nm}"
+		    atf_add_test_case $nm
+		done
+	    done
+	done
+    done
+
+    # XXX hack to make updating the baseline easier
+    if test "${__RUNNING_INSIDE_ATF_RUN}" != "internal-yes-value"; then
+	atf_add_test_case rebase
+    fi
+}
+
diff --git a/usr.bin/mkimg/uuid.c b/usr.bin/mkimg/uuid.c
new file mode 100644
index 0000000000..eaff880ccf
--- /dev/null
+++ b/usr.bin/mkimg/uuid.c
@@ -0,0 +1,125 @@
+/*-
+ * Copyright (c) 2016 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/uuid.c 314577 2017-03-03 01:56:55Z sjg $");
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "endian.h"
+#include "image.h"
+#include "mkimg.h"
+
+static void osdep_uuidgen(mkimg_uuid_t *);
+
+#ifdef __APPLE__
+#include <uuid/uuid.h>
+
+static void
+osdep_uuidgen(mkimg_uuid_t *uuid)
+{
+
+	uuid_generate_time((void *)uuid);
+}
+#endif	/* __APPLE__ */
+
+#if defined(__FreeBSD__) || defined(__DragonFly__)
+#include <sys/uuid.h>
+
+static void
+osdep_uuidgen(mkimg_uuid_t *uuid)
+{
+
+	uuidgen((void *)uuid, 1);
+}
+#endif	/* __FreeBSD__ */
+
+#ifdef __linux__
+#include <stdlib.h>
+#include <time.h>
+
+static void
+osdep_uuidgen(mkimg_uuid_t *uuid)
+{
+	struct timeval tv;
+	uint64_t time = 0x01B21DD213814000LL;
+	u_int i;
+	uint16_t seq;
+
+	if (gettimeofday(&tv, NULL) == -1)
+		abort();
+
+	time += (uint64_t)tv.tv_sec * 10000000LL;
+	time += tv.tv_usec * 10;
+
+	uuid->time_low = (uint32_t)time;
+	uuid->time_mid = (uint16_t)(time >> 32);
+	uuid->time_hi_and_version = (uint16_t)(time >> 48) & 0xfff;
+	uuid->time_hi_and_version |= 1 << 12;
+
+	seq = random();
+
+	uuid->clock_seq_hi_and_reserved = (uint8_t)(seq >> 8) & 0x3f;
+	uuid->clock_seq_low = (uint8_t)seq;
+
+	for (i = 0; i < 6; i++)
+		uuid->node[i] = (uint8_t)random();
+	uuid->node[0] |= 0x01;
+}
+#endif	/* __linux__ */
+
+void
+mkimg_uuid(mkimg_uuid_t *uuid)
+{
+	static uint8_t gen[sizeof(mkimg_uuid_t)];
+	u_int i;
+
+	if (!unit_testing) {
+		osdep_uuidgen(uuid);
+		return;
+	}
+
+	for (i = 0; i < sizeof(gen); i++)
+		gen[i]++;
+	memcpy(uuid, gen, sizeof(*uuid));
+}
+
+void
+mkimg_uuid_enc(void *buf, const mkimg_uuid_t *uuid)
+{
+	uint8_t *p = buf;
+	u_int i;
+
+	le32enc(p, uuid->time_low);
+	le16enc(p + 4, uuid->time_mid);
+	le16enc(p + 6, uuid->time_hi_and_version);
+	p[8] = uuid->clock_seq_hi_and_reserved;
+	p[9] = uuid->clock_seq_low;
+	for (i = 0; i < 6; i++)
+		p[10 + i] = uuid->node[i];
+}
diff --git a/usr.bin/mkimg/vhd.c b/usr.bin/mkimg/vhd.c
new file mode 100644
index 0000000000..b36c5acbb5
--- /dev/null
+++ b/usr.bin/mkimg/vhd.c
@@ -0,0 +1,416 @@
+/*-
+ * Copyright (c) 2014, 2015 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/vhd.c 307544 2016-10-18 01:55:07Z marcel $");
+
+#include <sys/errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "endian.h"
+#include "image.h"
+#include "format.h"
+#include "mkimg.h"
+
+#ifndef __has_extension
+#define	__has_extension(x)	0
+#endif
+
+/*
+ * General notes:
+ * o   File is in network byte order.
+ * o   The timestamp is seconds since 1/1/2000 12:00:00 AM UTC
+ *
+ * This file is divided in 3 parts:
+ * 1.  Common definitions
+ * 2.  Dynamic VHD support
+ * 3.  Fixed VHD support
+ */
+
+/*
+ * PART 1: Common definitions
+ */
+
+#define	VHD_SECTOR_SIZE	512
+#define	VHD_BLOCK_SIZE	(4096 * VHD_SECTOR_SIZE)	/* 2MB blocks */
+
+struct vhd_geom {
+	uint16_t	cylinders;
+	uint8_t		heads;
+	uint8_t		sectors;
+};
+
+struct vhd_footer {
+	uint64_t	cookie;
+#define	VHD_FOOTER_COOKIE	0x636f6e6563746978ULL
+	uint32_t	features;
+#define	VHD_FEATURES_TEMPORARY	0x01
+#define	VHD_FEATURES_RESERVED	0x02
+	uint32_t	version;
+#define	VHD_VERSION		0x00010000
+	uint64_t	data_offset;
+	uint32_t	timestamp;
+	uint32_t	creator_tool;
+#define	VHD_CREATOR_TOOL	0x2a696d67	/* FreeBSD mkimg */
+	uint32_t	creator_version;
+#define	VHD_CREATOR_VERSION	0x00020000
+	uint32_t	creator_os;
+#define	VHD_CREATOR_OS		0x5769326b	/* Wi2k */
+	uint64_t	original_size;
+	uint64_t	current_size;
+	struct vhd_geom	geometry;
+	uint32_t	disk_type;
+#define	VHD_DISK_TYPE_FIXED	2
+#define	VHD_DISK_TYPE_DYNAMIC	3
+#define	VHD_DISK_TYPE_DIFF	4
+	uint32_t	checksum;
+	mkimg_uuid_t	id;
+	uint8_t		saved_state;
+	uint8_t		_reserved[427];
+};
+#if __has_extension(c_static_assert)
+_Static_assert(sizeof(struct vhd_footer) == VHD_SECTOR_SIZE,
+    "Wrong size for footer");
+#endif
+
+static uint32_t
+vhd_checksum(void *buf, size_t sz)
+{
+	uint8_t *p = buf;
+	uint32_t sum;
+	size_t ofs;
+
+	sum = 0;
+	for (ofs = 0; ofs < sz; ofs++)
+		sum += p[ofs];
+	return (~sum);
+}
+
+static void
+vhd_geometry(uint64_t image_size, struct vhd_geom *geom)
+{
+	lba_t imgsz;
+	long cth;
+
+	imgsz = image_size / VHD_SECTOR_SIZE;
+
+	/* Respect command line options if possible. */
+	if (nheads > 1 && nheads < 256 &&
+	    nsecs > 1 && nsecs < 256 &&
+	    ncyls < 65536) {
+		geom->cylinders = (ncyls != 0) ? ncyls :
+		    imgsz / (nheads * nsecs);
+		geom->heads = nheads;
+		geom->sectors = nsecs;
+		return;
+	}
+
+	if (imgsz > 65536 * 16 * 255)
+		imgsz = 65536 * 16 * 255;
+	if (imgsz >= 65535 * 16 * 63) {
+		geom->cylinders = imgsz / (16 * 255);
+		geom->heads = 16;
+		geom->sectors = 255;
+		return;
+	}
+	geom->sectors = 17;
+	cth = imgsz / 17;
+	geom->heads = (cth + 1023) / 1024;
+	if (geom->heads < 4)
+		geom->heads = 4;
+	if (cth >= (geom->heads * 1024) || geom->heads > 16) {
+		geom->heads = 16;
+		geom->sectors = 31;
+		cth = imgsz / 31;
+	}
+	if (cth >= (geom->heads * 1024)) {
+		geom->heads = 16;
+		geom->sectors = 63;
+		cth = imgsz / 63;
+	}
+	geom->cylinders = cth / geom->heads;
+}
+
+static uint64_t
+vhd_resize(uint64_t origsz)
+{
+	struct vhd_geom geom;
+	uint64_t newsz;
+
+	/*
+	 * Round the image size to the pre-determined geometry that
+	 * matches the image size. This circular dependency implies
+	 * that we need to loop to handle boundary conditions.
+	 * The first time, newsz equals origsz and the geometry will
+	 * typically yield a new size that's smaller. We keep adding
+	 * cylinder's worth of sectors to the new size until its
+	 * larger or equal or origsz. But during those iterations,
+	 * the geometry can change, so we need to account for that.
+	 */
+	newsz = origsz;
+	while (1) {
+		vhd_geometry(newsz, &geom);
+		newsz = (int64_t)geom.cylinders * geom.heads *
+		    geom.sectors * VHD_SECTOR_SIZE;
+		if (newsz >= origsz)
+			break;
+		newsz += geom.heads * geom.sectors * VHD_SECTOR_SIZE;
+	}
+	return (newsz);
+}
+
+static uint32_t
+vhd_timestamp(void)
+{
+	time_t t;
+
+	if (!unit_testing) {
+		t = time(NULL);
+		return (t - 0x386d4380);
+	}
+
+	return (0x01234567);
+}
+
+static void
+vhd_make_footer(struct vhd_footer *footer, uint64_t image_size,
+    uint32_t disk_type, uint64_t data_offset)
+{
+	mkimg_uuid_t id;
+
+	memset(footer, 0, sizeof(*footer));
+	be64enc(&footer->cookie, VHD_FOOTER_COOKIE);
+	be32enc(&footer->features, VHD_FEATURES_RESERVED);
+	be32enc(&footer->version, VHD_VERSION);
+	be64enc(&footer->data_offset, data_offset);
+	be32enc(&footer->timestamp, vhd_timestamp());
+	be32enc(&footer->creator_tool, VHD_CREATOR_TOOL);
+	be32enc(&footer->creator_version, VHD_CREATOR_VERSION);
+	be32enc(&footer->creator_os, VHD_CREATOR_OS);
+	be64enc(&footer->original_size, image_size);
+	be64enc(&footer->current_size, image_size);
+	vhd_geometry(image_size, &footer->geometry);
+	be16enc(&footer->geometry.cylinders, footer->geometry.cylinders);
+	be32enc(&footer->disk_type, disk_type);
+	mkimg_uuid(&id);
+	mkimg_uuid_enc(&footer->id, &id);
+	be32enc(&footer->checksum, vhd_checksum(footer, sizeof(*footer)));
+}
+
+/*
+ * PART 2: Dynamic VHD support
+ *
+ * Notes:
+ * o   File layout:
+ *	copy of disk footer
+ *	dynamic disk header
+ *	block allocation table (BAT)
+ *	data blocks
+ *	disk footer
+ */
+
+struct vhd_dyn_header {
+	uint64_t	cookie;
+#define	VHD_HEADER_COOKIE	0x6378737061727365ULL
+	uint64_t	data_offset;
+	uint64_t	table_offset;
+	uint32_t	version;
+	uint32_t	max_entries;
+	uint32_t	block_size;
+	uint32_t	checksum;
+	mkimg_uuid_t	parent_id;
+	uint32_t	parent_timestamp;
+	char		_reserved1[4];
+	uint16_t	parent_name[256];	/* UTF-16 */
+	struct {
+		uint32_t	code;
+		uint32_t	data_space;
+		uint32_t	data_length;
+		uint32_t	_reserved;
+		uint64_t	data_offset;
+	} parent_locator[8];
+	char		_reserved2[256];
+};
+#if __has_extension(c_static_assert)
+_Static_assert(sizeof(struct vhd_dyn_header) == VHD_SECTOR_SIZE * 2,
+    "Wrong size for header");
+#endif
+
+static int
+vhd_dyn_resize(lba_t imgsz)
+{
+	uint64_t imagesz;
+
+	imagesz = vhd_resize(imgsz * secsz);
+	return (image_set_size(imagesz / secsz));
+}
+
+static int
+vhd_dyn_write(int fd)
+{
+	struct vhd_footer footer;
+	struct vhd_dyn_header header;
+	uint64_t imgsz, rawsz;
+	lba_t blk, blkcnt, nblks;
+	uint32_t *bat;
+	void *bitmap;
+	size_t batsz;
+	uint32_t sector;
+	int bat_entries, error, entry;
+
+	rawsz = image_get_size() * secsz;
+	imgsz = (rawsz + VHD_BLOCK_SIZE - 1) & ~(VHD_BLOCK_SIZE - 1);
+
+	vhd_make_footer(&footer, rawsz, VHD_DISK_TYPE_DYNAMIC, sizeof(footer));
+	if (sparse_write(fd, &footer, sizeof(footer)) < 0)
+		return (errno);
+
+	bat_entries = imgsz / VHD_BLOCK_SIZE;
+	memset(&header, 0, sizeof(header));
+	be64enc(&header.cookie, VHD_HEADER_COOKIE);
+	be64enc(&header.data_offset, ~0ULL);
+	be64enc(&header.table_offset, sizeof(footer) + sizeof(header));
+	be32enc(&header.version, VHD_VERSION);
+	be32enc(&header.max_entries, bat_entries);
+	be32enc(&header.block_size, VHD_BLOCK_SIZE);
+	be32enc(&header.checksum, vhd_checksum(&header, sizeof(header)));
+	if (sparse_write(fd, &header, sizeof(header)) < 0)
+		return (errno);
+
+	batsz = bat_entries * sizeof(uint32_t);
+	batsz = (batsz + VHD_SECTOR_SIZE - 1) & ~(VHD_SECTOR_SIZE - 1);
+	bat = malloc(batsz);
+	if (bat == NULL)
+		return (errno);
+	memset(bat, 0xff, batsz);
+	blkcnt = VHD_BLOCK_SIZE / secsz;
+	sector = (sizeof(footer) + sizeof(header) + batsz) / VHD_SECTOR_SIZE;
+	for (entry = 0; entry < bat_entries; entry++) {
+		blk = entry * blkcnt;
+		if (image_data(blk, blkcnt)) {
+			be32enc(&bat[entry], sector);
+			sector += (VHD_BLOCK_SIZE / VHD_SECTOR_SIZE) + 1;
+		}
+	}
+	if (sparse_write(fd, bat, batsz) < 0) {
+		free(bat);
+		return (errno);
+	}
+	free(bat);
+
+	bitmap = malloc(VHD_SECTOR_SIZE);
+	if (bitmap == NULL)
+		return (errno);
+	memset(bitmap, 0xff, VHD_SECTOR_SIZE);
+
+	blk = 0;
+	blkcnt = VHD_BLOCK_SIZE / secsz;
+	error = 0;
+	nblks = rawsz / secsz;
+	while (blk < nblks) {
+		if (!image_data(blk, blkcnt)) {
+			blk += blkcnt;
+			continue;
+		}
+		if (sparse_write(fd, bitmap, VHD_SECTOR_SIZE) < 0) {
+			error = errno;
+			break;
+		}
+		/* Handle partial last block */
+		if (blk + blkcnt > nblks)
+			blkcnt = nblks - blk;
+		error = image_copyout_region(fd, blk, blkcnt);
+		if (error)
+			break;
+		blk += blkcnt;
+	}
+	free(bitmap);
+	if (error)
+		return (error);
+	error = image_copyout_zeroes(fd, imgsz - rawsz);
+	if (error)
+		return (error);
+	if (sparse_write(fd, &footer, sizeof(footer)) < 0)
+		return (errno);
+
+	return (0);
+}
+
+static struct mkimg_format vhd_dyn_format = {
+	.name = "vhd",
+	.description = "Virtual Hard Disk",
+	.resize = vhd_dyn_resize,
+	.write = vhd_dyn_write,
+};
+
+FORMAT_DEFINE(vhd_dyn_format);
+
+/*
+ * PART 3: Fixed VHD
+ */
+
+static int
+vhd_fix_resize(lba_t imgsz)
+{
+	uint64_t imagesz;
+
+	imagesz = vhd_resize(imgsz * secsz);
+	/*
+	 * Azure demands that images are a whole number of megabytes.
+	 */
+	imagesz = (imagesz + 0xfffffULL) & ~0xfffffULL;
+	return (image_set_size(imagesz / secsz));
+}
+
+static int
+vhd_fix_write(int fd)
+{
+	struct vhd_footer footer;
+	uint64_t imagesz;
+	int error;
+
+	error = image_copyout(fd);
+	if (error)
+		return (error);
+
+	imagesz = image_get_size() * secsz;
+	vhd_make_footer(&footer, imagesz, VHD_DISK_TYPE_FIXED, ~0ULL);
+	error = (sparse_write(fd, &footer, sizeof(footer)) < 0) ? errno : 0;
+	return (error);
+}
+
+static struct mkimg_format vhd_fix_format = {
+	.name = "vhdf",
+	.description = "Fixed Virtual Hard Disk",
+	.resize = vhd_fix_resize,
+	.write = vhd_fix_write,
+};
+
+FORMAT_DEFINE(vhd_fix_format);
diff --git a/usr.bin/mkimg/vmdk.c b/usr.bin/mkimg/vmdk.c
new file mode 100644
index 0000000000..3f7cb5867c
--- /dev/null
+++ b/usr.bin/mkimg/vmdk.c
@@ -0,0 +1,260 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/vmdk.c 306621 2016-10-03 02:37:28Z marcel $");
+
+#include <sys/errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "endian.h"
+#include "image.h"
+#include "format.h"
+#include "mkimg.h"
+
+#define	VMDK_IMAGE_ROUND	1048576
+#define	VMDK_MIN_GRAIN_SIZE	8192
+#define	VMDK_SECTOR_SIZE	512
+
+struct vmdk_header {
+	uint32_t	magic;
+#define	VMDK_MAGIC		0x564d444b
+	uint32_t	version;
+#define	VMDK_VERSION		1
+	uint32_t	flags;
+#define	VMDK_FLAGS_NL_TEST	(1 << 0)
+#define	VMDK_FLAGS_RGT_USED	(1 << 1)
+#define	VMDK_FLAGS_COMPRESSED	(1 << 16)
+#define	VMDK_FLAGS_MARKERS	(1 << 17)
+	uint64_t	capacity;
+	uint64_t	grain_size;
+	uint64_t	desc_offset;
+	uint64_t	desc_size;
+	uint32_t	ngtes;
+#define	VMDK_NGTES		512
+	uint64_t	rgd_offset;
+	uint64_t	gd_offset;
+	uint64_t	overhead;
+	uint8_t		unclean;
+	uint32_t	nl_test;
+#define	VMDK_NL_TEST		0x0a200d0a
+	uint16_t	compress;
+#define	VMDK_COMPRESS_NONE	0
+#define	VMDK_COMPRESS_DEFLATE	1
+	char		padding[433];
+} __attribute__((__packed__));
+
+static const char desc_fmt[] =
+    "# Disk DescriptorFile\n"
+    "version=%d\n"
+    "CID=%08x\n"
+    "parentCID=ffffffff\n"
+    "createType=\"monolithicSparse\"\n"
+    "# Extent description\n"
+    "RW %ju SPARSE \"%s\"\n"
+    "# The Disk Data Base\n"
+    "#DDB\n"
+    "ddb.adapterType = \"ide\"\n"
+    "ddb.geometry.cylinders = \"%u\"\n"
+    "ddb.geometry.heads = \"%u\"\n"
+    "ddb.geometry.sectors = \"%u\"\n";
+
+static uint64_t grainsz;
+
+static int
+vmdk_resize(lba_t imgsz)
+{
+	uint64_t imagesz;
+
+	imagesz = imgsz * secsz;
+	imagesz = (imagesz + VMDK_IMAGE_ROUND - 1) & ~(VMDK_IMAGE_ROUND - 1);
+	grainsz = (blksz < VMDK_MIN_GRAIN_SIZE) ? VMDK_MIN_GRAIN_SIZE : blksz;
+
+	if (verbose)
+		fprintf(stderr, "VMDK: image size = %ju, grain size = %ju\n",
+		    (uintmax_t)imagesz, (uintmax_t)grainsz);
+
+	grainsz /= VMDK_SECTOR_SIZE;
+	return (image_set_size(imagesz / secsz));
+}
+
+static int
+vmdk_write(int fd)
+{
+	struct vmdk_header hdr;
+	uint32_t *gt, *gd, *rgd;
+	char *buf, *desc;
+	off_t cur, lim;
+	uint64_t imagesz;
+	lba_t blkofs, blkcnt;
+	size_t gdsz, gtsz;
+	uint32_t sec, cursec;
+	int error, desc_len, n, ngrains, ngts;
+
+	imagesz = (image_get_size() * secsz) / VMDK_SECTOR_SIZE;
+
+	memset(&hdr, 0, sizeof(hdr));
+	le32enc(&hdr.magic, VMDK_MAGIC);
+	le32enc(&hdr.version, VMDK_VERSION);
+	le32enc(&hdr.flags, VMDK_FLAGS_NL_TEST | VMDK_FLAGS_RGT_USED);
+	le64enc(&hdr.capacity, imagesz);
+	le64enc(&hdr.grain_size, grainsz);
+
+	n = asprintf(&desc, desc_fmt, 1 /*version*/, 0 /*CID*/,
+	    (uintmax_t)imagesz /*size*/, "" /*name*/,
+	    ncyls /*cylinders*/, nheads /*heads*/, nsecs /*sectors*/);
+	if (n == -1)
+		return (ENOMEM);
+
+	desc_len = (n + VMDK_SECTOR_SIZE - 1) & ~(VMDK_SECTOR_SIZE - 1);
+	desc = realloc(desc, desc_len);
+	memset(desc + n, 0, desc_len - n);
+
+	le64enc(&hdr.desc_offset, 1);
+	le64enc(&hdr.desc_size, desc_len / VMDK_SECTOR_SIZE);
+	le32enc(&hdr.ngtes, VMDK_NGTES);
+
+	sec = desc_len / VMDK_SECTOR_SIZE + 1;
+
+	ngrains = imagesz / grainsz;
+	ngts = (ngrains + VMDK_NGTES - 1) / VMDK_NGTES;
+	gdsz = (ngts * sizeof(uint32_t) + VMDK_SECTOR_SIZE - 1) &
+	    ~(VMDK_SECTOR_SIZE - 1);
+
+	gd = calloc(1, gdsz);
+	if (gd == NULL) {
+		free(desc);
+		return (ENOMEM);
+	}
+	le64enc(&hdr.gd_offset, sec);
+	sec += gdsz / VMDK_SECTOR_SIZE;
+	for (n = 0; n < ngts; n++) {
+		le32enc(gd + n, sec);
+		sec += VMDK_NGTES * sizeof(uint32_t) / VMDK_SECTOR_SIZE;
+	}
+
+	rgd = calloc(1, gdsz);
+	if (rgd == NULL) {
+		free(gd);
+		free(desc);
+		return (ENOMEM);
+	}
+	le64enc(&hdr.rgd_offset, sec);
+	sec += gdsz / VMDK_SECTOR_SIZE;
+	for (n = 0; n < ngts; n++) {
+		le32enc(rgd + n, sec);
+		sec += VMDK_NGTES * sizeof(uint32_t) / VMDK_SECTOR_SIZE;
+	}
+
+	sec = (sec + grainsz - 1) & ~(grainsz - 1);
+
+	if (verbose)
+		fprintf(stderr, "VMDK: overhead = %ju\n",
+		    (uintmax_t)(sec * VMDK_SECTOR_SIZE));
+
+	le64enc(&hdr.overhead, sec);
+	be32enc(&hdr.nl_test, VMDK_NL_TEST);
+
+	gt = calloc(ngts, VMDK_NGTES * sizeof(uint32_t));
+	if (gt == NULL) {
+		free(rgd);
+		free(gd);
+		free(desc);
+		return (ENOMEM);
+	}
+	gtsz = ngts * VMDK_NGTES * sizeof(uint32_t);
+
+	cursec = sec;
+	blkcnt = (grainsz * VMDK_SECTOR_SIZE) / secsz;
+	for (n = 0; n < ngrains; n++) {
+		blkofs = n * blkcnt;
+		if (image_data(blkofs, blkcnt)) {
+			le32enc(gt + n, cursec);
+			cursec += grainsz;
+		}
+	}
+
+	error = 0;
+	if (!error && sparse_write(fd, &hdr, VMDK_SECTOR_SIZE) < 0)
+		error = errno;
+	if (!error && sparse_write(fd, desc, desc_len) < 0)
+		error = errno;
+	if (!error && sparse_write(fd, gd, gdsz) < 0)
+		error = errno;
+	if (!error && sparse_write(fd, gt, gtsz) < 0)
+		error = errno;
+	if (!error && sparse_write(fd, rgd, gdsz) < 0)
+		error = errno;
+	if (!error && sparse_write(fd, gt, gtsz) < 0)
+		error = errno;
+	free(gt);
+	free(rgd);
+	free(gd);
+	free(desc);
+	if (error)
+		return (error);
+
+	cur = VMDK_SECTOR_SIZE + desc_len + (gdsz + gtsz) * 2;
+	lim = sec * VMDK_SECTOR_SIZE;
+	if (cur < lim) {
+		buf = calloc(1, VMDK_SECTOR_SIZE);
+		if (buf == NULL)
+			error = ENOMEM;
+		while (!error && cur < lim) {
+			if (sparse_write(fd, buf, VMDK_SECTOR_SIZE) < 0)
+				error = errno;
+			cur += VMDK_SECTOR_SIZE;
+		}
+		if (buf != NULL)
+			free(buf);
+	}
+	if (error)
+		return (error);
+
+	blkcnt = (grainsz * VMDK_SECTOR_SIZE) / secsz;
+	for (n = 0; n < ngrains; n++) {
+		blkofs = n * blkcnt;
+		if (image_data(blkofs, blkcnt)) {
+			error = image_copyout_region(fd, blkofs, blkcnt);
+			if (error)
+				return (error);
+		}
+	}
+	return (image_copyout_done(fd));
+}
+
+static struct mkimg_format vmdk_format = {
+	.name = "vmdk",
+	.description = "Virtual Machine Disk",
+	.resize = vmdk_resize,
+	.write = vmdk_write,
+};
+
+FORMAT_DEFINE(vmdk_format);
diff --git a/usr.bin/mkimg/vtoc8.c b/usr.bin/mkimg/vtoc8.c
new file mode 100644
index 0000000000..2c0e1bf8de
--- /dev/null
+++ b/usr.bin/mkimg/vtoc8.c
@@ -0,0 +1,115 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/mkimg/vtoc8.c 307544 2016-10-18 01:55:07Z marcel $");
+
+#include <sys/errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <vtoc.h>
+
+#include "endian.h"
+#include "image.h"
+#include "mkimg.h"
+#include "scheme.h"
+
+static struct mkimg_alias vtoc8_aliases[] = {
+    {	ALIAS_FREEBSD_NANDFS, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_NANDFS) },
+    {	ALIAS_FREEBSD_SWAP, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_SWAP) },
+    {	ALIAS_FREEBSD_UFS, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_UFS) },
+    {	ALIAS_FREEBSD_VINUM, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_VINUM) },
+    {	ALIAS_FREEBSD_ZFS, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_NANDFS) },
+    {	ALIAS_NONE, 0 }
+};
+
+static lba_t
+vtoc8_metadata(u_int where, lba_t blk)
+{
+
+	blk += (where == SCHEME_META_IMG_START) ? 1 : 0;
+	return (round_cylinder(blk));
+}
+
+static int
+vtoc8_write(lba_t imgsz, void *bootcode __unused)
+{
+	struct vtoc8 vtoc8;
+	struct part *part;
+	u_char *p;
+	int error, n;
+	uint16_t ofs, sum;
+
+	imgsz = (lba_t)ncyls * nheads * nsecs;
+
+	memset(&vtoc8, 0, sizeof(vtoc8));
+	sprintf(vtoc8.ascii, "FreeBSD%lldM",
+	    (long long)(imgsz * secsz / 1048576));
+	be32enc(&vtoc8.version, VTOC_VERSION);
+	be16enc(&vtoc8.nparts, VTOC8_NPARTS);
+	be32enc(&vtoc8.sanity, VTOC_SANITY);
+	be16enc(&vtoc8.rpm, 3600);
+	be16enc(&vtoc8.physcyls, ncyls);
+	be16enc(&vtoc8.ncyls, ncyls);
+	be16enc(&vtoc8.altcyls, 0);
+	be16enc(&vtoc8.nheads, nheads);
+	be16enc(&vtoc8.nsecs, nsecs);
+	be16enc(&vtoc8.magic, VTOC_MAGIC);
+
+	be32enc(&vtoc8.map[VTOC_RAW_PART].nblks, imgsz);
+	TAILQ_FOREACH(part, &partlist, link) {
+		n = part->index + ((part->index >= VTOC_RAW_PART) ? 1 : 0);
+		be16enc(&vtoc8.part[n].tag, ALIAS_TYPE2INT(part->type));
+		be32enc(&vtoc8.map[n].cyl, part->block / (nsecs * nheads));
+		be32enc(&vtoc8.map[n].nblks, part->size);
+	}
+
+	/* Calculate checksum. */
+	sum = 0;
+	p = (void *)&vtoc8;
+	for (ofs = 0; ofs < sizeof(vtoc8) - 2; ofs += 2)
+		sum ^= be16dec(p + ofs);
+	be16enc(&vtoc8.cksum, sum);
+
+	error = image_write(0, &vtoc8, 1);
+	return (error);
+}
+
+static struct mkimg_scheme vtoc8_scheme = {
+	.name = "vtoc8",
+	.description = "SMI VTOC8 disk labels",
+	.aliases = vtoc8_aliases,
+	.metadata = vtoc8_metadata,
+	.write = vtoc8_write,
+	.nparts = VTOC8_NPARTS - 1,
+	.maxsecsz = 512
+};
+
+SCHEME_DEFINE(vtoc8_scheme);
-- 
2.17.1

