Resizing/shrinking an OpenStack root partition

OpenStack itself at this moment does not support shrinking of volumes, and to complicate it even more a root partition cannot be unmounted/redacted. The following procedure seem t have worked for me:

1.) Make a clone of the volume (from the command line OpenStack client:
openstack volume create {name-it-something} --source {source-volume}source-volume is the ID or the name of the volume which you want to shrink.

2.) Attach the newly created volume into another guest;

3.) If you want data to be removed from the source partition (which was the case in my situation), then this is the time to do that. Mount the partition in that case, then unmount it when done.

4.) Shrink the filesystem on the partition to the desired size:
resize2fs /dev/{source-partition} 20G
5.) Shrink the partition (to a size which is bigger than the filesystem in the previous step):
parted /dev/{source-disk} resizepart {source-partition-number} 25GIf in doubt which parameters to use, start parted in interactive mode.

6.) Create a new volume in OpenStack, make it somehow bigger than the partition, attach that volume as well to the same (temporary) guest. Mount the volume. This will be your destination drive;

7.) Copy partition tables from source to destination:
sgdisk -R=/dev/{destination-disk} /dev/{source-disk}
8.) Copy the partitions from source, repeat it for all partitions:
dd if=/dev/{source-partition} of=/dev/{destination-partition} status=progress
9.) Resize partitions and filesystem so they occupy all the allocated space:
parted /dev/{destination-disk} resizepart {destination-partition-number} 100%If in doubt which parameters to use, start parted in interactive mode.
resize2fs /dev/{destination-partition}
10.) Create a new OpenStack instance of any flavor, but this time use the newly created volume as storage. You will need to have the boot option enabled in the volume to see it in the instance creation screen.

December-02-2022
OpenStack, ubuntu, linux

Leave a comment

Comments (if any)

Don't know what will come here, let's wait and see... But in the first instance it will be a login box (for myself):

Login