History log of /freebsd-head/usr.bin/mkimg/mkimg.c
Revision Date Author Comments
10246e837a91b2556801821a992ed6509dfa6d1e 12-Apr-2018 benno <benno@FreeBSD.org> Fix a conditional that got mucked up.

Sponsored by: iXsystems, Inc.
19e7651c74afe544df560120ec2986e83fbbb627 12-Apr-2018 benno <benno@FreeBSD.org> Add the ability to specify absolute and relative offsets to size partitions.

To create hybrid boot media we want to specify a partition at a known location.
This extends the syntax of size partitions to include an optional offset that
can be absolute or relative. It also introduces validation to make sure that
this hasn't resulted in overlapping partitions. I haven't added this to the
file and process partition specifications yet but the mechanics are designed
such that if someone comes up with a good way of specifying the offset it
will be fairly easy to add in.

Reviewed by: imp
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D14916
bf54eea21a419c6505139c7b196ace26b9eb8c8c 10-May-2017 manu <manu@FreeBSD.org> mkimg: Add -C argument to specify maximum capacity

Add a -C option to specify a maximum capacity for the final image file.
It is useful to control the size of the generated image for sdcard or
when we will add dynamic size partition.

Add --capacity which is a shorthand to define min and max capacity at
the same time.

Reviewed by: bapt, marcel, wblock (manpages)
Sponsored by: Gandi.net
Differential Revision: https://reviews.freebsd.org/D10509
5f1361a7ee6f30ec31b8b63993df6b8288d13615 18-Oct-2016 imp <imp@FreeBSD.org> Add a new flag to mkimg (-a num) to specify the active partition for
those partitioning schemes that have this concept. Implement it as an
override for mbr's setting 0x80 in the flags for the first partition
when we have boot code.

Differential Revision: https://reviews.freebsd.org/D4403
a31300a1ec00c0d5b95ebc0cd0d59818668fabc4 18-Oct-2016 marcel <marcel@FreeBSD.org> o Provide a private definition for UUIDs (mkimg_uuid_t) because
UUIDs are not portable.
o Move mkimg_uuid() to a new file and merge both gpt_uuid_enc()
and vhd_uuid_enc() into a single mkimg_uuid_enc() that lives
in the same file.
o Move the OS-specific implementation of generating a UUID to
osdep_uuidgen() and provide the implementations for FreeBSD,
macOS and Linux.
o Expect the partitioning scheme headers to be found by having
a search to the directory in which the headers live. This
avoids conflicts on non-FreeBSD machines.
2e6ae9742cf5677101e39b60016ebc77e6aaf435 03-Oct-2016 marcel <marcel@FreeBSD.org> Replace OFF_MAX with INT64_MAX. The former is defined on Linux.
5e84416ac964829fd8974acdd790791ef1d2aa7e 03-Oct-2016 marcel <marcel@FreeBSD.org> Prefer <stdint.h> over <sys/types.h>. While here remove redundant
inclusion of <sys/queue.h>.

Move the inclusion of the disk partitioning headers out of order
and inbetween standard headers and local header. They will change
in a subsequent commit.
f258aa5cde1113f397c3300bd85cc1798b6a7960 03-Oct-2016 marcel <marcel@FreeBSD.org> Replace STAILQ with TAILQ. TAILQs are portable enough that they can
be used on both macOS and Linux. STAILQs are not. In particular,
STAILQ_LAST does not next on Linux. Since neither STAILQ_FOREACH_SAFE
nor TAILQ_FOREACH_SAFE exist on Linux, replace its use with a regular
TAILQ_FOREACH. The _SAFE variant was only used for having the next
pointer in a local variable.
a70a0571cb84a55133d9b7e2639aeca584691de4 25-Sep-2016 marcel <marcel@FreeBSD.org> Replace the use of linker sets with constructors for both the
formats and schemes. Formats and schemes are registered at
runtime now, rather than collected at link time.
89337d7b723a2607780884564870331752e50171 24-Sep-2016 marcel <marcel@FreeBSD.org> Update local variable 'block' after calling capacity_resize(),
otherwise format_resize(), which is called right after, isn't
getting the current/actual image size. Rather than rounding up,
format_resize() could end up truncating the size and we don't
allow that by design.

MFC after: 1 week
00d578928eca75be320b36d37543a7e2a4f9fbdb 27-May-2016 grehan <grehan@FreeBSD.org> Create branch for bhyve graphics import.
e4538d7f16467dec857ab8e8974664043aebed5a 17-Jun-2015 marcel <marcel@FreeBSD.org> MFC 279125, 279126, 279128, 279139:
Add the -c option for specifying the capacity of the disk image.
Bump the version to 20150222.
1603ce9a33ddb0dc5267a0f77616314fa3cdf101 22-Feb-2015 marcel <marcel@FreeBSD.org> Add the -c option for specifying the capacity of the disk image. When
a capcity is given, no partitions are required. When no partitions are
given, no scheme needs to be specified either. This makes it possible
to create an entirely empty disk image. To add an empty partitioning
table, specify the scheme.

