# Directory

**URL:** <https://hub.mender.io/t/directory/325>\
**Category:** Update Modules\
**Created:** [March 12, 2019, 8:53am UTC](https://hub.mender.io/t/directory/325 "2019-03-12T08:53:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![lluiscampos](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/lluiscampos/32/112_2.png) [@lluiscampos](https://hub.mender.io/u/lluiscampos)\
**Post date:** [March 12, 2019, 8:53am UTC](https://hub.mender.io/t/directory/325/1 "2019-03-12T08:53:46Z")

</div>

### Description

The Directory Update Module installs a user defined file tree structure (files and subfolders) into a given destination directory on the device.

Before deploying to the destination folder on the device, the Update Module will take a backup copy of the current contents. This allows to restore it with the rollback mechanism of the Mender client if something goes wrong.

Example use-cases:

- Updating an application which resides in a standalone directory on the device

### Specification

| | |
| --- | --- |
| Module name | directory |
| Supports rollback | yes |
| Requires restart | no |
| Artifact generation script | yes |
| Full operating system updater | no |
| Source code | [Update Module](https://github.com/mendersoftware/mender/blob/master/support/modules/directory), [Artifact Generator](https://github.com/mendersoftware/mender/blob/master/support/modules-artifact-gen/directory-artifact-gen) |
| Maintainer | Community |

**Please be aware that Mender Update modules are meant to update parts of the operating system and if not configured properly they could potentially delete parts or the complete operating system. Always inspect the code carefully and only test modules on a devices that you can recover easily.**

**It is not recommended to install a Mender Artifact on your workstation**

## Prepare the device

This section describes how to setup your target device, i.e. the device to be updated. This will also be referred to as the device environment.

All commands outlined in this section should be run in the device environment.

### Prerequisites

This Update Module has the following prerequisites for the device environment:

- [Install the Mender client](https://docs.mender.io/client-installation/install-with-debian-package), version 2.0 or later

### Install the Update Module

Download the latest version of this Update Module by running:

```bash
mkdir -p /usr/share/mender/modules/v3 && wget -N -P /usr/share/mender/modules/v3 https://raw.githubusercontent.com/mendersoftware/mender/master/support/modules/directory

```

## Prepare the development environment on your workstation

This section describes how to set up your development environment on your workstation.

All commands outlined in this section should be run in the development environment.

### Prerequisites

This Update Modules has the following prerequisites for the development environment:

- [Install mender-artifact](https://docs.mender.io/downloads), version 3.1.0 or later

### Create Mender Artifacts

For convenience, an Artifact generator tool `directory-artifact-gen` is provided with the Update Module. This tool will generate [Mender Artifacts](https://docs.mender.io/overview/artifact) in the same format that the Update Module expects them.

Download `directory-artifact-gen`, by running the following command:

```bash
wget https://raw.githubusercontent.com/mendersoftware/mender/master/support/modules-artifact-gen/directory-artifact-gen

```

Make it executable:

```bash
chmod +x directory-artifact-gen

```

Create example content to deploy:

```bash
mkdir dir-to-deploy
echo "File created by Mender directory Update Module!" > dir-to-deploy/file1.txt
echo "File created by Mender directory Update Module!" > dir-to-deploy/file2.txt

```

Now generate a Mender Artifact using the following command:

```bash
ARTIFACT_NAME="my-update-1.0"
DEVICE_TYPE="my-device-type"
OUTPUT_PATH="my-update-1.0.mender"
DEST_DIR="/opt/installed-by-directory/"
FILE_TREE="dir-to-deploy"
./directory-artifact-gen -n ${ARTIFACT_NAME} -t ${DEVICE_TYPE} -d ${DEST_DIR} -o ${OUTPUT_PATH} ${FILE_TREE}

```

- `ARTIFACT_NAME` - The name of the Mender Artifact
- `DEVICE_TYPE` - The compatible device type of this Mender Artifact
- `OUTPUT_PATH` - The path where to place the output Mender Artifact. This should always have a `.mender` suffix
- `DEST_DIR` - The path on target device where content of `FILE_TREE` will be installed.
- `FILE_TREE` - The path to a folder containing the contents to be sent to the device in the update.

You can either deploy this Artifact in managed mode with the Mender server (upload it under Releases in the server UI) or by using the Mender client only in [Standalone deployments](https://docs.mender.io/artifact-creation/standalone-deployment).

### Artifact technical details

The Mender Artifact used by this Update Module has two payload files: a tarball containing all the files to be deployed and a regular file with the `DEST_DIR` in plain text.

The Mender Artifact contents will look like:

```bash
Updates:
    0:
    Type: directory
    Provides: Nothing
    Depends: Nothing
    Metadata: Nothing
    Files:
        name: update.tar
        size: 17571840
        modified: 2019-03-05 15:20:42 +0100 CET
        checksum: dab0a292a8c2a089eb0a22e56082e51fcfa5485264b66063a4f9798db919af23
    Files:
        name: dest_dir
        size: 12
        modified: 2019-03-05 15:20:42 +0100 CET
        checksum: 5dfbbf0a8baa51888494fa5fe1665cc5b2826419f9ec6d90a92eeabd54a0f574

```

---

<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:** [March 3, 2020, 1:10pm UTC](https://hub.mender.io/t/directory/325/2 "2020-03-03T13:10:39Z")

</div>

4 posts were split to a new topic: [ARTIFACT\_NAME when using Update Modules](https://hub.mender.io/t/artifact-name-when-using-update-modules/1596)

---

<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:** [September 26, 2019, 8:34am UTC](https://hub.mender.io/t/directory/325/6 "2019-09-26T08:34:05Z")

</div>

26 posts were split to a new topic: [Issue with key verification using Directory Update Module](https://hub.mender.io/t/issue-with-key-verification-using-directory-update-module/1074)

---

<div class="post-metadata">

**Author:** ![ramu](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@ramu](https://hub.mender.io/u/ramu)\
**Post date:** [June 4, 2019, 10:24am UTC](https://hub.mender.io/t/directory/325/8 "2019-06-04T10:24:10Z")

</div>

Hi @kacf,  
Please let me know the usage example for **directory-artifact-gen**? I have tried few but failed to create the signed artifact for docker…  
Unable to understand where to specify the {DOCKER\_IMAGES} and what is --dest-dir , directory options for it?

~/new-workspace/mender/docker-updatemodule/directory-artifact-gen --artifact-name {ARTIFACT\_NAME} --device-type {DEVICE\_TYPE} --dest-dir ~/new-workspace/mender/docker-images/ --output-path {OUTPUT\_PATH} directory {DOCKER\_IMAGES} – -k …/artifact-keys/private.key  
File tree already specified. Unrecognized argument “debian@sha256:84e2351ae76c072adac3b6e0a958e5b238e693bdff3cc4f3c94eace3d4577f76”

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [June 4, 2019, 10:43am UTC](https://hub.mender.io/t/directory/325/9 "2019-06-04T10:43:02Z")

</div>

You cannot use the `directory-artifact-gen` for generating docker artifacts. For that you need to use the [`docker-artifact-gen` from 2.0.x](https://raw.githubusercontent.com/mendersoftware/mender/2.0.x/support/modules-artifact-gen/docker-artifact-gen).

---

<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:** [September 26, 2019, 8:32am UTC](https://hub.mender.io/t/directory/325/34 "2019-09-26T08:32:21Z")

</div>

14 posts were split to a new topic: [Issues with rollback using Directory Update Module](https://hub.mender.io/t/issues-with-rollback-using-directory-update-module/1073)

---

<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:** [April 21, 2020, 6:31am UTC](https://hub.mender.io/t/directory/325/35 "2020-04-21T06:31:32Z")

</div>

A post was split to a new topic: [Getting a “no artifact” message from Mender Server when deploying directory update](https://hub.mender.io/t/getting-a-no-artifact-message-from-mender-server-when-deploying-directory-update/1806)

---

<div class="post-metadata">

**Author:** ![kd-krishna](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kd-krishna/32/510_2.png) [@kd-krishna](https://hub.mender.io/u/kd-krishna)\
**Post date:** [February 11, 2020, 5:32pm UTC](https://hub.mender.io/t/directory/325/36 "2020-02-11T17:32:53Z")

</div>

Great tutorial.  
Just wondering how do we handle updating a directory with executables running? does mender provide a handler to stop the execution before going ahead with the update? Thanks.

---

<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:** [February 11, 2020, 5:49pm UTC](https://hub.mender.io/t/directory/325/37 "2020-02-11T17:49:47Z")

</div>

Nothing specific since it’s going to be very dependent on the system design. The existing update module could be easily updated to handle that for your specifics though.

---

<div class="post-metadata">

**Author:** ![JoZerByte](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@JoZerByte](https://hub.mender.io/u/JoZerByte)\
**Post date:** [February 19, 2020, 12:04am UTC](https://hub.mender.io/t/directory/325/38 "2020-02-19T00:04:53Z")

</div>

Is there a way to force a device restart after the artifact gets installed?

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [February 19, 2020, 7:13am UTC](https://hub.mender.io/t/directory/325/39 "2020-02-19T07:13:04Z")

</div>

Fork and make your own version of the `directory` Update Module, and implement the `ArtifactReboot` state, where you should print `Automatic` and `exit 0`. This will reboot every time the Update Module installs anything.

You can also add more advanced logic and consider printing `No` in some cases, if you want to make it conditional.

---

<div class="post-metadata">

**Author:** ![kd-krishna](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kd-krishna/32/510_2.png) [@kd-krishna](https://hub.mender.io/u/kd-krishna)\
**Post date:** [February 21, 2020, 8:53pm UTC](https://hub.mender.io/t/directory/325/40 "2020-02-21T20:53:07Z")

</div>

@drewmoseley thanks for that. Is it possible to update multiple folders at different locations in the target device? Thanks.

---

<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:** [February 21, 2020, 9:30pm UTC](https://hub.mender.io/t/directory/325/41 "2020-02-21T21:30:31Z")

</div>

Not with this update module. You can do that with a custom module.

---

<div class="post-metadata">

**Author:** ![ajithpv](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/ajithpv/32/728_2.png) [@ajithpv](https://hub.mender.io/u/ajithpv)\
**Post date:** [February 25, 2020, 6:52am UTC](https://hub.mender.io/t/directory/325/42 "2020-02-25T06:52:48Z")

</div>

Are you looking for something like [this](https://hub.mender.io/t/directory-overlay/529)?

---

<div class="post-metadata">

**Author:** ![zainmehdi](https://avatars.discourse-cdn.com/v4/letter/z/ce7236/32.png) [@zainmehdi](https://hub.mender.io/u/zainmehdi)\
**Post date:** [April 10, 2020, 1:33am UTC](https://hub.mender.io/t/directory/325/43 "2020-04-10T01:33:27Z")

</div>

Hi, I was wondering if there is any way to update the directory without deleting unwanted items. For instance I am updating a directory that contains all the executables along with the user data. I want to update the exes but I dont want any user data to be removed. I created a mender artifact with only exes but its deleting any user data previously on that directory as well. Would be thankful for any feed. Thanks

---

<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:** [April 10, 2020, 3:13pm UTC](https://hub.mender.io/t/directory/325/44 "2020-04-10T15:13:20Z")

</div>

You may want to look at the [Directory Overlay module.](https://hub.mender.io/t/directory-overlay/529)

---

<div class="post-metadata">

**Author:** ![zainmehdi](https://avatars.discourse-cdn.com/v4/letter/z/ce7236/32.png) [@zainmehdi](https://hub.mender.io/u/zainmehdi)\
**Post date:** [April 20, 2020, 6:24am UTC](https://hub.mender.io/t/directory/325/45 "2020-04-20T06:24:43Z")

</div>

Hi @drewmoseley. I tried Mender Directory Overlay module. My Mender Client version is 2.2 and mender-artifact I am using is 3.1.1. When trying to deploy the artifact I am getting this error

" Artifact Payload type ‘dir-overlay’ is not supported by this Mender Client"

According the the example provided it is supposed to be working with these version but I am somehow failing to do so. Can you please provide some insight

PS: I am not trying to overlay rootfs. I am trying it with for a custom directory in the home folder.

Thanks

---

<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:** [April 20, 2020, 1:29pm UTC](https://hub.mender.io/t/directory/325/46 "2020-04-20T13:29:07Z")

</div>

It sounds like you don’t have the update module itself installed on the client. To do that manually, run the following:

`mkdir -p /usr/share/mender/modules/v3 && wget -P /usr/share/mender/modules/v3 https://raw.githubusercontent.com/mendersoftware/mender-update-modules/master/dir-overlay/module/dir-overlay && chmod +x /usr/share/mender/modules/v3/dir-overlay`

---

<div class="post-metadata">

**Author:** ![zainmehdi](https://avatars.discourse-cdn.com/v4/letter/z/ce7236/32.png) [@zainmehdi](https://hub.mender.io/u/zainmehdi)\
**Post date:** [April 20, 2020, 11:09pm UTC](https://hub.mender.io/t/directory/325/47 "2020-04-20T23:09:36Z")

</div>

Thanks it worked.

---

<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 15, 2020, 2:27pm UTC](https://hub.mender.io/t/directory/325/48 "2020-09-15T14:27:08Z")

</div>

Hello,

Can I use the same directory update module to create new directories in persistent data section(/data)?

[Next page](https://hub.mender.io/t/directory/325.md?page=2)
