xref: /freebsd/usr.bin/mkimg/mkimg.1 (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1.\" Copyright (c) 2013, 2014 Juniper Networks, Inc.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\"
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24.\"
25.Dd February 28, 2024
26.Dt MKIMG 1
27.Os
28.Sh NAME
29.Nm mkimg
30.Nd "utility to make disk images"
31.Sh SYNOPSIS
32.Nm
33.Op Fl H Ar heads
34.Op Fl P Ar blksz
35.Op Fl S Ar secsz
36.Op Fl T Ar tracksz
37.Op Fl b Ar bootcode
38.Op Fl c Ar min_capacity
39.Op Fl C Ar max_capacity
40.Op Fl -capacity Ar capacity
41.Op Fl f Ar format
42.Op Fl o Ar outfile
43.Op Fl a Ar active
44.Op Fl v
45.Op Fl y
46.Op Fl s Ar scheme Op Fl p Ar partition ...
47.Nm
48.Fl -formats | Fl -schemes | Fl -version
49.Sh DESCRIPTION
50The
51.Nm
52utility creates a disk image from the raw partition contents specified with
53the
54.Ar partition
55argument(s) and using the partitioning scheme specified with the
56.Ar scheme
57argument.
58The disk image is written to
59.Ar stdout
60by default or the file specified with the
61.Ar outfile
62argument.
63The image file is a raw disk image by default, but the format of the
64image file can be specified with the
65.Ar format
66argument.
67.Pp
68The disk image can be made bootable by specifying the scheme-specific boot
69block contents with the
70.Ar bootcode
71argument and,
72depending on the scheme,
73with a boot partition.
74The contents of such a boot partition is provided like any other partition
75and the
76.Nm
77utility does not treat it any differently from other partitions.
78.Pp
79Some partitioning schemes need a disk geometry and for those the
80.Nm
81utility accepts the
82.Ar tracksz
83and
84.Ar heads
85arguments, specifying the number of sectors per track and the number of
86heads per cylinder (resp.)
87.Pp
88Both the logical and physical sector size can be specified and for that the
89.Nm
90utility
91accepts the
92.Ar secsz
93and
94.Ar blksz
95arguments.
96The
97.Ar secsz
98argument is used to specify the logical sector size.
99This is the sector size reported by a disk when queried for its capacity.
100Modern disks use a larger sector size internally,
101referred to as block size by the
102.Nm
103utility and this can be specified by the
104.Ar blksz
105argument.
106The
107.Nm
108utility will use the (physical) block size to determine the start of
109partitions and to round the size of the disk image.
110.Pp
111The
112.Fl c
113option can be used to specify a minimal capacity for the disk image.
114Use this option without the
115.Fl s
116and
117.Fl p
118options to create an empty disk image with the given (virtual) size.
119An empty partition table can be written to the disk when specifying a
120partitioning scheme with the
121.Fl s
122option, but without specifying any partitions.
123When the size required for all the partitions is larger than the
124given capacity, then the disk image will be larger than the capacity
125given.
126.Pp
127The
128.Fl C
129option specifies a maximum capacity for the disk image.
130If the combined sizes of the given partitions exceed the size given with
131.Fl C ,
132image creation fails.
133.Pp
134The
135.Fl -capacity
136option is a shorthand to specify the minimum and maximum capacity at the
137same time.
138.Pp
139The
140.Fl v
141option increases the level of output that the
142.Nm
143utility prints.
144.Pp
145The
146.Fl y
147option is used for testing purposes only and is not to be used in production.
148When present, the
149.Nm
150utility will generate predictable values for Universally Unique Identifiers
151(UUIDs) and time stamps so that consecutive runs of the
152.Nm
153utility will create images that are identical.
154.Pp
155The
156.Ar active
157option marks a partition as active, if the partitioning
158scheme supports it.
159Currently, only the
160.Ar mbr
161scheme supports this concept.
162By default,
163.Nm
164will only mark the first partition as active when boot code is
165specified.
166Use the
167.Ar active
168option to override the active partition.
169The number specified corresponds to the number after the 's' in the
170partition's
171.Xr geom 8
172name.
173No partitions are marked active when the value is 0.
174.Pp
175A set of long options exist to query about the
176.Nm
177utility itself.
178Options in this set should be given by themselves because the
179.Nm
180utility exits immediately after providing the requested information.
181The version of the
182.Nm
183utility is printed when the
184.Fl -version
185option is given.
186The list of supported output formats is printed when the
187.Fl -formats
188option is given and the list of supported partitioning schemes is printed
189when the
190.Fl -schemes
191option is given.
192Both the format and scheme lists a space-separated lists for easy handling
193in scripts.
194.Pp
195For a more descriptive list of supported partitioning schemes or supported
196output format, or for a detailed description of how to specify partitions,
197run the
198.Nm
199utility without any arguments.
200This will print a usage message with all the necessary details.
201.Sh DISK FORMATS
202The
203.Nm
204utility supports a number of output file formats.
205A short description of these is given below.
206.Ss QCOW and QCOW2
207QCOW stands for "QEMU Copy On Write".
208It's a sparse file format akin to VHD and VMDK and QCOW represents the
209first version.
210QCOW2 represents version 2 of the file format.
211Version 2 is not backward compatible with version 1 and adds support for
212snapshots among other things.
213The QCOW file formats are natively supported by QEMU and Xen.
214To write QCOW, specify
215.Fl f Ar qcow
216on the command line.
217To write version 2 QCOW, specify
218.Fl f Ar qcow2
219on the command line.
220The preferred file extension is ".qcow" and ".qcow2" for QCOW and QCOW2
221(resp.), but ".qcow" is sometimes used for version 2 files as well.
222.Ss RAW file format
223This file format is a sector by sector representation of an actual disk.
224There is no extra information that describes or relates to the format itself.
225The size of the file is the size of the (virtual) disk.
226This file format is suitable for being copied onto a disk with utilities
227like
228.Nm dd .
229To write a raw disk file, either omit the
230.Fl f
231option, or specify
232.Fl f Ar raw
233on the command line.
234The preferred file extension is one of ".img" or ".raw", but there's no
235real convention for it.
236.Ss Dynamic VHD and Fixed VHD
237Microsoft's "Virtual Hard Disk" file formats.
238The dynamic format is a sparse format akin to QCOW and VMDK.
239The fixed format is effectively a raw format with a footer appended to the
240file and as such it's often indistinguishable from the raw format.
241The fixed file format has been added to support Microsoft's Azure platform
242and due to inconsistencies in interpretation of the footer is not compatible
243with utilities like
244.Nm qemu
245when it is specifically instructed to interpreted the file as a VHD file.
246By default
247.Nm qemu
248will treat the file as a raw disk file, which mostly works fine.
249To have
250.Nm
251create a dynamic VHD file, specify
252.Fl f Ar vhd
253on the command line.
254To create a fixed VHD file for use by Azure, specify
255.Fl f Ar vhdf
256on the command line.
257The preferred file extension is ".vhd".
258.Ss Dynamic VHDX
259Microsoft's "Virtual Hard Disk v2" file formats, the
260successor to VHD.
261VHDX is the required format for the 2nd generation Hyper-V VMs.
262To have
263.Nm
264create a dynamic VHDX file, specify
265.Fl f Ar vhdx
266on the command line.
267The preferred file extension is ".vhdx".
268.Ss VMDK
269VMware's "Virtual Machine Disk" file format.
270It's a sparse file format akin to QCOW and VHD and supported by many
271virtualization solutions.
272To create a VMDK file, specify
273.Fl f Ar vmdk
274on the command line.
275The preferred file extension is ".vmdk".
276.Pp
277Not all virtualization solutions support all file formats, but often those
278virtualization environments have utilities to convert from one format to
279another.
280Note however that conversion may require that the virtual disk size is
281changed to match the constraints of the output format and this may invalidate
282the contents of the disk image.
283For example, the GUID Partition Table (GPT) scheme has a header in the last
284sector on the disk.
285When changing the disk size, the GPT must be changed so that the last header
286is moved accordingly.
287This is typically not part of the conversion process.
288If possible, use an output format specifically for the environment in which
289the file is intended to be used.
290.Sh PARTITION SPECIFICATION
291An option
292.Fl p
293may be used multiple times to specify a list of created partition entries.
294A specification that is a single dash indicates an unused partition entry.
295Otherwise, a partition specification has the following format:
296.Bd -literal -offset indent
297<type> ':' <kind> <contents>
298.Ed
299.Bl -tag -width indent
300.It Cm type
301the partition type alias (f.e.: freebsd-swap)
302that may be optionally followed by a '/' separator
303and a label for partitioning schemes that feature partition labels
304(see the
305.Sx EXAMPLES
306Section below)
307.It Cm kind
308the interpretation of the contents specification:
309.Bl -tag -width indent
310.It Cm ':'
311contents holds the size of an empty partition,
312a number that may be suffixed with one of K, M, G, T, P or E
313(either upper or lower case) following the SI power of two convention
314(see also
315.Xr expand_number 3 )
316.It Cm '='
317contents holds the name of a file to read
318.It Cm '-'
319contents holds a command to run; the output of which is the contents
320of the partition.
321Multi-word strings should be quoted according to the shell rules.
322.El
323.It Cm contents
324the specification of a partition's contents
325.El
326.Sh ENVIRONMENT
327.Bl -tag -width "TMPDIR" -compact
328.It Ev TMPDIR
329Directory to put temporary files in; default is
330.Pa /tmp .
331.El
332.Sh EXAMPLES
333To create a bootable disk image that is partitioned using the GPT scheme and
334containing a root file system that was previously created using
335.Xr makefs 8
336and also containing a swap partition, run the
337.Nm
338utility as follows:
339.Dl % mkimg -s gpt -b /boot/pmbr -p freebsd-boot:=/boot/gptboot \
340-p freebsd-ufs:=root-file-system.ufs -p freebsd-swap::1G \
341-o gpt.img
342.Pp
343The command line given above results in a raw image file.
344This is because no output format was given.
345To create a VMDK image for example, add the
346.Fl f Ar vmdk
347argument to the
348.Nm
349utility and name the output file accordingly.
350.Pp
351A nested partitioning scheme is created by running the
352.Nm
353utility twice.
354The output of the first will be fed as the contents of a partition to the
355second.
356This can be done using a temporary file, like so:
357.Dl % mkimg -s bsd -b /boot/boot -p freebsd-ufs:=root-file-system.ufs \
358-p freebsd-swap::1G -o /tmp/bsd.img
359.Dl % mkimg -s mbr -b /boot/mbr -p freebsd:=/tmp/bsd.img -o mbr-bsd.img
360.Pp
361Alternatively, the
362.Nm
363utility can be run in a cascaded fashion, whereby the output of the
364first is fed directly into the second.
365To do this, run the
366.Nm
367utility as follows:
368.Dl % mkimg -s mbr -b /boot/mbr -p freebsd:-'mkimg -s bsd -b /boot/boot \
369-p freebsd-ufs:=root-file-system.ufs -p freebsd-swap::1G' -o mbr-bsd.img
370.Pp
371To accommodate the need to have partitions named or numbered in a certain
372way, the
373.Nm
374utility allows for the specification of empty partitions.
375For example, to create an image that is compatible with partition layouts
376found in
377.Pa /etc/disktab ,
378the 'd' partition often needs to be skipped.
379This is accomplished by inserting an unused partition after the first 2
380partition specifications.
381It is worth noting at this time that the BSD scheme will automatically
382skip the 'c' partition by virtue of it referring to the entire disk.
383To create an image that is compatible with the qp120at disk, use the
384.Nm
385utility as follows:
386.Dl % mkimg -s bsd -b /boot/boot -p freebsd-ufs:=root-file-system.ufs \
387-p freebsd-swap::20M -p- -p- -p- -p- -p freebsd-ufs:=usr-file-system.ufs \
388-o bsd.img
389.Pp
390For partitioning schemes that feature partition labels, the
391.Nm
392utility supports assigning labels to the partitions specified.
393In the following example the file system partition is labeled as 'backup':
394.Dl % mkimg -s gpt -p freebsd-ufs/backup:=file-system.ufs -o gpt.img
395.Sh SEE ALSO
396.Xr dd 1 ,
397.Xr expand_number 3 ,
398.Xr gpart 8 ,
399.Xr makefs 8 ,
400.Xr mdconfig 8 ,
401.Xr newfs 8
402.Sh HISTORY
403The
404.Nm
405utility first appeared in
406.Fx 10.1 .
407.Sh AUTHORS
408The
409.Nm
410utility and manpage were written by
411.An Marcel Moolenaar Aq Mt marcel@FreeBSD.org .
412