# Migrating Image Library from Local Drive to Persistent Volume

This guide provides step-by-step instructions for migrating the <code class="expression">space.vars.product\_name</code> Image Library backend from a local drive (file backend) to a volume (block storage service backend), along with important considerations for High Availability (HA) mode and multi-host Image Library configurations.

## Overview

By default, the Image Service in the <code class="expression">space.vars.product\_name</code> uses a local file-based backend to store VM images. For enhanced scalability, persistence, and centralized management, it is recommended that the image library be migrated to use a persistent storage volume.

Migrating to a persistent storage backend is particularly beneficial in High Availability (HA) environments and supports future scalability through multi-host image library configuration.

## Prerequisites

* The <code class="expression">space.vars.product\_name</code> environment is already deployed with a functional Image Library using the file backend.
* A block storage service compatible storage backend is configured and available.
* At least one available volume for storing the image library.
* Image Library role is assigned on one or more hosts.
* Administrator access to all relevant nodes and services.
* Downtime window for migration (this process involves stopping image services).

## Step-by-Step Instructions

### Step 1: Prepare the Volume

Create a new volume with sufficient capacity to hold all existing images (plus future growth).

Attach the volume to the host where the Image Library role is currently assigned.

{% tabs %}
{% tab title="Bash" %}

```yaml
pcdctl volume create --size <size-in-GB> pcd-image-repo-vol
pcdctl server add volume <image-node-hostname> pcd-image-repo-vol
```

{% endtab %}
{% endtabs %}

On the host, identify the volume device (e.g., `/dev/vdb`) and mount it:

{% tabs %}
{% tab title="Bash" %}

```yaml
sudo mkfs.ext4 /dev/vdb
sudo mkdir -p /mnt/glance-cinder
sudo mount /dev/vdb /mnt/glance-cinder
```

{% endtab %}
{% endtabs %}

Copy existing image data from local image library (default: `/opt/pf9/pf9-glance/images`) to the mounted volume:

{% tabs %}
{% tab title="YAML" %}

```yaml
sudo rsync -avh /opt/pf9/pf9-glance/images/ /mnt/glance-cinder/
```

{% endtab %}
{% endtabs %}

Update the system to mount the volume persistently:

{% tabs %}
{% tab title="Bash" %}

```yaml
echo '/dev/vdb /mnt/glance-cinder ext4 defaults 0 0' | sudo tee -a /etc/fstab
```

{% endtab %}
{% endtabs %}

### Step 2: Update Image Library Configuration

Edit the image library service configuration file (e.g., `/etc/glance/glance-api.conf`) and set the following backend settings:

{% tabs %}
{% tab title="Bash" %}

```yaml
[DEFAULT]
enabled_backends = cinder:cinder

[glance_store]
default_backend = cinder

[cinder]
volume_type = <your-volume-type-if-applicable>
```

{% endtab %}
{% endtabs %}

Restart the image library service:

{% tabs %}
{% tab title="Bash" %}

```yaml
sudo systemctl restart glance-api
sudo systemctl restart pf9-ostackhost
```

{% endtab %}
{% endtabs %}

Verify the backend is now using block storage volume:

{% tabs %}
{% tab title="YAML" %}

```yaml
pcdctl image show <image-id> -f json | grep location
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Info**

Ensure the Image Service on each node is configured correctly with the same backend settings and the volume is mounted identically across all nodes.
{% endhint %}

## High Availability and Multi-Host Image Library Considerations

* **HA Mode Support**: Using a blocks storage volume backend for the image library is fully supported in HA mode, as the block storage service provides persistent and shared storage accessible across multiple controller nodes.
* **Multi-Host Image Library**: If multiple hosts have the Image Library role:
  * The persistent storage backend ensures centralized image access without needing data synchronization between nodes.
  * All image library nodes must have access to the persistent storage service and appropriate authentication configured.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.platform9.com/private-cloud-director/tutorials/migrating-image-library-from-local-drive-to-cinder-volume.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
