<a id="storage-dir"></a>

# Directory - `dir`


            <p class="youtube_link">
              <a href="https://www.youtube.com/watch?v=imWkPM9GjCY" target="_blank">
                <span title="Directory storage and LXD" class="play_icon">▶</span>
                <span title="Directory storage and LXD">Watch on YouTube</span>
              </a>
            </p>
        
The directory storage driver is a basic backend that stores its data in a standard file and directory structure.
This driver is quick to set up and allows inspecting the files directly on the disk, which can be convenient for testing.
However, LXD operations are [not optimized](https://canonical.com/lxd/docs/latest/reference/storage_drivers/index.html.md#storage-drivers-features) for this driver.

## `dir` driver in LXD

The `dir` driver in LXD is fully functional and provides the same set of features as other drivers.
However, it is much slower than all the other drivers because it must unpack images and do instant copies of instances, snapshots and images.

Unless specified differently during creation (with the `source` configuration option), the data is stored in the `/var/snap/lxd/common/lxd/storage-pools/` (for snap installations) or `/var/lib/lxd/storage-pools/` directory.

<a id="storage-dir-quotas"></a>

### Quotas

<!-- Include start dir quotas -->

The `dir` driver supports storage quotas when running on either ext4 or XFS with project quotas enabled at the file system level.

<!-- Include end dir quotas -->

## Configuration options

The following configuration options are available for storage pools that use the `dir` driver and for storage volumes in these pools.

### Storage pool configuration

<!-- Include content from [../metadata.txt](../metadata.txt) -->

<a id="storage-dir-pool-conf:rsync.bwlimit"></a>
`rsync.bwlimit`

Upper limit on the socket I/O for `rsync`

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-pool-conf:rsync.bwlimit)

| **Key:**     | `rsync.bwlimit`   |
|--------------|-------------------|
| **Type:**    | string            |
| **Default:** | `0` (no limit)    |
| **Scope:**   | global            |

When `rsync` must be used to transfer storage entities, this option specifies the upper limit
to be placed on the socket I/O.

<a id="storage-dir-pool-conf:rsync.compression"></a>
`rsync.compression`

Whether to use compression while migrating storage pools

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-pool-conf:rsync.compression)

| **Key:**     | `rsync.compression`   |
|--------------|-----------------------|
| **Type:**    | bool                  |
| **Default:** | `true`                |
| **Scope:**   | global                |

<a id="storage-dir-pool-conf:source"></a>
`source`

Path to an existing directory

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-pool-conf:source)

| **Key:**    | `source`   |
|-------------|------------|
| **Type:**   | string     |
| **Scope:**  | local      |

<a id="storage-dir-pool-conf:source.recover"></a>
`source.recover`

Whether to recover an existing `source`

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-pool-conf:source.recover)

| **Key:**     | `source.recover`   |
|--------------|--------------------|
| **Type:**    | bool               |
| **Default:** | `false`            |
| **Scope:**   | local              |

Set this option to true to recover an existing source which was previously created by LXD.

<a id="storage-dir-pool-conf:user.*"></a>
`user.*`

User-provided free-form key/value pairs

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-pool-conf:user.*)

| **Key:**    | `user.*`   |
|-------------|------------|
| **Type:**   | string     |
| **Scope:**  | global     |

#### TIP
In addition to these configurations, you can also set default values for the storage volume configurations. See storage-configure-vol-default.

### Storage volume configuration

<!-- Include content from [../metadata.txt](../metadata.txt) -->

<a id="storage-dir-volume-conf:security.shared"></a>
`security.shared`

Enable volume sharing

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:security.shared)

| **Key:**       | `security.shared`                           |
|----------------|---------------------------------------------|
| **Type:**      | bool                                        |
| **Default:**   | same as `volume.security.shared` or `false` |
| **Condition:** | virtual-machine or custom block volume      |
| **Scope:**     | global                                      |

Enable this option to allow the volume to be shared across multiple instances despite the possibility of data loss.

<a id="storage-dir-volume-conf:security.shifted"></a>
`security.shifted`

Enable ID shifting overlay

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:security.shifted)

| **Key:**       | `security.shifted`                           |
|----------------|----------------------------------------------|
| **Type:**      | bool                                         |
| **Default:**   | same as `volume.security.shifted` or `false` |
| **Condition:** | custom volume                                |
| **Scope:**     | global                                       |

Enable this option to allow the volume to be attached to multiple isolated instances.

<a id="storage-dir-volume-conf:security.unmapped"></a>
`security.unmapped`

Disable ID mapping for the volume

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:security.unmapped)

