One of the key features in OpenStack is the ability to resize the Instance’s flavor to increase resource limits used by Instances, such as vCPUs and RAM. Unfortunately, in the case of an Instance with a Cinder-backed volume, changing flavor does not affect the underlying volume.
To resize a volume we would normally detach it from an Instance first, but the bad news is that OpenStack won’t let us detach the volume from the existing Instance if the volume is attached as a root device volume, throwing an error:
Cannot detach a root device volume (HTTP 400) (Request-ID: req-1b1e7a08-0da7-4c60-aefb-3631520feda5)
To bypass this obstacle, we can change the volume’s status to available before resizing.
Steps:
1. Power off the Instance
[root@infra1-utility-container-74de693b ~]# openstack server stop instance1
Ensure the Instance has been stopped:
[root@infra1-utility-container-74de693b ~]# openstack server show instance1 | grep vm_state
| OS-EXT-STS:vm_state | stopped
2. Change volume’s state
Find Instance’s volume ID:
[root@infra1-utility-container-74de693b ~]# openstack server show instance1 | grep volumes_attached
| volumes_attached | id='fc7f8748-d37d-4c51-a5b6-5233283fa939'
Check current volume’s status (should be in-use):
[root@infra1-utility-container-74de693b ~]# openstack volume show fc7f8748-d37d-4c51-a5b6-5233283fa939 | grep status
| migration_status | None
| os-vol-mig-status-attr:migstat | None
| os-vol-mig-status-attr:name_id | None
| replication_status | None
| status | in-use
Change volume’s status to available (execute the below command as admin, otherwise it won’t work):
[root@infra1-utility-container-74de693b ~]# cinder reset-state --state available fc7f8748-d37d-4c51-a5b6-5233283fa939
Verify new status (should be available now):
[root@infra1-utility-container-74de693b ~]# openstack volume show fc7f8748-d37d-4c51-a5b6-5233283fa939 | grep status
| migration_status | None
| os-vol-mig-status-attr:migstat | None
| os-vol-mig-status-attr:name_id | None
| replication_status | None
| status | available
3. Resize the volume
Display current volume size:
[root@infra1-utility-container-74de693b ~]# openstack volume show fc7f8748-d37d-4c51-a5b6-5233283fa939 | grep size
| size | 20
Resize the volume by setting a new size, for example, 40GB:
[root@infra1-utility-container-74de693b ~]# openstack volume set fc7f8748-d37d-4c51-a5b6-5233283fa939 --size 40
Verify new size:
[root@infra1-utility-container-74de693b ~]# openstack volume show fc7f8748-d37d-4c51-a5b6-5233283fa939 | grep size
| size | 40
Note: after resizing OpenStack automatically sets volume’s status back to in-use, so there is no need to do it manually.
Verify current status (should be in-use now):
[root@infra1-utility-container-74de693b ~]# openstack volume show fc7f8748-d37d-4c51-a5b6-5233283fa939 | grep status
| migration_status | None
| os-vol-mig-status-attr:migstat | None
| os-vol-mig-status-attr:name_id | None
| replication_status | None
| status | in-use
4. Power on the Instance
[root@infra1-utility-container-74de693b ~]# openstack server start instance1
Note: the file system inside the Instance should be resized automatically by cloud-init growpart module to match the new volume size, so there is no need to do it manually.