18f8cb840SMaxim Sobolev.\"- 28f8cb840SMaxim Sobolev.\" Copyright (c) 2004-2016 Maxim Sobolev <sobomax@FreeBSD.org> 38f8cb840SMaxim Sobolev.\" All rights reserved. 48f8cb840SMaxim Sobolev.\" 58f8cb840SMaxim Sobolev.\" Redistribution and use in source and binary forms, with or without 68f8cb840SMaxim Sobolev.\" modification, are permitted provided that the following conditions 78f8cb840SMaxim Sobolev.\" are met: 88f8cb840SMaxim Sobolev.\" 1. Redistributions of source code must retain the above copyright 98f8cb840SMaxim Sobolev.\" notice, this list of conditions and the following disclaimer. 108f8cb840SMaxim Sobolev.\" 2. Redistributions in binary form must reproduce the above copyright 118f8cb840SMaxim Sobolev.\" notice, this list of conditions and the following disclaimer in the 128f8cb840SMaxim Sobolev.\" documentation and/or other materials provided with the distribution. 138f8cb840SMaxim Sobolev.\" 148f8cb840SMaxim Sobolev.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 158f8cb840SMaxim Sobolev.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 168f8cb840SMaxim Sobolev.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 178f8cb840SMaxim Sobolev.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 188f8cb840SMaxim Sobolev.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 198f8cb840SMaxim Sobolev.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 208f8cb840SMaxim Sobolev.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 218f8cb840SMaxim Sobolev.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 228f8cb840SMaxim Sobolev.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 238f8cb840SMaxim Sobolev.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 248f8cb840SMaxim Sobolev.\" SUCH DAMAGE. 257f4caa8cSMaxim Sobolev.\" 26eefd8f96SConrad Meyer.Dd August 9, 2019 27cf7b3b65SRuslan Ermilov.Dt MKUZIP 8 287f4caa8cSMaxim Sobolev.Os 297f4caa8cSMaxim Sobolev.Sh NAME 307f4caa8cSMaxim Sobolev.Nm mkuzip 3142ecdf05SMaxim Sobolev.Nd compress disk image for use with 327f4caa8cSMaxim Sobolev.Xr geom_uzip 4 3342ecdf05SMaxim Sobolevclass 347f4caa8cSMaxim Sobolev.Sh SYNOPSIS 357f4caa8cSMaxim Sobolev.Nm 36eefd8f96SConrad Meyer.Op Fl dSsvZ 37eefd8f96SConrad Meyer.Op Fl A Ar compression_algorithm 38eefd8f96SConrad Meyer.Op Fl C Ar compression_level 3990ce2410SKonstantin Belousov.Op Fl j Ar compression_jobs 407f4caa8cSMaxim Sobolev.Op Fl o Ar outfile 417f4caa8cSMaxim Sobolev.Op Fl s Ar cluster_size 427f4caa8cSMaxim Sobolev.Ar infile 437f4caa8cSMaxim Sobolev.Sh DESCRIPTION 447f4caa8cSMaxim SobolevThe 457f4caa8cSMaxim Sobolev.Nm 46d3ff2972SMaxim Sobolevutility compresses a disk image file so that the 477f4caa8cSMaxim Sobolev.Xr geom_uzip 4 48d3ff2972SMaxim Sobolevclass will be able to decompress the resulting image at run-time. 49d3ff2972SMaxim SobolevThis allows for a significant reduction of size of disk image at 5042ecdf05SMaxim Sobolevthe expense of some CPU time required to decompress the data each 51cf7b3b65SRuslan Ermilovtime it is read. 52cb29445aSRuslan ErmilovThe 53d3ff2972SMaxim Sobolev.Nm 54cb29445aSRuslan Ermilovutility 55d3ff2972SMaxim Sobolevworks in two phases: 567f4caa8cSMaxim Sobolev.Bl -enum 577f4caa8cSMaxim Sobolev.It 587f4caa8cSMaxim SobolevAn 597f4caa8cSMaxim Sobolev.Ar infile 60eefd8f96SConrad Meyerimage is split into clusters; each cluster is compressed. 617f4caa8cSMaxim Sobolev.It 62eefd8f96SConrad MeyerThe resulting set of compressed clusters is written to the output file. 63eefd8f96SConrad MeyerIn addition, a 64eefd8f96SConrad Meyer.Dq table of contents 65eefd8f96SConrad Meyerheader is written which allows for efficient seeking. 667f4caa8cSMaxim Sobolev.El 677f4caa8cSMaxim Sobolev.Pp 687f4caa8cSMaxim SobolevThe options are: 69cf7b3b65SRuslan Ermilov.Bl -tag -width indent 70eefd8f96SConrad Meyer.It Fl A Op Ar lzma | Ar zlib | Ar zstd 71eefd8f96SConrad MeyerSelect a specific compression algorithm. 72eefd8f96SConrad MeyerIf this option is not provided, the default is 73eefd8f96SConrad Meyer.Ar zlib . 74eefd8f96SConrad Meyer.Pp 75eefd8f96SConrad MeyerThe 76eefd8f96SConrad Meyer.Ar lzma 77eefd8f96SConrad Meyeralgorithm provides noticeable better compression levels than zlib on the same 78eefd8f96SConrad Meyerdata set. 79eefd8f96SConrad MeyerIt has vastly slower compression speed and moderately slower decompression 80eefd8f96SConrad Meyerspeed. 81eefd8f96SConrad Meyer.Pp 82eefd8f96SConrad MeyerThe 83eefd8f96SConrad Meyer.Ar zstd 84eefd8f96SConrad Meyeralgorithm provides better compression levels than zlib on the same data set. 85eefd8f96SConrad MeyerIt also has faster compression and decompression speed than zlib. 86eefd8f96SConrad MeyerIn the very high compression 87eefd8f96SConrad Meyer.Dq level 88eefd8f96SConrad Meyersettings, it does not offer quite as high a compression ratio as 89eefd8f96SConrad Meyer.Ar lzma . 90eefd8f96SConrad MeyerHowever, its decompression speed does not suffer at high compression 91eefd8f96SConrad Meyer.Dq levels . 92eefd8f96SConrad Meyer.It Fl C Ar compression_level 93eefd8f96SConrad MeyerSelect the integer compression level used to parameterize the chosen 94eefd8f96SConrad Meyercompression algorithm. 95eefd8f96SConrad Meyer.Pp 96eefd8f96SConrad MeyerFor any given algorithm, a lesser number selects a faster compression mode. 97eefd8f96SConrad MeyerA greater number selects a slower compression mode. 98eefd8f96SConrad MeyerTypically, for the same algorithm, a greater 99eefd8f96SConrad Meyer.Ar compression_level 100eefd8f96SConrad Meyerprovides better final compression ratio. 101eefd8f96SConrad Meyer.Pp 102eefd8f96SConrad MeyerFor 103eefd8f96SConrad Meyer.Ar lzma , 104eefd8f96SConrad Meyerthe range of valid compression levels is 105eefd8f96SConrad Meyer.Va 0-9 . 106eefd8f96SConrad MeyerThe 107eefd8f96SConrad Meyer.Nm 108eefd8f96SConrad Meyerdefault for lzma is 109eefd8f96SConrad Meyer.Va 6 . 110eefd8f96SConrad Meyer.Pp 111eefd8f96SConrad MeyerFor 112eefd8f96SConrad Meyer.Ar zlib , 113eefd8f96SConrad Meyerthe range of valid compression levels is 114eefd8f96SConrad Meyer.Va 1-9 . 115eefd8f96SConrad MeyerThe 116eefd8f96SConrad Meyer.Nm 117eefd8f96SConrad Meyerdefault for zlib is 118eefd8f96SConrad Meyer.Va 9 . 119eefd8f96SConrad Meyer.Pp 120eefd8f96SConrad MeyerFor 121eefd8f96SConrad Meyer.Ar zstd , 122eefd8f96SConrad Meyerthe range of valid compression levels is currently 123eefd8f96SConrad Meyer.Va 1-19 . 124eefd8f96SConrad MeyerThe 125eefd8f96SConrad Meyer.Nm 126eefd8f96SConrad Meyerdefault for zstd is 127eefd8f96SConrad Meyer.Va 9 . 128eefd8f96SConrad Meyer.It Fl d 129eefd8f96SConrad MeyerEnable de-duplication. 130eefd8f96SConrad MeyerWhen the option is enabled 131eefd8f96SConrad Meyer.Nm 132eefd8f96SConrad Meyerdetects identical blocks in the input and replaces each subsequent occurrence 133eefd8f96SConrad Meyerof such block with pointer to the very first one in the output. 134eefd8f96SConrad MeyerSetting this option results is moderate decrease of compressed image size, 135eefd8f96SConrad Meyertypically around 3-5% of a final size of the compressed image. 13690ce2410SKonstantin Belousov.It Fl j Ar compression_jobs 13790ce2410SKonstantin BelousovSpecify the number of compression jobs that 13890ce2410SKonstantin Belousov.Nm 13990ce2410SKonstantin Belousovruns in parallel to speed up compression. 14090ce2410SKonstantin BelousovWhen option is not specified the number of jobs set to be equal 14190ce2410SKonstantin Belousovto the value of 14290ce2410SKonstantin Belousov.Va hw.ncpu 14390ce2410SKonstantin Belousov.Xr sysctl 8 14490ce2410SKonstantin Belousovvariable. 145eefd8f96SConrad Meyer.It Op Fl L 146eefd8f96SConrad MeyerLegacy flag that indicates the same thing as 147eefd8f96SConrad Meyer.Dq Fl A Ar lzma . 1487f4caa8cSMaxim Sobolev.It Fl o Ar outfile 149d3ff2972SMaxim SobolevName of the output file 1507f4caa8cSMaxim Sobolev.Ar outfile . 1517f4caa8cSMaxim SobolevThe default is to use the input name with the suffix 1528f8cb840SMaxim Sobolev.Pa .uzip 1538f8cb840SMaxim Sobolevfor the 1548f8cb840SMaxim Sobolev.Xr zlib 3 1558f8cb840SMaxim Sobolevcompression or 1568f8cb840SMaxim Sobolev.Pa .ulzma 1578f8cb840SMaxim Sobolevfor the 1588f8cb840SMaxim Sobolev.Xr lzma 3 . 15990ce2410SKonstantin Belousov.It Fl S 16090ce2410SKonstantin BelousovPrint summary about the compression ratio as well as output 16190ce2410SKonstantin Belousovfile size after file has been processed. 1627f4caa8cSMaxim Sobolev.It Fl s Ar cluster_size 163d3ff2972SMaxim SobolevSplit the image into clusters of 1647f4caa8cSMaxim Sobolev.Ar cluster_size 165d3ff2972SMaxim Sobolevbytes, 16384 bytes by default. 166cf7b3b65SRuslan ErmilovThe 1677f4caa8cSMaxim Sobolev.Ar cluster_size 168cf7b3b65SRuslan Ermilovshould be a multiple of 512 bytes. 1697f4caa8cSMaxim Sobolev.It Fl v 1707f4caa8cSMaxim SobolevDisplay verbose messages. 1718f8cb840SMaxim Sobolev.It Fl Z 172eefd8f96SConrad MeyerDisable zero-block detection and elimination. 173eefd8f96SConrad MeyerWhen this option is set, 1748f8cb840SMaxim Sobolev.Nm 175eefd8f96SConrad Meyercompresses blocks of zero bytes just as it would any other block. 176eefd8f96SConrad MeyerWhen the option is not set, 1778f8cb840SMaxim Sobolev.Nm 178eefd8f96SConrad Meyerdetects and compresses zero blocks in a space-efficient way. 1798f8cb840SMaxim SobolevSetting 1808f8cb840SMaxim Sobolev.Fl Z 181eefd8f96SConrad Meyerincreases compressed image sizes slightly, typically less than 0.1%. 1827f4caa8cSMaxim Sobolev.El 183eefd8f96SConrad Meyer.Sh IMPLEMENTATION NOTES 184eefd8f96SConrad MeyerThe compression ratio largely depends on the compression algorithm, level, and 185eefd8f96SConrad Meyercluster size used. 186eefd8f96SConrad MeyerFor large cluster sizes (16kB and higher), typical overall image compression 187eefd8f96SConrad Meyerratios with 188eefd8f96SConrad Meyer.Xr zlib 3 189d3ff2972SMaxim Sobolevare only 1-2% less than those achieved with 190eefd8f96SConrad Meyer.Xr gzip 1 191eefd8f96SConrad Meyerover the entire image. 192eefd8f96SConrad MeyerHowever, it should be kept in mind that larger cluster sizes lead to higher 193eefd8f96SConrad Meyeroverhead in the 1947f4caa8cSMaxim Sobolev.Xr geom_uzip 4 1957f4caa8cSMaxim Sobolevclass, as the class has to decompress the whole cluster even if 196d3ff2972SMaxim Sobolevonly a few bytes from that cluster have to be read. 19742ecdf05SMaxim Sobolev.Pp 198eefd8f96SConrad MeyerAdditionally, the threshold at 16-32 kB where a larger cluster size does not 199eefd8f96SConrad Meyerbenefit overall compression ratio is an artifact of the 200eefd8f96SConrad Meyer.Xr zlib 3 201eefd8f96SConrad Meyeralgorithm in particular. 202eefd8f96SConrad Meyer.Ar Lzma 203eefd8f96SConrad Meyerand 204eefd8f96SConrad Meyer.Ar Zstd will continue to provide better compression ratios as cluster sizes 205eefd8f96SConrad Meyerare increased, at high enough compression levels. 206eefd8f96SConrad MeyerThe same tradeoff continues to apply: reads in 207eefd8f96SConrad Meyer.Xr geom_uzip 4 208eefd8f96SConrad Meyerbecome more expensive the greater the cluster size. 209eefd8f96SConrad Meyer.Pp 2108f8cb840SMaxim SobolevThe de-duplication is a 2118f8cb840SMaxim Sobolev.Fx 2128f8cb840SMaxim Sobolevspecific feature and while it does not require any changes to on-disk 2138f8cb840SMaxim Sobolevcompressed image format, however it did require some matching changes to the 2148f8cb840SMaxim Sobolev.Xr geom_uzip 4 2158f8cb840SMaxim Sobolevto handle resulting images correctly. 216eefd8f96SConrad Meyer.Pp 217eefd8f96SConrad MeyerTo make use of 218eefd8f96SConrad Meyer.Ar zstd 219eefd8f96SConrad Meyer.Nm 220eefd8f96SConrad Meyerimages, the kernel must be configured with 221eefd8f96SConrad Meyer.Cd ZSTDIO . 222eefd8f96SConrad MeyerIt is enabled by default in many 223eefd8f96SConrad Meyer.Cd GENERIC 224eefd8f96SConrad Meyerkernels provided as binary distributions by 225eefd8f96SConrad Meyer.Fx . 226eefd8f96SConrad MeyerThe status on any particular system can be verified by checking 227eefd8f96SConrad Meyer.Xr sysctl 8 228eefd8f96SConrad Meyer.Dv kern.features.geom_uzip_zstd 229eefd8f96SConrad Meyerfor 230eefd8f96SConrad Meyer.Dq 1 . 2316c7216dfSRuslan Ermilov.Sh EXIT STATUS 2326c7216dfSRuslan Ermilov.Ex -std 233*525a177cSRobert Wing.Sh EXAMPLES 234*525a177cSRobert Wing.Pp 235*525a177cSRobert WingThe following describes how to create and mount a uzip image. 236*525a177cSRobert Wing.Pp 237*525a177cSRobert WingCreate a file system image: 238*525a177cSRobert Wing.Bd -literal -offset indent 239*525a177cSRobert Wingmakefs /src.img /usr/src 240*525a177cSRobert Wing.Ed 241*525a177cSRobert Wing.Pp 242*525a177cSRobert WingCreate the uzip image, the output file will be named src.img.uzip: 243*525a177cSRobert Wing.Bd -literal -offset indent 244*525a177cSRobert Wingmkuzip /src.img 245*525a177cSRobert Wing.Ed 246*525a177cSRobert Wing.Pp 247*525a177cSRobert WingEnsure geom_uzip is loaded: 248*525a177cSRobert Wing.Bd -literal -offset indent 249*525a177cSRobert Wingkldload geom_uzip 250*525a177cSRobert Wing.Ed 251*525a177cSRobert Wing.Pp 252*525a177cSRobert WingCreate an MD device backed by the uzip image: 253*525a177cSRobert Wing.Bd -literal -offset indent 254*525a177cSRobert Wingmdconfig -f /src.img.uzip 255*525a177cSRobert Wing.Ed 256*525a177cSRobert Wing.Pp 257*525a177cSRobert WingMount the uzip image: 258*525a177cSRobert Wing.Bd -literal -offset indent 259*525a177cSRobert Wingmount -o ro /dev/md0.uzip /mnt 260*525a177cSRobert Wing.Ed 2617f4caa8cSMaxim Sobolev.Sh SEE ALSO 2627f4caa8cSMaxim Sobolev.Xr gzip 1 , 2638f8cb840SMaxim Sobolev.Xr xz 1 , 264eefd8f96SConrad Meyer.Xr zstd 1 , 265b7dd44ebSBaptiste Daroussin.Xr zlib 3 , 26642ecdf05SMaxim Sobolev.Xr geom 4 , 267cf7b3b65SRuslan Ermilov.Xr geom_uzip 4 , 26842ecdf05SMaxim Sobolev.Xr md 4 , 26942ecdf05SMaxim Sobolev.Xr mdconfig 8 , 270cf7b3b65SRuslan Ermilov.Xr mount_cd9660 8 2717f4caa8cSMaxim Sobolev.Sh AUTHORS 2722b7af31cSBaptiste Daroussin.An Maxim Sobolev Aq Mt sobomax@FreeBSD.org 273