# Migrating Image Library from Local Drive to Cinder 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 Cinder volume (cinder 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 Cinder volume.

Migrating to a Cinder 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 Cinder-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 Cinder Volume

Create a new Cinder 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
openstack volume create --size <size-in-GB> pcd-image-repo-vol
openstack 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 Cinder 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 Glance Configuration

Edit the Glance 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 Glance service:

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

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

{% endtab %}
{% endtabs %}

Verify the backend is now using Cinder:

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

```yaml
openstack 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 Cinder volume for the image library is fully supported in HA mode, as Cinder provides persistent and shared storage accessible across multiple controller nodes.
* **Multi-Host Image Library**: If multiple hosts have the Image Library role:
  * The Cinder backend ensures centralized image access without needing data synchronization between nodes.
  * All image library nodes must have access to the Cinder volume and appropriate authentication configured.
