# Mender switch root fs partitions?

**URL:** <https://hub.mender.io/t/mender-switch-root-fs-partitions/1479>\
**Category:** General Discussions\
**Created:** [January 29, 2020, 1:20am UTC](https://hub.mender.io/t/mender-switch-root-fs-partitions/1479 "2020-01-29T01:20:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikkysleepy](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/ikkysleepy/32/156_2.png) [@ikkysleepy](https://hub.mender.io/u/ikkysleepy)\
**Post date:** [January 29, 2020, 1:20am UTC](https://hub.mender.io/t/mender-switch-root-fs-partitions/1479/1 "2020-01-29T01:20:39Z")

</div>

Once you update to an image, can you easily switch back to that partition and if so, will the next update just overwrite that other partition that you switched from?

I see the rollback but looks like this is only if things are broken during the update, is that correct? Looks like if I try to update and I reboot it does not boot to the new partition, so I can’t verify things are working on the new partition unless I commit but if I commit and reboot I can’t roll back. I am looking for a way to go back to the previous partition even if the image did install correctly on the partition and the user switched to it.

Thanks,  
– Jorge

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [January 29, 2020, 7:52am UTC](https://hub.mender.io/t/mender-switch-root-fs-partitions/1479/2 "2020-01-29T07:52:00Z")

</div>

assuming your using uboot as your bootloader, on the device you can use fw-utils to change the uboot environment to switch between the active partitions from the operating system. Make sure you change both variables together and then reboot.

To make partition 1 the active partition:

fw\_setenv mender\_boot\_part 1  
fw\_setenv mender\_boot\_part\_hex 1

To make partition 2 the active partition:

fw\_setenv mender\_boot\_part 2  
fw\_setenv mender\_boot\_part\_hex 2

[https://developer.toradex.com/knowledge-base/u-boot-fw-utils](https://developer.toradex.com/knowledge-base/u-boot-fw-utils)

We manufacture our products with a gpio pin connected to a physical button that allows the customer to roll back to the previous partition if they are not happy for some reason with the new update.

You can also change these variables from within a uboot session before you boot the operating system.

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [January 29, 2020, 8:41am UTC](https://hub.mender.io/t/mender-switch-root-fs-partitions/1479/3 "2020-01-29T08:41:46Z")

</div>

Do also keep in mind that there is no guarantees made by the Mender client that the “previous” partition actually contains something that will boot once you have run `mender -commit`.

E.g the Mender client could have started a deployment and aborted for someone reason, and then you would have something incomplete on the old partition and forcing a rollback in this case would result in a bricked device.

So you need to make sure that you always have something valid on the “old partition”, which can be done by hooking in the Mender state-machine and making sure to restore “old partition” in some chosen states.

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [January 29, 2020, 8:59am UTC](https://hub.mender.io/t/mender-switch-root-fs-partitions/1479/4 "2020-01-29T08:59:53Z")

</div>

yes, that’s an good point to remember. I should of stated in my reply, that our physical button and gpio pin code is is included in the boot-loader code to avoid ever having a bricked device caused by a mender os update.

---

<div class="post-metadata">

**Author:** ![ikkysleepy](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/ikkysleepy/32/156_2.png) [@ikkysleepy](https://hub.mender.io/u/ikkysleepy)\
**Post date:** [January 30, 2020, 4:27am UTC](https://hub.mender.io/t/mender-switch-root-fs-partitions/1479/5 "2020-01-30T04:27:55Z")

</div>

> [@dellgreen](#):
>
> fw-utils

So you can only change this via uboot menu on bootup or via physical button? I was just wondering if this was easy for a non-techie or not so sounds like the answer is no, which is fine. I have an internal website to update firmware and wanted to see if there was an easy way to switch partitions.

Thanks,  
– Jorge

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [January 30, 2020, 10:01am UTC](https://hub.mender.io/t/mender-switch-root-fs-partitions/1479/6 "2020-01-30T10:01:50Z")

</div>

when you boot your device, if using uboot and is configured to allow you to enter a shell then you can usually hit the keyboard to drop into a uboot shell where there are commands to be able to manipulate all manner of things. However this is usually just for development/testing. To make permanent changes alterations one would add C code to uboot with the extra functionality you require or get uboot to load in scripts from memory. Either way its not non-techie. 🙂

Making the changes from the operating system as already mention is simple, but as @mirzak pointed out you need to be careful.

---

<div class="post-metadata">

**Author:** ![gschmott](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@gschmott](https://hub.mender.io/u/gschmott)\
**Post date:** [February 11, 2022, 3:15pm UTC](https://hub.mender.io/t/mender-switch-root-fs-partitions/1479/7 "2022-02-11T15:15:47Z")

</div>

As @dellgreen mention, it’s possible to force Mender to boot the “old” partition by explicitly changing U-Boot’s environment, specifically:

> To make partition 1 the active partition:
> 
> fw\_setenv mender\_boot\_part 1  
> fw\_setenv mender\_boot\_part\_hex 1
> 
> To make partition 2 the active partition:
> 
> fw\_setenv mender\_boot\_part 2  
> fw\_setenv mender\_boot\_part\_hex 2

As @mirzak pointed out you better be sure the “old” partition can boot or you may have bricked your device. I wonder if there is an alternate solution available. If you set the _mender\_boot\_part_ and _mender\_boot\_part\_hex_ and also set _upgrade\_available=1_ doesn’t this prevent the bricking scenario? On a subsequent reboot (and failure to boot the “old” partition) shouldn’t U-boot fallback to the original partition to boot? It’s almost like doing an installation (to the “old” partition) that fails and the normal boot-count recovery mechanisms in U-Boot returns you to the original partition. I have tested this and it seems to work. Am I missing something that could be leaving Mender in an inconstistent state? I suspect if it boots successfully back into the “old” partition you’ll have to do a “mender commit” to make the change permanent and clear the “upgrade\_available” flag.
