# Rootfs update module - keep existing file from active partition in new partition

**URL:** <https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465>\
**Category:** General Discussions\
**Tags:** debian, raspberrypi-cm3\
**Created:** [September 21, 2020, 3:33pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465 "2020-09-21T15:33:54Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![PFGO](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@PFGO](https://hub.mender.io/u/PFGO)\
**Post date:** [September 21, 2020, 3:33pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/1 "2020-09-21T15:33:54Z")

</div>

Hello community,

what’s the best way to keep a persistent file, which is stored in the home path, after a rootfs update?

I want to keep an existing configuration file from an active partition and move it to the new active partition? What’s the best way without using a separate persistent partition?

Thank you in advance  
cheers,  
PFGO

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [September 21, 2020, 3:41pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/2 "2020-09-21T15:41:02Z")

</div>

I am not sure if I understand the question.  
But you have to move all the persistent data to `/data` which is persistent data partition so that they don’t get overwritten after an update

---

<div class="post-metadata">

**Author:** ![PFGO](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@PFGO](https://hub.mender.io/u/PFGO)\
**Post date:** [September 21, 2020, 3:42pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/3 "2020-09-21T15:42:50Z")

</div>

> [@thesillywhat](#):
>
> But you have to move all the persistent data to `/data` which is persistent data partition so that the don’t get overwritten after an update

Ok but where should I define it? in the update-module?

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [September 21, 2020, 3:51pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/4 "2020-09-21T15:51:32Z")

</div>

I think this [link](https://docs.mender.io/system-updates-debian-family/convert-a-mender-debian-image/state-scripts) should answer your question.

You might have to create a state script.

---

<div class="post-metadata">

**Author:** ![PFGO](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@PFGO](https://hub.mender.io/u/PFGO)\
**Post date:** [September 21, 2020, 3:56pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/5 "2020-09-21T15:56:18Z")

</div>

Sorry but I don’t really understand it.

So should I create an own update module, which copies the persistent file from the active partition to the persistent data partition and after the upgrade process, it should copy the file from the persistent data partition, back to the new active partition?

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [September 21, 2020, 4:00pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/6 "2020-09-21T16:00:57Z")

</div>

Can you be a little more specific about what configuration you are trying to keep persistent between updates? Maybe share some examples/outputs for me to help you out?

---

<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:** [September 21, 2020, 4:21pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/7 "2020-09-21T16:21:22Z")

</div>

@PFGO this simplest approach is to simply put the config file somewhere in /data and then use a symlink in the home path if you need it there. This will work transparently with a full rootfs update since the newly installed image will also have the symlink pointing into the data partition.

If that does not work then you can use [state scripts](https://docs.mender.io/overview/state-script) to implement this. You could, for instance us a DownloadEnter script to backup the existing copy and then an ArtifactCommit\_Enter script to restore it just before committing the update.

Drew

---

<div class="post-metadata">

**Author:** ![PFGO](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@PFGO](https://hub.mender.io/u/PFGO)\
**Post date:** [September 21, 2020, 4:39pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/8 "2020-09-21T16:39:46Z")

</div>

@drewmoseley thank you for the answer.

Is the state “DownloadEnter” also called when I use mender standalone deployment?

---

<div class="post-metadata">

**Author:** ![PFGO](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@PFGO](https://hub.mender.io/u/PFGO)\
**Post date:** [September 21, 2020, 4:50pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/9 "2020-09-21T16:50:56Z")

</div>

@thesillywhat I think drewmoseley gave me the correct answer for this. I will try to implement it with the state scripts.

In short summary:  
I’ve a node-red instance running on the device and there is a persistent context file, which stores some variables for the node-red application. I need to keep those variables after the upgrade process. But the context file is not always present, only in some cases. So I think it’s the best way to use a shell script to check if the file exists before the upgrade and then copy it back to the correct path.

Otherwise I should have to think on a complete new design for the system. To use the /data partition for all persistent files. Which seems to be the correct way for me. But it would require a huge change in the system, and needs to be tested for a lot of days. And for now I don’t have time to do it. But for a correct system design, it should be done in the near future.

Thank you

---

<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:** [September 21, 2020, 9:41pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/10 "2020-09-21T21:41:38Z")

</div>

No the DownloadEnter only works when running in managed mode. When running in standalone mode, you need to have some other scripting that detects an update is available and launches Mender so presumably you can back the file up there when you detect an update but before calling Mender.

Drew

---

<div class="post-metadata">

**Author:** ![PFGO](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@PFGO](https://hub.mender.io/u/PFGO)\
**Post date:** [September 22, 2020, 7:48am UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/11 "2020-09-22T07:48:48Z")

</div>

Ok thank you for the answers! Great community - thumbs up.

I will focus on the correct way, and migrate the configuration files to the persistent `/data` partition.

By the way is there an overview, which shows what states are supported by which mode (standalone/managed)?

---

<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:** [September 22, 2020, 1:45pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/12 "2020-09-22T13:45:44Z")

</div>

Looks like I was wrong; Download is executed in standalone mode. See [https://docs.mender.io/artifact-creation/state-scripts#standalone-mode](https://docs.mender.io/artifact-creation/state-scripts#standalone-mode)

Drew

---

<div class="post-metadata">

**Author:** ![PFGO](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@PFGO](https://hub.mender.io/u/PFGO)\
**Post date:** [September 24, 2020, 8:00am UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/13 "2020-09-24T08:00:41Z")

</div>

OK I tried it but I get the following Error:

```
--script /home/username/build/mender-convert/state-scripts/Download_Enter_00
	scripter: unsupported script state: Download

```

**Edit:**  
Ok, I’ve found following information in the code:

> <https://github.com/mendersoftware/mender-artifact/blob/master/artifact/scripter.go>

```
var availableScriptType = map[string]bool{
	// Idle, Sync and Download scripts are part of rootfs and can not
	// be a part of the artifact itself; Leaving below for refference...
	//"Idle": true,
	//"Sync": true,
	//"Download": true,
	"ArtifactInstall": true,
	"ArtifactReboot": true,
	"ArtifactCommit": true,
	"ArtifactRollback": true,
	"ArtifactRollbackReboot": true,
	"ArtifactFailure": true,
}

```

And also I’ve found the information in the documentation for version 2.3:  
[https://docs.mender.io/2.3/artifacts/state-scripts#root-file-system-and-artifact-scripts](https://docs.mender.io/2.3/artifacts/state-scripts#root-file-system-and-artifact-scripts)

And it also has been answered here:

> [@Some State Scripts cannot be called](https://hub.mender.io/t/some-state-scripts-cannot-be-called/2048/2):
>
> Not all scripts should be in /etc/mender/scripts, please see the following section in the docs for more information [https://docs.mender.io/2.3/artifacts/state-scripts#root-file-system-and-artifact-scripts](https://docs.mender.io/2.3/artifacts/state-scripts#root-file-system-and-artifact-scripts)

Just for information 🙂

---

<div class="post-metadata">

**Author:** ![hacpa](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hacpa](https://hub.mender.io/u/hacpa)\
**Post date:** [September 29, 2020, 3:26pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/14 "2020-09-29T15:26:46Z")

</div>

There are some examples here: [https://github.com/mendersoftware/mender/tree/master/examples/state-scripts](https://github.com/mendersoftware/mender/tree/master/examples/state-scripts)

Personally, I did something like this, but put my state script in the artifact, under the state ArtifactInstall\_Enter. It made more sense to me that the new rootfs that is being installed knows what it wants to keep from the old one. If you use Download\_Enter or Download\_Leave, the state script lives in the ORIGINAL rootfs, NOT in the artifact. So this means that the current rootfs decides to write stuff to the new rootfs, which didn’t make sense in my use case.

---

<div class="post-metadata">

**Author:** ![PFGO](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@PFGO](https://hub.mender.io/u/PFGO)\
**Post date:** [September 30, 2020, 3:33pm UTC](https://hub.mender.io/t/rootfs-update-module-keep-existing-file-from-active-partition-in-new-partition/2465/15 "2020-09-30T15:33:54Z")

</div>

Hello @hacapa,

thank you I also ended up in using the script in the `ArtifactInstall_Enter` state.

The state scripts are very great! Thank you for the help 🙂

cheers,  
PFGO
