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:
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.
vdb
:undercloud# openstack server add volume "My First Instance" my_volume instance# ls /dev/vd* /dev/vda /dev/vda1 /dev/vdb
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
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.
3.143.205.136