xz-utils

From Gentoo Wiki
Jump to:navigation Jump to:search

xz is an LZMA2-based data compression utility. Typically, files compressed with LZMA2 compression are 30% smaller than equivalent gzip files and 15% smaller than equivalent bzip2 files.

Installation

Emerge

The app-arch/xz-utils package provides utilities for mangling xz-compressed files:

root #emerge --ask app-arch/xz-utils

Usage

xz has multiple compression levels available. The default is -6. The normal highest level is -9.

If the user is willing to accept more memory usage and time to compress, --extreme (-e) can be used with a numerical level to increase the intensity, e.g. xz -9e.

In future, xz may be able to decompress lzip files too, as they share the same format (LZMA) [1] [2].

Parallelization

All modern versions of xz can compress in parallel, but only >=app-arch/xz-utils-5.3.3_alpha can decompress in parallel. Archives must be compressed using the parallel compressor (which will become the default in 5.3.3_alpha too) for parallel decompression.

Until a stable release of xz-utils (5.3.3) containing parallel decompression is made, app-arch/pixz can be used for parallel decompression but only with archives made using pixz.

As a result of some tools using pixz opportunistically, simply installing pixz can be useful even without configuration.

Configuration

xz can be configured via environment variables: XZ_DEFAULTS is intended for system administration, while XZ_OPT is intended for scripts to set defaults.

Create the following file:

FILE /etc/env.d/99xz
# -T0: compress and decompress with the number of cores available
# -9: use maximum compression level (but not extreme)
XZ_DEFAULTS="-9 -T0"

Then run:

root #env-update && . /etc/profile

Portage

To use xz for Portage compression of both installed files and binary packages:

FILE /etc/portage/make.conf
PORTAGE_COMPRESS="xz"
BINPKG_COMPRESS="xz"

Dracut

Warning
The kernel must be compiled with support for xz compression!

To use xz for Dracut's compression of initramfs:

FILE /etc/dracut.conf.d/compression.conf
compress="xz"

systemd

systemd has a Meson configuration option default-compression to allow choosing the preferred default compression algorithm.

To use xz:

FILE /etc/portage/env/sys-apps/systemd
MYMESONARGS="-Ddefault-compression=xz"

Ensure that USE=lzma is enabled on sys-apps/systemd.

Removal

Unmerge

root #emerge --ask --depclean --verbose app-arch/xz-utils

See also

  • lha
  • lzip
  • p7zip — a command-line port of 7-Zip for POSIX compliant systems such as Unix, OS X, BeOS, and Amiga.
  • tar — an archiver tool that provides the ability to create tar archives, as well as various other kinds of manipulation.
  • unrar
  • zip — provides classic zip compression.

References

  1. Michał Górny. Lzip decompression support for xz-utils, Michał Górny blog, February 10th, 2021. Retrieved on September 29th, 2022.
  2. Jia Tan. [xz-devel] XZ Utils 5.3.3alpha, xz-devel mailing list, 27th September, 2022. Retrieved on September 29th, 2022.