Attaching the block storage to an instance

The virtual storage device we just created is not much good to us unless it is attached to an instance that can make use of it. Luckily for us, we just launched an OpenStack instance and logged in to it. Perform the following steps to attach the block storage to an instance:

  1. To show the attachment, start by connecting to the instance and listing the existing block devices on the instance that is running:
    instance# ls /dev/vd*
    /dev/vda  /dev/vda1
    

    The boot device for this instance is vda; this is the Glance image that was used to boot.

  2. Now attach the volume you just created to the instance you have running. When you list the devices on the instance again, you will see the Cinder volume show up as vdb:
    undercloud# openstack server add volume "My First Instance" my_volume
    instance# ls /dev/vd*
    /dev/vda  /dev/vda1  /dev/vdb
    
  3. The Cinder volume was attached as vdb to the instance. Now that we have a new block device on the instance, we treat it just as we would any other block device. Make a partition, create a file system, mount it, and read and write to it. The output from the following commands will be truncated for brevity:
    instance# fdisk /dev/vdb
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    Partition number (1-4, default 1): 1
    First sector (2048-2097151, default 2048):
    Last sector, +sectors or +size{K,M,G,T,P} (2048-2097151, default 2097151):
    Created a new partition 1 of type 'Linux' and of size 1023 MiB.
    Command (m for help): w
    The partition table has been altered.
    instance# mkfs -t ext4 /dev/vdb1
    Writing superblocks and filesystem accounting information: done
    instance# mount /dev/vdb1 /mnt
    instance# echo "test" > /mnt/test
    instance# cat /mnt/test
    test
    
  4. Let's unmount the device and detach it from the running instance:
    instance# umount /mnt
    undercloud# openstack server remove volume "My First Instance" my_volume
    instance# ls /dev/vd*
    /dev/vda  /dev/vda1
    

In these steps, we showed that only vda exists on the instance. Next, we attached the volume and showed you how the instance sees it as vdb. Then, we partitioned, mounted, and wrote to the file system. Finally, the device was unmounted and detached, and it was shown that vdb has been removed. If the volume was reattached, there would be no need to partition it and create a file system. Data written to the volume will persist as long as the volume exists.

..................Content has been hidden....................

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