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 February 22, 2015 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 capacity 41.Op Fl f Ar format 42.Op Fl o Ar outfile 43.Op Fl v 44.Op Fl y 45.Op Fl s Ar scheme Op Fl p Ar partition ... 46.Nm 47.Ar --formats | --schemes | --version 48.Sh DESCRIPTION 49The 50.Nm 51utility creates a disk image from the raw partition contents specified with 52the 53.Ar partition 54argument(s) and using the partitioning scheme specified with the 55.Ar scheme 56argument. 57The disk image is written to 58.Ar stdout 59by default or the file specified with the 60.Ar outfile 61argument. 62The image file is a raw disk image by default, but the format of the 63image file can be specified with the 64.Ar format 65argument. 66.Pp 67The disk image can be made bootable by specifying the scheme-specific boot 68block contents with the 69.Ar bootcode 70argument and, 71depending on the scheme, 72with a boot partition. 73The contents of such a boot partition is provided like any other partition 74and the 75.Nm 76utility does not treat it any differently from other partitions. 77.Pp 78Some partitioning schemes need a disk geometry and for those the 79.Nm 80utility accepts the 81.Ar tracksz 82and 83.Ar heads 84arguments, specifying the number of sectors per track and the number of 85heads per cylinder (resp.) 86.Pp 87Both the logical and physical sector size can be specified and for that the 88.Nm 89utility 90accepts the 91.Ar secsz 92and 93.Ar blksz 94arguments. 95The 96.Ar secsz 97argument is used to specify the logical sector size. 98This is the sector size reported by a disk when queried for its capacity. 99Modern disks use a larger sector size internally, 100referred to as block size by the 101.Nm 102utility and this can be specified by the 103.Ar blksz 104argument. 105The 106.Nm 107utility will use the (physical) block size to determine the start of 108partitions and to round the size of the disk image. 109.Pp 110The 111.Fl c 112option can be used to specify a minimal capacity for the disk image. 113Use this option without the 114.Fl s 115and 116.Fl p 117options to create an empty disk image with the given (virtual) size. 118An empty partition table can be written to the disk when specifying a 119partitioning scheme with the 120.Fl s 121option, but without specifying any partitions. 122When the size required to for all the partitions is larger than the 123given capacity, then the disk image will be larger than the capacity 124given. 125.Pp 126The 127.Fl v 128option increases the level of output that the 129.Nm 130utility prints. 131.Pp 132The 133.Fl y 134option is used for testing purposes only and is not to be used in production. 135When present, the 136.Nm 137utility will generate predictable values for Universally Unique Identifiers 138(UUIDs) and time stamps so that consecutive runs of the 139.Nm 140utility will create images that are identical. 141.Pp 142A set of long options exist to query about the 143.Nm 144utilty itself. 145Options in this set should be given by themselves because the 146.Nm 147utility exits immediately after providing the requested information. 148The version of the 149.Nm 150utility is printed when the 151.Ar --version 152option is given. 153The list of supported output formats is printed when the 154.Ar --formats 155option is given and the list of supported partitioning schemes is printed 156when the 157.Ar --schemes 158option is given. 159Both the format and scheme lists a space-separated lists for easy handling 160in scripts. 161.Pp 162For a more descriptive list of supported partitioning schemes or supported 163output format, or for a detailed description of how to specify partitions, 164run the 165.Nm 166utility without any arguments. 167This will print a usage message with all the necessary details. 168.Sh ENVIRONMENT 169.Bl -tag -width "TMPDIR" -compact 170.It Ev TMPDIR 171Directory to put temporary files in; default is 172.Pa /tmp . 173.El 174.Sh EXAMPLES 175To create a bootable disk image that is partitioned using the GPT scheme and 176containing a root file system that was previously created using 177.Xr makefs 178and also containing a swap partition, run the 179.Nm 180utility as follows: 181.Dl % mkimg -s gpt -b /boot/pmbr -p freebsd-boot:=/boot/gptboot \ 182-p freebsd-ufs:=root-file-system.ufs -p freebsd-swap::1G \ 183-o gpt.img 184.Pp 185The command line given above results in a raw image file. 186This is because no output format was given. 187To create a VMDK image for example, add the 188.Fl f Ar vmdk 189argument to the 190.Nm 191utility and name the output file accordingly. 192.Pp 193A nested partitioning scheme is created by running the 194.Nm 195utility twice. 196The output of the first will be fed as the contents of a partition to the 197second. 198This can be done using a temporary file, like so: 199.Dl % mkimg -s bsd -b /boot/boot -p freebsd-ufs:=root-file-system.ufs \ 200-p freebsd-swap::1G -o /tmp/bsd.img 201.Dl % mkimg -s mbr -b /boot/mbr -p freebsd:=/tmp/bsd.img -o mbr-bsd.img 202.Pp 203Alternatively, the 204.Nm 205utility can be run in a cascaded fashion, whereby the output of the 206first is fed directly into the second. 207To do this, run the 208.Nm 209utility as follows: 210.Dl % mkimg -s mbr -b /boot/mbr -p freebsd:-'mkimg -s bsd -b /boot/boot \ 211-p freebsd-ufs:=root-file-system.ufs -p freebsd-swap::1G' -o mbr-bsd.img 212.Pp 213To accomodate the need to have partitions named or numbered in a certain 214way, the 215.Nm 216utility allows for the specification of empty partitions. 217For example, to create an image that is compatible with partition layouts 218found in 219.Pa /etc/disktab , 220the 'd' partition often needs to be skipped. 221This is accomplished by inserting an unused partition after the first 2 222partition specifications. 223It is worth noting at this time that the BSD scheme will automatically 224skip the 'c' partition by virtue of it referring to the entire disk. 225To create an image that is compatible with the qp120at disk, use the 226.Nm 227utility as follows: 228.Dl % mkimg -s bsd -b /boot/boot -p freebsd-ufs:=root-file-system.ufs \ 229-p freebsd-swap::20M -p- -p- -p- -p- -p freebsd-ufs:=usr-file-system.ufs \ 230-o bsd.img 231.Pp 232For partitioning schemes that feature partition labels, the 233.Nm 234utility supports assigning labels to the partitions specified. 235In the following example the file system partition is labeled as 'backup': 236.Dl % mkimg -s gpt -p freebsd-ufs/backup:=file-system.ufs -o gpt.img 237.Sh SEE ALSO 238.Xr gpart 8 , 239.Xr makefs 8 , 240.Xr mdconfig 8 , 241.Xr newfs 8 242.Sh HISTORY 243The 244.Nm 245utility first appeared in 246.Fx 10.1 . 247.Sh AUTHORS 248The 249.Nm 250utility and manpage were written by Marcel Moolenaar <marcelm@juniper.net> 251