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