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