| **Key:**       | `security.unmapped`                           |
|----------------|-----------------------------------------------|
| **Type:**      | bool                                          |
| **Default:**   | same as `volume.security.unmapped` or `false` |
| **Condition:** | custom volume                                 |
| **Scope:**     | global                                        |

<a id="storage-dir-volume-conf:size"></a>
`size`

Size/quota of the storage volume

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:size)

| **Key:**       | `size`                |
|----------------|-----------------------|
| **Type:**      | string                |
| **Default:**   | same as `volume.size` |
| **Condition:** | appropriate driver    |
| **Scope:**     | global                |

<a id="storage-dir-volume-conf:snapshots.expiry"></a>
`snapshots.expiry`

Time until snapshots are deleted

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:snapshots.expiry)

| **Key:**       | `snapshots.expiry`                |
|----------------|-----------------------------------|
| **Type:**      | string                            |
| **Default:**   | same as `volume.snapshots.expiry` |
| **Condition:** | custom volume                     |
| **Scope:**     | global                            |

Specify an expression like `1M 2H 3d 4w 5m 6y`.

<a id="storage-dir-volume-conf:snapshots.pattern"></a>
`snapshots.pattern`

Template for the snapshot name

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:snapshots.pattern)

| **Key:**       | `snapshots.pattern`                            |
|----------------|------------------------------------------------|
| **Type:**      | string                                         |
| **Default:**   | same as `volume.snapshots.pattern` or `snap%d` |
| **Condition:** | custom volume                                  |
| **Scope:**     | global                                         |

You can specify a naming template for scheduled snapshots and unnamed snapshots.

The `snapshots.pattern` option takes a Pongo2 template string to format the snapshot name.

To add a time stamp to the snapshot name, use the Pongo2 context variable `creation_date`.
Make sure to format the date in your template string to avoid forbidden characters in the snapshot name.
For example, set `snapshots.pattern` to `{{ creation_date|date:'2006-01-02_15-04-05' }}` to name the snapshots after their time of creation, down to the precision of a second.

Another way to avoid name collisions is to use the placeholder `%d` in the pattern.
If no matching snapshots exist, the placeholder is replaced with `0`.
Otherwise, it is replaced with the next snapshot index, which is one higher than the highest existing matching snapshot index.

<a id="storage-dir-volume-conf:snapshots.schedule"></a>
`snapshots.schedule`

Schedule for automatic volume snapshots

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:snapshots.schedule)

| **Key:**       | `snapshots.schedule`         |
|----------------|------------------------------|
| **Type:**      | string                       |
| **Default:**   | same as `snapshots.schedule` |
| **Condition:** | custom volume                |
| **Scope:**     | global                       |

Specify either a cron expression (`<minute> <hour> <dom> <month> <dow>`), a comma-separated list of schedule aliases (`@hourly`, `@daily`, `@midnight`, `@weekly`, `@monthly`, `@annually`, `@yearly`), or leave empty to disable automatic snapshots (the default).

<a id="storage-dir-volume-conf:user.*"></a>
`user.*`

User-provided free-form key/value pairs

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:user.*)

| **Key:**    | `user.*`   |
|-------------|------------|
| **Type:**   | string     |
| **Scope:**  | global     |

<a id="storage-dir-volume-conf:volatile.devlxd.owner"></a>
`volatile.devlxd.owner`

ID of the DevLXD identity that owns the volume

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:volatile.devlxd.owner)

| **Key:**     | `volatile.devlxd.owner`   |
|--------------|---------------------------|
| **Type:**    | string                    |
| **Default:** | DevLXD owner identity ID  |
| **Scope:**   | global                    |

<a id="storage-dir-volume-conf:volatile.idmap.last"></a>
`volatile.idmap.last`

JSON-serialized UID/GID map that has been applied to the volume

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:volatile.idmap.last)

| **Key:**       | `volatile.idmap.last`   |
|----------------|-------------------------|
| **Type:**      | string                  |
| **Condition:** | filesystem              |

<a id="storage-dir-volume-conf:volatile.idmap.next"></a>
`volatile.idmap.next`

JSON-serialized UID/GID map that has been applied to the volume

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:volatile.idmap.next)

| **Key:**       | `volatile.idmap.next`   |
|----------------|-------------------------|
| **Type:**      | string                  |
| **Condition:** | filesystem              |

<a id="storage-dir-volume-conf:volatile.uuid"></a>
`volatile.uuid`

Volume UUID

[<i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i>](#storage-dir-volume-conf:volatile.uuid)

| **Key:**     | `volatile.uuid`   |
|--------------|-------------------|
| **Type:**    | string            |
| **Default:** | random UUID       |
| **Scope:**   | global            |
