# Which compression algorithm to choose in mkinitcpio.conf?

**URL:** <https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457>\
**Category:** General system\
**Created:** [December 16, 2020, 7:03pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457 "2020-12-16T19:03:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pebcak](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pebcak/32/100472_2.png) [@pebcak](https://forum.endeavouros.com/u/pebcak)\
**Post date:** [December 16, 2020, 7:03pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/1 "2020-12-16T19:03:28Z")

</div>

I wonder if I should use lzop or lz4 instead of the default gzip?

```auto
# COMPRESSION
# Use this to compress the initramfs image. By default, gzip compression
# is used. Use 'cat' to create an uncompressed image.
#COMPRESSION="gzip"
#COMPRESSION="bzip2"
#COMPRESSION="lzma"
#COMPRESSION="xz"
#COMPRESSION="lzop"
#COMPRESSION="lz4"

```

Which one would you recommend? My system is installed on BTRFS if that would make any difference.

---

<div class="post-metadata">

**Author:** ![ricklinux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ricklinux/32/110798_2.png) [@ricklinux](https://forum.endeavouros.com/u/ricklinux)\
**Post date:** [December 16, 2020, 7:07pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/2 "2020-12-16T19:07:10Z")

</div>

I think @2000 has zstd on Btrfs

---

<div class="post-metadata">

**Author:** ![pebcak](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pebcak/32/100472_2.png) [@pebcak](https://forum.endeavouros.com/u/pebcak)\
**Post date:** [December 16, 2020, 7:15pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/3 "2020-12-16T19:15:52Z")

</div>

I was also advised by @2000 to add `compress=zstd` to the options in fstab:

`ID=1a1b20eb-6fb5-46fc-9666-3b0e6f4c4300 / btrfs subvol=@,defaults,noatime,space_cache,autodefrag,compress=zstd 0 0`

But those in `mkinitcpio.conf`, aren’t those for compressing the kernels put in /boot?

---

<div class="post-metadata">

**Author:** ![ricklinux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ricklinux/32/110798_2.png) [@ricklinux](https://forum.endeavouros.com/u/ricklinux)\
**Post date:** [December 16, 2020, 7:19pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/4 "2020-12-16T19:19:36Z")

</div>

I don’t know about it really. I just used his copy & paste method. Maybe it can or can’t be used? 🤔

---

<div class="post-metadata">

**Author:** ![pebcak](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pebcak/32/100472_2.png) [@pebcak](https://forum.endeavouros.com/u/pebcak)\
**Post date:** [December 16, 2020, 7:23pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/5 "2020-12-16T19:23:27Z")

</div>

Don’t know. `zstd` is not among those options in mkinitcpio.conf. Maybe it can be added to it. I really don’t know. I read a little bit about lzof and lz4. They seem to be a bit faster in compressing but the images produced are slightly larger in size…

---

<div class="post-metadata">

**Author:** ![ricklinux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/ricklinux/32/110798_2.png) [@ricklinux](https://forum.endeavouros.com/u/ricklinux)\
**Post date:** [December 16, 2020, 7:25pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/6 "2020-12-16T19:25:09Z")

</div>

Ya maybe it’s not an Arch option for that or some other reason. I don’t really know. 🙃

---

<div class="post-metadata">

**Author:** ![2000](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/2/ee59a6/32.png) [@2000](https://forum.endeavouros.com/u/2000)\
**Post date:** [December 16, 2020, 7:54pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/7 "2020-12-16T19:54:54Z")

</div>

`zstd` compressed initramfs is only supported by Linux 5.9 and newer.

Your `/etc/mkinitcpo.conf` should include the option `#COMPRESSION="zstd"`. You probably didn’t check those .pacnew files if not 😉 .

---

<div class="post-metadata">

**Author:** ![pebcak](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pebcak/32/100472_2.png) [@pebcak](https://forum.endeavouros.com/u/pebcak)\
**Post date:** [December 16, 2020, 8:01pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/8 "2020-12-16T20:01:07Z")

</div>

> [@2000](#):
>
> You probably didn’t check those .pacnew files if not 😉 .

You are right! Shame on me!  
🤦🏾‍♂️

How about the other two, lzop and lz4 when it comes to speed and cpu usage? Or you think zstd is the best option overall?

---

<div class="post-metadata">

**Author:** ![anon72019930](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/f07891/32.png) [@anon72019930](https://forum.endeavouros.com/u/anon72019930)\
**Post date:** [December 16, 2020, 8:04pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/9 "2020-12-16T20:04:50Z")

</div>

yeah, i chose `zstd` when merging my mkinitcpio.conf and the .pacnew. But i’m not sure what is “the best” option. The speed depends on the CPU and number of cores as far as i remember… there is a another thread where this got discussed.

---

<div class="post-metadata">

**Author:** ![pebcak](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pebcak/32/100472_2.png) [@pebcak](https://forum.endeavouros.com/u/pebcak)\
**Post date:** [December 16, 2020, 8:10pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/10 "2020-12-16T20:10:03Z")

</div>

Thanks for the reply!  
I will change the compression to zstd.  
I will look around the forum and see if I find that thread.

---

<div class="post-metadata">

**Author:** ![pebcak](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pebcak/32/100472_2.png) [@pebcak](https://forum.endeavouros.com/u/pebcak)\
**Post date:** [December 16, 2020, 11:08pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/11 "2020-12-16T23:08:33Z")

</div>

Just an off-topic question:

Will `arch-chroot` from a live medium works as usual even though / is on a subvolume?

---

<div class="post-metadata">

**Author:** ![2000](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/2/ee59a6/32.png) [@2000](https://forum.endeavouros.com/u/2000)\
**Post date:** [December 17, 2020, 8:07am UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/12 "2020-12-17T08:07:28Z")

</div>

> [@pebcak](#):
>
> Will `arch-chroot` from a live medium works as usual even though / is on a subvolume?

As long as you mount the subvolume @, yes.

1. Boot into the live environment
2. In case your device is encrypted, decrypt and mount your luks partition (e. g. /dev/sda2); otherwise leave out the decryption part and use /dev/sda2 instead of /dev/mapper/crypt:

```auto
sudo cryptsetup luksOpen /dev/sda2 crypt &&
sudo mount -o compress=zstd,subvol=@ /dev/mapper/crypt /mnt
 

```

1. Only on UEFI systems: Mount your EFI boot folder (e. g. /dev/sda1)

```auto
sudo mount /dev/sda1 /mnt/boot/efi

```

1. `chroot` into your system

```auto
sudo arch-chroot /mnt

```

1. Do some _root_ stuff …

---

<div class="post-metadata">

**Author:** ![pebcak](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pebcak/32/100472_2.png) [@pebcak](https://forum.endeavouros.com/u/pebcak)\
**Post date:** [December 17, 2020, 8:26am UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/13 "2020-12-17T08:26:49Z")

</div>

Thank you so much for your answer! I appreciate it!

Have a great day!  
🌞

---

<div class="post-metadata">

**Author:** ![mbod](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/mbod/32/16833_2.png) [@mbod](https://forum.endeavouros.com/u/mbod)\
**Post date:** [December 17, 2020, 9:14am UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/14 "2020-12-17T09:14:21Z")

</div>

> [@pebcak](#):
>
> Which one would you recommend?

It doesnt matter. And I honestly do not know why there are so many choices. This is just over complicating things. I stick with “xz”.

---

<div class="post-metadata">

**Author:** ![anon31687413](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@anon31687413](https://forum.endeavouros.com/u/anon31687413)\
**Post date:** [December 17, 2020, 5:36pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/15 "2020-12-17T17:36:29Z")

</div>

> [@mbod](#):
>
> And I honestly do not know why there are so many choices.

Because it’s Linux, which is all about choice.

But you’re not wrong, bzip2 and lzma are superseded by faster algos with better compression ratio. Gzip, xz, lz4 and zstd are valid and useful alternatives.

That said, XZ in my opinion only makes sense if you want to squeeze out a few KB/MB of free space. It’s rather slow both in compression and in decompression.

---

<div class="post-metadata">

**Author:** ![pebcak](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pebcak/32/100472_2.png) [@pebcak](https://forum.endeavouros.com/u/pebcak)\
**Post date:** [December 17, 2020, 5:46pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/16 "2020-12-17T17:46:03Z")

</div>

In terms of speed and/or CPU usage how would you rate the algorithm that you have mentioned above if space is not a concern.

---

<div class="post-metadata">

**Author:** ![anon31687413](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@anon31687413](https://forum.endeavouros.com/u/anon31687413)\
**Post date:** [December 17, 2020, 5:50pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/17 "2020-12-17T17:50:29Z")

</div>

lz4 or zstd. Depends on the exact options and of course your hardware.  
I use `zstd -15` as a good compromise.  
Somewhere I have a little script that logs total and cpu time, and file size for zstd and xz, might post it some day (I don’t have it on this computer).

(and there’s always “uncompressed” but I’m not sure if it’s really faster than e.g. lz4)

---

<div class="post-metadata">

**Author:** ![pebcak](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pebcak/32/100472_2.png) [@pebcak](https://forum.endeavouros.com/u/pebcak)\
**Post date:** [December 17, 2020, 6:15pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/18 "2020-12-17T18:15:32Z")

</div>

> [@anon31687413](#):
>
> z4 or zstd. Depends on the exact options and of course your hardware.

Thanks for the reply and explanation!  
This machine got a AMD Ryzen 7 4800U. So if I were to use `zstd -15`, where do I need to make the change?

I know that I need to read up on these stuff and perhaps at the end of the day the difference is in order of some hundreds of a second but it is just nice to know that you can speed up things a bit when possible.

> [@anon31687413](#):
>
> Somewhere I have a little script that logs total and cpu time, and file size for zstd and xz, might post it some day (I don’t have it on this computer).

That would be nice!

---

<div class="post-metadata">

**Author:** ![anon31687413](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@anon31687413](https://forum.endeavouros.com/u/anon31687413)\
**Post date:** [December 17, 2020, 6:23pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/19 "2020-12-17T18:23:04Z")

</div>

> [@pebcak](#):
>
> where do I need to make the change?

To use a specific compression algorithm simply uncomment it in mkinitcpio.conf (and comment all the others).

For options, see `COMPRESSION_OPTIONS` array.  
**Important** : Do not use the above as I think it applies to **all** compression algos.  
From manpage:

> This option is generally not used. It can be potentially dangerous and may cause invalid images to be generated **without any sign of an error**.

If you’re adventurous, you can modify `/usr/bin/mkinitcpio` like I already described [here](https://forum.endeavouros.com/t/warning-when-updating-mkinitcpio-29-1/9350/19). I don’t support or endorse this 🙂

---

<div class="post-metadata">

**Author:** ![pebcak](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pebcak/32/100472_2.png) [@pebcak](https://forum.endeavouros.com/u/pebcak)\
**Post date:** [December 17, 2020, 6:26pm UTC](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457/20 "2020-12-17T18:26:29Z")

</div>

Great!

> [@anon31687413](#):
>
> If you’re adventurous, you can modify `/usr/bin/mkinitcpio` like I already described [here](https://forum.endeavouros.com/t/warning-when-updating-mkinitcpio-29-1/9350/19).

This sounds very tempting now! I’ll have a look!

> [@anon31687413](#):
>
> I don’t support or endorse this

No problem! See my username? 😅

[Next page](https://forum.endeavouros.com/t/which-compression-algorithm-to-choose-in-mkinitcpio-conf/10457.md?page=2)
