How to attach a Volume to your Instance
volumes blockstorage

How to attach a Volume to your Instance

I’m going to assume you have a running instance already. Mine is called test-instance. See Create a cloud instance to see how to create an instance.

STEP 1 Creating a volume

Create the volume by clicking Compute -> Volumes -> Create Volume.

Fuga Volumes

Mine is called test-volume, will be 20 GB large and use the regular storage tier.

Create volume

STEP 2 Attach the volume to the instance

After you have created the volume it is time to attach it to your instance. This can be done with the context menu of the test-volume row. Click manage attachments.

Attach volume to instance

Choose the instance you want to attach the volume to, test-instance in my case. And choose Attach Volume.

Manage volume attachments

In the volume list you should now see something like this:


Especially the "Attached to test-instance on /dev/vdb" part is important. This is the device name we will be using in our instance.

STEP 3 Format the volume on the instance

It is now time to log in to the instance we have attached the volume to. See How to log in to your instance if you don't know how to do this.

To be able to use the volume we will first need to format it. I will use ext4 as my filesystem. There are also other filesystems to choose from. My instance was attached on /dev/vdb, so that is the block device I need to format. Replace /dev/vdb with the device your volume is attached to.

Log in with ssh and execute the following commands:

$ sudo mkfs.ext4 /dev/vdb

sudo commands might give the following error:
sudo: unable to resolve host test-instance

This is harmless and can be ignored. If you want to get rid off it, you can add the hostname to /etc/hosts:
$ echo " test-instance" | sudo tee -a /etc/hosts

STEP 4 Mount the volume

The volume is attached to our instance and we have formatted it. Before we can use it we need to mount it. If you do not have experience with mounting filesystems in Linux, Ubuntu has a good explanation.
We need to make a mountpoint to mount our volume in:

$ sudo mkdir /mnt/test-volume

We are going to add this mountpoint to /etc/fstab, so it will be mounted automatically on startup. Do this using your favorite editor. Mine is vim.

$ sudo vim /etc/fstab

And add this line to the end of the file:

/dev/vdb    /mnt/test-volume    ext4    defaults    0 0

Save and close (How to exit Vim). This will automatically mount the volume at startup, but we still need to mount it manually now:

$ sudo mount /mnt/test-volume

This will mount the volume. Any data you now save to /mnt/test-volume will be stored on the volume.

Was this article helpful?

Next article:

How to connect to the Fuga Cloud ObjectStore using Python

Fuga supports Amazon S3 compatible object storage. To access the S3 storage you need an EC2 access key and secret key. These can be obtained using the Openstack CLI or the OpenStack Keystone API (which is beyond the scope of this tutorial). Using the OpenStack CLI you can obtain the keypair using the ec2 credentials command as shown below. openstack ec2 credentials list +----------------------------------+----------------------------------+----------------------------------+----------------------------------+ | Access | Secret | Project ID | User ID | +----------------------------------+----------------------------------+----------------------------------+----------------------------------+ | 99999999999999999999999999999999 | 99999999999999999999999999999999 | 99999999999999999999999999999999 | 99999999999999999999999999999999 | +----------------------------------+----------------------------------+----------------------------------+----------------------------------+ When the list is empty a new keypair can be created using the 'openstack ec2 credentials create' command.