Skip to content

How to attach a Volume to your Instance

Estimated time to read: 2 minutes

I’m going to assume you have a running instance already. If you don't please read How to create an instance.

Create a volume and attach it to an instance

  1. Go to Storage -> Volume Store.
  2. Click on Create Volume.
  3. Choose a name and size. For this example, you keep the Volume source to resources.
  4. After creation, you will see the volume in the list. Click on add volume to an instance.
  5. Choose the right instance and submit the form.
  6. Now you see the instance besides the volume data.

Format the volume on the instance

It is now time to log in to the instance you 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 you will first need to format it. I will use ext4 as my file system. There are other file systems 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

Info

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 "127.0.0.1 test-instance" | sudo tee -a /etc/hosts

Mount the volume

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

$ sudo mkdir /mnt/test-volume

You are going to add this mount point 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. This will automatically mount the volume at startup, but You 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.