# When building mender 4.x with LZMA support, mender-updated no longer functions properly

**URL:** <https://hub.mender.io/t/when-building-mender-4-x-with-lzma-support-mender-updated-no-longer-functions-properly/7205>\
**Category:** General Discussions\
**Created:** [October 4, 2024, 3:48pm UTC](https://hub.mender.io/t/when-building-mender-4-x-with-lzma-support-mender-updated-no-longer-functions-properly/7205 "2024-10-04T15:48:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aduskett](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@aduskett](https://hub.mender.io/u/aduskett)\
**Post date:** [October 4, 2024, 3:48pm UTC](https://hub.mender.io/t/when-building-mender-4-x-with-lzma-support-mender-updated-no-longer-functions-properly/7205/1 "2024-10-04T15:48:26Z")

</div>

Hello;

I am currently in the process of converting the mender package in Buildroot from 3.x to 4.x, which is quite an extensive overhaul. As I near the end and prepare to submit a patch, I have ran into a rather nasty bug.

If the XZ package is selected, the following logic happens in the mender.mk file:

```auto
ifeq ($(BR2_PACKAGE_XZ),y)
MENDER_DEPENDENCIES += xz
MENDER_CONF_OPTS += -DMENDER_ARTIFACT_LZMA_COMPRESSION=ON
else
MENDER_CONF_OPTS += -DMENDER_ARTIFACT_LZMA_COMPRESSION=OFF
endif

```

However, this seems to break mender completely, as any run of mender-update provides the following output:

```auto
record_id=1 severity=info time="2024-Oct-04 15:22:29.911871" name="Global" msg="Installing the bootstrap Artifact" 
record_id=2 severity=error time="2024-Oct-04 15:22:29.912730" name="Global" msg="Failed to initialize the Archive handle: xz compression is not supported on this platform" 
record_id=3 severity=error time="2024-Oct-04 15:22:29.912822" name="Global" msg="Error reading the next tar entry: Error reading the tar stream: archive_read_next failed in LibArchive. Error code: -30 Error message: INTERNAL ERROR: Function 'archive_read_next_header' invoked with archive structure in state 'new', should be in state 'header/data'" 
Could not fulfill request: Parse error: Failed to install the bootstrap Artifact: Got unexpected token : 'Unrecognized' expected 'version'

```

Even when the `bootstrap.mender` and mender update files are not compressed using lzma.

```auto
  "${HOST_DIR}"/bin/mender-artifact write bootstrap-artifact \
    --compression zstd_best \
    --artifact-name "${ARTIFACT_NAME}" \
    --device-type "${DEVICE_TYPE}" \
    --provides "rootfs-image.version:${ARTIFACT_NAME}" \
    --provides "rootfs-image.checksum:${img_checksum}" \
    --clears-provides "rootfs-image.*" \
    --output-path "${BINARIES_DIR}"/"${bootstrap_artifact}" \
    --version 3

```

```auto
    echo "Creating ${BINARIES_DIR}/${DEVICE_TYPE}-${ARTIFACT_NAME}.mender"
    "${HOST_DIR}/bin/mender-artifact" \
        write rootfs-image \
        --compression zstd_best \
        -t "${DEVICE_TYPE}" \
        -n "${BR2_VERSION}" \
        -f "${BINARIES_DIR}/rootfs.ext2" \
        -o "${BINARIES_DIR}/${DEVICE_TYPE}-${ARTIFACT_NAME}.mender"

```

**NOTE: This above error also happens when --compression is set to lzma for both the bootstrap artifact and mender artifact!**

Other items of note: libarchive is built with lzma support

To replicate:  
**NOTE: The following commands require docker and qemu-system-x86\_64 installed on the host.**

Clone the buildroot-mender repository with the compression-testing branch:  
`git clone https://github.com/mendersoftware/buildroot-mender.git -b compression-testing`

Build a buildroot mender 4.x build suitable to run in a qemu environment:  
`cd buildroot-mender && EXIT_AFTER_BUILD=true make up`

Run the qemu environment:  
`sh buildroot-external-mender/board/x86_64/qemu-run.sh`

switch to serial0 `view -> serial0`  
login as root (no password)

run `mender-update show-provides`

All the logic to create the bootstrap and update artifacts are in `buildroot-external-mender/board/common/post-image-include`

Edit: To view the mender package logic, run the following commands in the buildroot-mender directory:

`make shell`  
`nano package/mender/mender.mk`

If you wish to build manually, after running `make shell`:  
`cd ~/buildroot/buildroot-external-mender/output/x86_64_mender/`  
`make -j$(nproc)`

- Patches to buildroot are in the `buildroot-external-mender/patches/buildroot` directory.
- The exact buildroot git hash is found in the `docker-compose.yaml` file

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![aduskett](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@aduskett](https://hub.mender.io/u/aduskett)\
**Post date:** [October 7, 2024, 10:27am UTC](https://hub.mender.io/t/when-building-mender-4-x-with-lzma-support-mender-updated-no-longer-functions-properly/7205/2 "2024-10-07T10:27:57Z")

</div>

It seems like the real issue is that mixed-compression methods do not work properly!  
If the bootstrap artifact is a different compression method than the update artifact, you receive the above error. Very strange!