Bump the version to 20150222.
88793a4ac9b477634e5763a3796e1d185081e8e5 22-Feb-2015 marcel <marcel@FreeBSD.org> Don't require a scheme if no partitions are given. Change the code
to handle that case. Note that we still require partitions, so the
change is effectively a no-op.
06c3519db4ab553527fa1efe992f1fc8099ec02e 22-Feb-2015 marcel <marcel@FreeBSD.org> Remove extraneous parenthesis in assignment.
4742b8fd12181fb4ab76f445c6bf6e95c7598e0c 08-Oct-2014 marcel <marcel@FreeBSD.org> MFC r272485: Fill cyclinder, head and sector fields for the EBR,
MBR and PC98 schemes.

Requested by: gjb
27db89ec695f2599ec2afd7010338235b49ea485 08-Oct-2014 marcel <marcel@FreeBSD.org> MFC 272198, 272217:
Add 3 long options (--version, --formats & --schemes) for getting
information about mkimg itself.

Requested by: gjb

Relnotes: yes
ad936aa7f4c00106fddfb0c8ef0e057b0fdb1a9f 03-Oct-2014 marcel <marcel@FreeBSD.org> Add mkimg_chs() for those schemes that need the LBA broken down into
cylinder, head and track numbers. Return ~0U for these values when
mkimg wasn't given both -T and -H (i.e. no geometry) or the cylinder
would be larger than the provided maximum.

Use mkimgs_chs() for the EBR, MBR and PC98 schemes to fill in the
appropriate fields. Make sure to use a "rounded" size so that the
partition is always a multiple of the track size. We reserved the
room for it in the metadata callback so that's a valid thing to

Bump the mkimg version number.
While doing that again: have mkimg.o depend on the Makefile so that
a version change triggers a rebuild as needed.
2bf89afb2b390cf0e131c1d6b2f377b480f4bf21 27-Sep-2014 marcel <marcel@FreeBSD.org> Update the usage message and the man page to account for the new long
options. Bump the version number to 20140927.
While here, use explicit fputc() calls to skip a line in the output.
This to avoid having to hunt for extra '\n' characters in the printf
format strings.

MFC after: 1 week
Relnotes: yes
bf39d18edb9ad7a21a819c3dad15cc5d653191a2 27-Sep-2014 marcel <marcel@FreeBSD.org> Add 3 long options for getting information about mkimg itself:
--version print the version of mkimg and also whether it's
64- or 32-bit.
--formats list the supported output formats separated by space.
--schemes list the supported partitioning schemes separated by

Inspired by a patch from: gjb@

MFC after: 1 week
Relnotes: yes
a6288e6f8dd6adc0fe8a9e9250a8b65ec769c0f5 22-Sep-2014 marcel <marcel@FreeBSD.org> MFC 271482: Add support for adding empty partition entries.

Relnotes: yes
Approved by: re@ (gjb)
91c4578a03d7a8305fb1a393adee17b31c67f7c2 12-Sep-2014 marcel <marcel@FreeBSD.org> Add support for adding empty partition entries. I.e. skip partition
numbers or names. This gives more control over the actual layout and
helps to construct BSD disklabels with /usr or /var at dedicated

Obtained from: Juniper Networks, Inc.
MFC after: 3 days
Relnotes: yes
37a9f7be2fd32cf24c75d466cacac9ce83a3766b 28-Jul-2014 marcel <marcel@FreeBSD.org> MFC r268236,268264,268524,268646,268802,269021:
This brings VHD support to mkimg(1); both dynamic and fixed file formats.
Dynamic VHD and VMDK file images are now sparsely written, meaning that
"free" sectors do not occupy space.

Relnotes: yes
72dff6b0abb1ab52a520a1feb2c2ce11b056dafc 04-Jul-2014 marcel <marcel@FreeBSD.org> Document the -y option as a unit test option.
Add missing -v (and -y) to the usage message.

Requested by: eadler@
a33844e926a330bdb5c1966b112da53d2735b82a 02-Jul-2014 marcel <marcel@FreeBSD.org> MFC mkimg(1) -- revisions 268159, 268134, 266556, 266514, 266513,
266512, 266511, 266510, 266509, 266176, 265468, 265467,
265462, 265170, 263926, 263924, 263923, 263919 and 263918.

Revision 267182 changed mkimg.1 alongside other unrelated manpages.
The change to mkimg.1 has been applied without registering a merge
of the revision. This allows a future merge of r267182 to happen.

Relnotes: yes
f10e28b41fb321b32c2b40e964d002b0cd1cc51a 06-May-2014 marcel <marcel@FreeBSD.org> Add mkimg_write() which combines lseek(2) and write(2) and uses
sector granularity for both offset and length. Have all schemes
use mkimg_write() instead of mkimg_seek() followed by write(2).

Now that schemes don't use lseek(2) nor write(2) directly, it's
easier to support output formats other than raw disks.