# Possible rootfs-version-check bug

**URL:** <https://hub.mender.io/t/possible-rootfs-version-check-bug/4561>\
**Category:** General Discussions\
**Created:** [February 1, 2022, 7:05pm UTC](https://hub.mender.io/t/possible-rootfs-version-check-bug/4561 "2022-02-01T19:05:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ckelloug2](https://avatars.discourse-cdn.com/v4/letter/c/c6cbf5/32.png) [@ckelloug2](https://hub.mender.io/u/ckelloug2)\
**Post date:** [February 1, 2022, 7:05pm UTC](https://hub.mender.io/t/possible-rootfs-version-check-bug/4561/1 "2022-02-01T19:05:02Z")

</div>

We’re using rootfs-version-check but we have problems with getting INCONSISTENT updates and rollbacks.

I’m looking at [https://raw.githubusercontent.com/mendersoftware/mender-update-modules/master/rootfs-version-check/module/rootfs-version-check](https://raw.githubusercontent.com/mendersoftware/mender-update-modules/master/rootfs-version-check/module/rootfs-version-check)

It appears that it forgets to set mender\_boot\_part\_hex to $passive\_num in ArtifactInstall and ArtifactRollback. Does anyone know if this is in fact a bug? I know drew wrote this script so I’m tagging him here: @drewmoseley

```auto
#!/bin/sh

set -ue

# Is expected to contain two variable definitions with device paths:
# - MENDER_ROOTFS_PART_A
# - MENDER_ROOTFS_PART_B
. /etc/mender/rootfs-version-check.conf

MENDER_ROOTFS_PART_A_NUMBER="$(echo "$MENDER_ROOTFS_PART_A" | egrep -o '[0-9]+$')"
MENDER_ROOTFS_PART_B_NUMBER="$(echo "$MENDER_ROOTFS_PART_B" | egrep -o '[0-9]+$')"

active_num="$(fw_printenv mender_boot_part)"
active_num="${active_num#mender_boot_part=}"
if test $active_num -eq $MENDER_ROOTFS_PART_A_NUMBER; then
    passive=$MENDER_ROOTFS_PART_B
    passive_num=$MENDER_ROOTFS_PART_B_NUMBER
else
    passive=$MENDER_ROOTFS_PART_A
    passive_num=$MENDER_ROOTFS_PART_A_NUMBER
fi

compare_versions_or_exit() {
    local COMPARE_VERSIONS="/usr/share/mender/utils/mender-compare-versions"

    if [! -x "${COMPARE_VERSIONS}"]; then
        echo "Unable to locate mender-compare-versions executable."
        exit 1
    fi
    # This script needs to be provided by the integrator and customized specifically for their naming scheme.
    if ! "${COMPARE_VERSIONS}" "$(cat header/artifact_name)" "$(cat current_artifact_name)"; then
        echo "Refusing to install $(cat header/artifact_name) over current version $(cat current_artifact_name)."
        exit 1
    fi

    echo "Allowing installation of $(cat header/artifact_name) over current version $(cat current_artifact_name)."
}

case "$1" in
    Download)
        compare_versions_or_exit
        file="$(cat stream-next)"
        cat "$file" > $passive
        if ["$(cat stream-next)" != ""]; then
            echo "More than one file in payload"
            exit 1
        fi
        ;;

    ArtifactInstall)
        fw_setenv -s - <<EOF
mender_boot_part $passive_num
upgrade_available 1
bootcount 0
EOF
        ;;

    PerformsFullUpdate)
        echo "Yes"
        ;;

    NeedsArtifactReboot)
        echo "Automatic"
        ;;

    SupportsRollback)
        echo "Yes"
        ;;

    ArtifactVerifyReboot)
        if test "$(fw_printenv upgrade_available)" != "upgrade_available=1"; then
            exit 1
        fi
        ;;

    ArtifactVerifyRollbackReboot)
        if test "$(fw_printenv upgrade_available)" = "upgrade_available=1"; then
            exit 1
        fi
        ;;

    ArtifactCommit)
        compare_versions_or_exit
        fw_setenv upgrade_available 0
        ;;

    ArtifactRollback)
        if test "$(fw_printenv upgrade_available)" = "upgrade_available=1"; then
            fw_setenv -s - <<EOF
mender_boot_part $passive_num
upgrade_available 0
EOF
        fi
        ;;
esac
exit 0

```

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [February 2, 2022, 1:46am UTC](https://hub.mender.io/t/possible-rootfs-version-check-bug/4561/2 "2022-02-02T01:46:37Z")

</div>

Wow. Yes, that does seem like a miss in this script. Do you have a reliable enough reproduction scenario where you can modify the script, test and submit a PR?

cc @Alan @lramirez

Drew

---

<div class="post-metadata">

**Author:** ![ckelloug2](https://avatars.discourse-cdn.com/v4/letter/c/c6cbf5/32.png) [@ckelloug2](https://hub.mender.io/u/ckelloug2)\
**Post date:** [February 2, 2022, 2:25am UTC](https://hub.mender.io/t/possible-rootfs-version-check-bug/4561/3 "2022-02-02T02:25:50Z")

</div>

I’ve currently got a fix in ArtifactInstall\_Leave\_99 that uses uboot’s uEnv.txt file to reset mender\_boot\_part\_hex to be mender\_boot\_part. I could potentially remove that fix and then fix the rootfs\_version\_check script and see what goes wrong. This fix has worked for successful upgrades but I get INCONSISTENT on my devices when there is a rollback.

Setting mender\_boot\_part\_hex to mender\_boot\_part will work on devices like the Technexion pico-pi imx6ull that we’re using but it may be a problem on devices with enough partitions to have mender\_boot\_part\_hex be different than mender\_boot\_part

I think I can test the script and submit a PR

---

<div class="post-metadata">

**Author:** ![ckelloug2](https://avatars.discourse-cdn.com/v4/letter/c/c6cbf5/32.png) [@ckelloug2](https://hub.mender.io/u/ckelloug2)\
**Post date:** [February 2, 2022, 10:10pm UTC](https://hub.mender.io/t/possible-rootfs-version-check-bug/4561/4 "2022-02-02T22:10:13Z")

</div>

I tested the fixed script in our baseline and got no INCONSISTENT errors where I would have expected them. I’ve put in a PR to the original repository. [https://github.com/mendersoftware/mender-update-modules/pull/20](https://github.com/mendersoftware/mender-update-modules/pull/20)
