xref: /freebsd/usr.bin/mkimg/mkimg.1 (revision 6137b5f7b8c183ee8806d79b3f1d8e5e3ddb3df3)
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 June 8, 2020
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 ENVIRONMENT
291.Bl -tag -width "TMPDIR" -compact
292.It Ev TMPDIR
293Directory to put temporary files in; default is
294.Pa /tmp .
295.El
296.Sh EXAMPLES
297To create a bootable disk image that is partitioned using the GPT scheme and
298containing a root file system that was previously created using
299.Xr makefs 8
300and also containing a swap partition, run the
301.Nm
302utility as follows:
303.Dl % mkimg -s gpt -b /boot/pmbr -p freebsd-boot:=/boot/gptboot \
304-p freebsd-ufs:=root-file-system.ufs -p freebsd-swap::1G \
305-o gpt.img
306.Pp
307The command line given above results in a raw image file.
308This is because no output format was given.
309To create a VMDK image for example, add the
310.Fl f Ar vmdk
311argument to the
312.Nm
313utility and name the output file accordingly.
314.Pp
315A nested partitioning scheme is created by running the
316.Nm
317utility twice.
318The output of the first will be fed as the contents of a partition to the
319second.
320This can be done using a temporary file, like so:
321.Dl % mkimg -s bsd -b /boot/boot -p freebsd-ufs:=root-file-system.ufs \
322-p freebsd-swap::1G -o /tmp/bsd.img
323.Dl % mkimg -s mbr -b /boot/mbr -p freebsd:=/tmp/bsd.img -o mbr-bsd.img
324.Pp
325Alternatively, the
326.Nm
327utility can be run in a cascaded fashion, whereby the output of the
328first is fed directly into the second.
329To do this, run the
330.Nm
331utility as follows:
332.Dl % mkimg -s mbr -b /boot/mbr -p freebsd:-'mkimg -s bsd -b /boot/boot \
333-p freebsd-ufs:=root-file-system.ufs -p freebsd-swap::1G' -o mbr-bsd.img
334.Pp
335To accommodate the need to have partitions named or numbered in a certain
336way, the
337.Nm
338utility allows for the specification of empty partitions.
339For example, to create an image that is compatible with partition layouts
340found in
341.Pa /etc/disktab ,
342the 'd' partition often needs to be skipped.
343This is accomplished by inserting an unused partition after the first 2
344partition specifications.
345It is worth noting at this time that the BSD scheme will automatically
346skip the 'c' partition by virtue of it referring to the entire disk.
347To create an image that is compatible with the qp120at disk, use the
348.Nm
349utility as follows:
350.Dl % mkimg -s bsd -b /boot/boot -p freebsd-ufs:=root-file-system.ufs \
351-p freebsd-swap::20M -p- -p- -p- -p- -p freebsd-ufs:=usr-file-system.ufs \
352-o bsd.img
353.Pp
354For partitioning schemes that feature partition labels, the
355.Nm
356utility supports assigning labels to the partitions specified.
357In the following example the file system partition is labeled as 'backup':
358.Dl % mkimg -s gpt -p freebsd-ufs/backup:=file-system.ufs -o gpt.img
359.Sh SEE ALSO
360.Xr dd 1 ,
361.Xr gpart 8 ,
362.Xr makefs 8 ,
363.Xr mdconfig 8 ,
364.Xr newfs 8
365.Sh HISTORY
366The
367.Nm
368utility first appeared in
369.Fx 10.1 .
370.Sh AUTHORS
371The
372.Nm
373utility and manpage were written by
374.An Marcel Moolenaar Aq Mt marcel@FreeBSD.org .
375