From 329eba697b086386f191e11836fc709e821fdb2a Mon Sep 17 00:00:00 2001 From: Mirza Krak Date: Tue, 14 Aug 2018 13:54:49 +0200 Subject: [PATCH] Fall-back to environment and conf in active part probe There are situations where it nearly impossible to find the active root-filesystem based on probing mounted devices. One example is this: /dev/root on /rom type squashfs (ro,relatime) There is no information about the actual device device used in above example. One additional probe step could be parsing /proc/cmdline to find the "root=" argument but this is essentially the same as looking at "mender_boot_part" environment variable. Hence we add a fall-back to only using the "mender_boot_part" environment variable and comparing that to what we have in "mender.conf" if we are not able to match against mounted devices. Changelog: Fix active partition detection when using non-native filesystems. Signed-off-by: Mirza Krak (cherry picked from commit dfa22977a474424105ed8f04475b5c119b3b3b76) --- partitions.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/partitions.go b/partitions.go index db67a3032..5aba1d222 100644 --- a/partitions.go +++ b/partitions.go @@ -191,6 +191,20 @@ func (p *partitions) getAndCacheActivePartition(rootChecker func(StatCommander, activePartition, err := getRootFromMountedDevices(p, rootChecker, mountedDevices, rootDevice) if err != nil { + // If we reach this point, we have not been able to find a match + // based on mounted device. + // + // Fall-back to configuration and environment only! + if checkBootEnvAndRootPartitionMatch(bootEnvBootPart, p.rootfsPartA) { + p.active = p.rootfsPartA + log.Debug("Setting active partition from configuration and environment: ", p.active) + return p.active, nil + } + if checkBootEnvAndRootPartitionMatch(bootEnvBootPart, p.rootfsPartB) { + p.active = p.rootfsPartB + log.Debug("Setting active partition from configuration and environment: ", p.active) + return p.active, nil + } return "", err } if checkBootEnvAndRootPartitionMatch(bootEnvBootPart, activePartition) {