Skip to content

Commit

Permalink
resin_update_state_probe: ignore RAID members when looking for root
Browse files Browse the repository at this point in the history
At this moment resin_update_state_probe looks for the root partition
by UUID and assumes that only a single device is returned. This
assumption breaks when the root is on a MD RAID1 device as not only
the virtual MD device holds a filesystem with the given UUID,
each member does as well.

This patch makes resin_update_state_probe ignore devices
that are RAID members which in that case will only return
the MD device as expected.

Change-type: patch
Signed-off-by: Michal Toman <michalt@balena.io>
  • Loading branch information
mtoman committed Feb 29, 2024
1 parent 7f676ac commit e984b21
Showing 1 changed file with 19 additions and 1 deletion.
Expand Up @@ -50,7 +50,25 @@ else
ruuid=$(get_cmdline_root_uuid)
fi
# Determine if the partition is on the same drive as root
rpdev=$(lsblk -nlo pkname,uuid | grep "${ruuid}" | cut -d " " -f1) || true
rpdev=""

# Look for the filesystem by UUID
# lsblk returns multiple entries when the root is on RAID1
# (the virtual MD device and each of the members).
# Loop through the candidates and ignore RAID members.
# This will also randomly choose the first device that matches the UUID
# if multiple devices with the same filesystem UUID are connected
# (e.g. a cloned drive).
for cand in $(lsblk -nlo pkname,uuid | grep "${ruuid}" | cut -d " " -f1); do
cand_fstype=$(lsblk "/dev/${cand}" -ndlo fstype) || true
if [ "${cand_fstype}" = "linux_raid_member" ]; then
continue
fi

rpdev="${cand}"
break
done

if [ -n "${rpdev}" ]; then
rptype=$(lsblk -nlo type,uuid | grep "${ruuid}" | cut -d " " -f1) || true
if [ "${rptype}" = "crypt" ]; then
Expand Down

0 comments on commit e984b21

Please sign in to comment.