Detaching volumes from an instance

Ordinarily, Cinder volumes can only be attached to one instance at a time. Thus, you need to detach it from one instance before attaching it to another. To detach a volume, we will use another OpenStack client command called openstack server remove volume.

Getting ready

To detach a volume from an instance, you will need the following:

  • The openstack command-line client
  • An openrc file with appropriate credentials for the environment
  • The name or ID of the volume to detach
  • The name or ID of the instance to detach the volume from

For our example, these values are as follows:

  • Volume: cookbook.volume
  • Instance: cookbook.test
  • Mount point: /mnt1

How to do it...

Carry out the following steps to detach a volume to an instance using the openstack client:

  1. List running instances to get the ID of our instance:
    How to do it...
  2. List the volumes that are available and in-use in our environment:
    openstack volume list
    

    This will bring back an output like the following. Note that the information provided shows you if a volume is in use and what instance it is attached to:

    How to do it...
  3. We now need to perform actions inside the running instance. Connect to this instance and verify that the volume is mounted:
    df -h
    

    This will show an output like the following:

    Filesystem Size Used Avail Use% Mounted on
    udev       238M 0    238M  0%   /dev
    tmpfs      49M  1.8M 48M   4%   /run
    /dev/vda1  2.1G 843M 1.3G  41%  /
    tmpfs      245M 0    245M  0%   /dev/shm
    tmpfs      5.0M 0    5.0M  0%   /run/lock
    tmpfs      245M 0    245M  0%   /sys/fs/cgroup
    tmpfs      49M  0    49M   0%   /run/user/1000
    /dev/vdb    9.8G 23M  9.2G   1%   /mnt1
    
  4. Now unmount the /mnt1 volume:
    sudo umount /mnt1
    

    (Verify that it has been unmounted by running df -h again).

  5. Exit the guest, and back on our OpenStack client, detach the volume from the instance with the following command:
    openstack server remove volume cookbook.test c
    ookbook.volume
    
  6. This command doesn't produce any output on success, so view the volume list again to verify that the volume has been detached from the cookbook.test instance:
    openstack volume list
    

    This shows the volume is available and not attached to any instance:

    How to do it...

How it works…

Detaching a Cinder volume from an instance is similar to the steps you would take when removing a USB stick from a computer. First, we need to unmount it from the instance so the operating system doesn't complain about an unexpected removal of some storage. Next under the openstack client, the server remove volume option takes the following syntax:

openstack server remove volume instance_name_or_id volume_name_or_id
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.4.181