# Issues with dir-overlay Update Module rollback state

**URL:** <https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914>\
**Category:** General Discussions\
**Created:** [August 13, 2019, 8:40pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914 "2019-08-13T20:40:36Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![speeltronics](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@speeltronics](https://hub.mender.io/u/speeltronics)\
**Post date:** [August 13, 2019, 8:40pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/1 "2019-08-13T20:40:36Z")

</div>

The rollback state of this module doesn’t seem to be working correctly. This line “[[-f $prev\_files\_tar]]” always fails. This is a bash command not a shell command and since the dir-overlay module is using “#!/bin/sh” instead of “#!/bin/bash”, it does not work. Maybe it works on some machines, but I’m pretty sure this a built in bash command. Also, even when the rollback does execute, it copies all the backed up files to the root of the overlay and not where they were copied from, since all the files are copied to the tmp directory and tarred up without their original location. At least that’s what happened when I tried the rollback feature, unless I’m doing something wrong?

---

<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:** [August 13, 2019, 8:55pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/2 "2019-08-13T20:55:43Z")

</div>

Regarding the second problem you mention, this was recently fixed by @texierp.

> <https://github.com/mendersoftware/mender-update-modules/commit/66f58596b23dee9cd88d4ea3c8ad09ce941482d4>

Regarding the first issue, you are probably right that it is bashism. Please feel free to fix 🙂

---

<div class="post-metadata">

**Author:** ![speeltronics](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@speeltronics](https://hub.mender.io/u/speeltronics)\
**Post date:** [August 13, 2019, 10:32pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/3 "2019-08-13T22:32:01Z")

</div>

@texierp and @mirzak That gets the files where they need to go, but after it rolls back my root directory permission gets set to 700 and all the directories in the overlay get owned by root. So, I can’t even get into it unless I use the serial port. Any ideas why it would set the root directory permissions to 700? Or how to keep the current directory permisisons I tried using the -p flag on tar, but stil can’t get it to work…

---

<div class="post-metadata">

**Author:** ![texierp](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/texierp/32/45_2.png) [@texierp](https://hub.mender.io/u/texierp)\
**Post date:** [August 14, 2019, 7:10am UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/4 "2019-08-14T07:10:09Z")

</div>

@speeltronics, indeed you’re right.  
I’ve made a fix, can you try ?

> <https://github.com/texierp/mender-update-modules/commit/a78c221507307d34b94cece349911cc93823faa6>

There is also a fix for the bashism:

> <https://github.com/texierp/mender-update-modules/commit/3176c7251d4f6f2479d2a787ec7aa01e71901960>

Let me know if it is good for you 😉

---

<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:** [August 14, 2019, 12:18pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/5 "2019-08-14T12:18:29Z")

</div>

@texierp, feel free to submit a PR for " [module/dir-overlay: fix bashism in rollback state](https://github.com/texierp/mender-update-modules/commit/3176c7251d4f6f2479d2a787ec7aa01e71901960)"

A comment on " [module/dir-overlay: make sure permissions are preserved after a rollback](https://github.com/texierp/mender-update-modules/commit/a78c221507307d34b94cece349911cc93823faa6)", this change only fixes the permission of the root directory but not the underlying files.

What I suggest that we do is for the dir-overlay generator and installer to “preserve” owner ship and permissions of all files (it does not do this today but I think it should). Getting around the problem of `DEST_DIR` changing permissions is not possible in a “generic” way. The “workaround” is to make sure that `OVERLAY_TREE` permissions are the same as `DEST_DIR` on target, because this where how these permissions are transferred and that is why I want the module to “preserve” properties in the module and then it is up to the user to set them.

Then the example of generating sample files would look something like this,

```auto
# The permissions must match DEST_DIR on the target rootfs
sudo install -d -m 755 -g root -o root rootfs_overlay

# Create directory structure
sudo install -d -m 755 -g root -o root rootfs_overlay/etc
sudo install -d -m 755 -g root -o root rootfs_overlay/usr/bin
sudo install -d -m 755 -g root -o root rootfs_overlay/usr/share/app

# Create sample files
sudo touch rootfs_overlay/etc/app.conf
sudo touch rootfs_overlay/usr/bin/app
sudo touch rootfs_overlay/usr/share/app/data.txt

# You would typically chmod above files to have the appropriate mode in a production environment

```

I have a patch prepared for this, but I need to some more testing.

---

<div class="post-metadata">

**Author:** ![texierp](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/texierp/32/45_2.png) [@texierp](https://hub.mender.io/u/texierp)\
**Post date:** [August 14, 2019, 12:36pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/6 "2019-08-14T12:36:09Z")

</div>

> [@Directory Overlay](https://hub.mender.io/t/directory-overlay/529/13):
>
> @texierp, feel free to submit a PR for " [module/dir-overlay: fix bashism in rollback state](https://github.com/texierp/mender-update-modules/commit/3176c7251d4f6f2479d2a787ec7aa01e71901960)"

I will do.

> [@Directory Overlay](https://hub.mender.io/t/directory-overlay/529/13):
>
> this change only fixes the permission of the root directory but not the underlying files.

Sure, but during my quick test, it seems the problem only appears for the root directory (to be confirmed 😉 )

Thanks @mirzak for the feedback and the suggestion, I’m going to test it and investigate more.

---

<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:** [August 14, 2019, 12:37pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/7 "2019-08-14T12:37:40Z")

</div>

This is what I was thinking (still testing needed),

> <https://github.com/mirzak/mender-update-modules/commit/33499e672c935c14fe0563266f90d5041c74d468>

---

<div class="post-metadata">

**Author:** ![texierp](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/texierp/32/45_2.png) [@texierp](https://hub.mender.io/u/texierp)\
**Post date:** [August 14, 2019, 12:42pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/8 "2019-08-14T12:42:15Z")

</div>

@mirzak sure, but on my target

```auto
root@nitrogen8m:~# cp --parents
cp: unrecognized option '--parents'

```

that’s why I used tar in fact.

---

<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:** [August 14, 2019, 12:43pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/9 "2019-08-14T12:43:31Z")

</div>

Ah makes sense, it is probably not present in a busybox `cp`. I will revert that part 🙂

---

<div class="post-metadata">

**Author:** ![texierp](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/texierp/32/45_2.png) [@texierp](https://hub.mender.io/u/texierp)\
**Post date:** [August 14, 2019, 12:44pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/10 "2019-08-14T12:44:08Z")

</div>

> [@Directory Overlay](https://hub.mender.io/t/directory-overlay/529/17):
>
> Ah makes sense, it is probably not present in a busybox

Indeed you’re right 😉

---

<div class="post-metadata">

**Author:** ![speeltronics](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@speeltronics](https://hub.mender.io/u/speeltronics)\
**Post date:** [August 14, 2019, 7:48pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/11 "2019-08-14T19:48:33Z")

</div>

Confirmed that it only appears for the root directory for the install. The other directories follow the permissions and owners of what is set in for the overlay directory and if the overlay directory is not set to root it will also change the owner of the root directory. The permissions file does the trick for the root permissions. Thanks!

---

<div class="post-metadata">

**Author:** ![speeltronics](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@speeltronics](https://hub.mender.io/u/speeltronics)\
**Post date:** [August 14, 2019, 7:53pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/12 "2019-08-14T19:53:08Z")

</div>

This does work for the roll back using these changes with “cp --archive --parents {dest\_dir}/{file} ${backup\_dir}”. I could not get it to work correctly using the line “tar cf - $dest\_dir/$file | (cd $backup\_dir/ && tar xf -)”, it would change my user’s home directory to be owned by root on the roll back.

---

<div class="post-metadata">

**Author:** ![speeltronics](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@speeltronics](https://hub.mender.io/u/speeltronics)\
**Post date:** [August 14, 2019, 7:55pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/13 "2019-08-14T19:55:49Z")

</div>

One thing I did notice is if one of the files is set to 700 and owned by root then I had to call the generator as sudo and put the mender-artifact in the /sbin directory if I generated it as a user other than root.

---

<div class="post-metadata">

**Author:** ![texierp](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/texierp/32/45_2.png) [@texierp](https://hub.mender.io/u/texierp)\
**Post date:** [August 14, 2019, 9:16pm UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/14 "2019-08-14T21:16:30Z")

</div>

@speeltronics, great, thanks for reporting back.

---

<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:** [August 16, 2019, 8:09am UTC](https://hub.mender.io/t/issues-with-dir-overlay-update-module-rollback-state/914/15 "2019-08-16T08:09:28Z")

</div>

We have pushed a couple of [code changes](https://github.com/mendersoftware/mender-update-modules/pull/6) and update the [post](https://hub.mender.io/t/directory-overlay/529/9) with new instructions when creating the input directory.

Please give it a try now, and make sure to update both generator and module to get the latest changes.
