How to create and mount volumes on DreamCompute

DreamCompute, like other OpenStack clouds, has multiple kinds of storage available to use. This article works with 'Volume' storage which is recommended for storing critical and important data. For more info on the types of storage, please visit the article on differences between ephemeral and volume storage.

What is Volume storage?

Volumes can be thought of like a hot-swap hard disk, in that you can pull it out of one system (detach it), plug it into another system (attach it) and the data will remain on it as it is reused.

There are several ways to do the initial steps of creating and attach the volume, so please select the method you wish to use:

Create and attach a Volume using the dashboard

Checking your storage capacity

The first step is to make sure you have sufficient volume storage to add a new volume. Check the DreamCompute dashboard project overview page. On that page, view the 'Volume Storage' pie chart.

how-to-create-and-mount-volumes-on-dreamcompute_01

If you need additional storage, more can be added in the DreamHost control panel.

Creating a Volume

  1. Navigate to the DreamCompute dashboard volumes page.
  2. Click the Create Volume button on the top right.
  3. Give the volume a required size in GB, and an optional name and description while leaving the other options set to the defaults.

Using your Volume

  1. To use your volume, it needs to be attached to a running instance. If you have no instances, create one first.
  2. Navigate to the DreamCompute dashboard volumes page.
  3. Click the drop-down menu and select Manage Attachments:
    how-to-create-and-mount-volumes-on-dreamcompute_02
  4. The new window will show no attachments at this time. It also displays a dropdown with list of your instances. Click on the list and select your instance name, then click Attach Volume.
    how-to-create-and-mount-volumes-on-dreamcompute_03

This completes the creation of the volume. Please click below to continue with creating your file system and mounting the volume.

Create and attach a Volume using the OpenStack CLI

The first step is to make sure you have sufficient volume storage to add a new volume. Check the DreamCompute dashboard project overview page. On that page, view the 'Volume Storage' pie chart.

how-to-create-and-mount-volumes-on-dreamcompute_01

If you need additional storage, more can be added in the DreamHost control panel.

Creating a Volume

To create the new volume, run this command:

[user@localhost]$ openstack volume create --size SIZE_IN_GB VOLUME_NAME

The volume should now show up in the dashboard, and on the command line.

Using the Volume

To use your volume, it now needs to be attached to a running instance.

  1. If you have no instances, you will need to create one. Using the CLI requires the instance name and the UUID of the volume. Find the volume details by running:
    [user@localhost]$ openstack volume list
    +-----------------------+--------------+-----------+------------+-----------------------+
    | ID                    | Display Name | Status    | Size       | Attached to           |
    +-----------------------+--------------+-----------+------------+-----------------------+
    | 26c25d21-cff5-4154... | -            | in-use    | 50         | b781a709-27d7-4d7a... |
    | 8edfb18b-6b4b-424e... | VOLUME_NAME  | available | SIZE_IN_GB |                       |
    +-----------------------+--------------+-----------+------------+-----------------------+
    
    In this example the instance is called 'VOLUME_NAME' and there is only one 'available' volume which is the one just created.
  2. Once you have your values, attach the volume with the following command:
    [user@localhost]$ openstack server add volume mysql VOLUME_NAME
    

The device name listed may not always be accurate, so double-check before using a new device.

Create a file system

The new drive now needs a file system so it can store data. There are many choices when it comes to file systems, but for this example, a safe default of ext4 is used.

Now connect to your instance with the default username for your image.

Instances created before October 5th, 2016 will continue to have 'dhc-user' as the default user, except for CoreOS, which will have 'core' as the default user. To find your default user, visit the following article:

First, find the device name for the new volume. You can see what devices are available by checking for /dev/vd* device files:

[user@localhost]$ ls /dev/vd*
/dev/vda  /dev/vda1  /dev/vdb

Generally /dev/vda will be the boot drive, and in this case /dev/vdb appears to be the new volume. You can double check the size matches with the command:

[user@localhost]$ sudo fdisk -l /dev/vdb
Disk /dev/vdb: 1 GiB, 1073741824 bytes, 2097152 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

This matches the 1GB size of the volume created. Next, create a file system on the drive by running the mkfs command.

This command is destructive! If ran on the wrong device, it will erase it so please be sure you have it correct!

[user@localhost]$ sudo mkfs.ext4 /dev/vdb
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: 51751b87-a583-42b3-8d61-27ed586ba8da
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

The file system is now created.

Mount the File System

As mentioned before, the device for the drive can change should udev or other changes happen, and such an error can prevent your instance from booting up properly. To avoid this, boot via UUID. You can find the drives UUID by running the blkid command:

[user@localhost]$ sudo blkid /dev/vdb
/dev/vdb: UUID="51751b87-a583-42b3-8d61-27ed586ba8da" TYPE="ext4"

If you wish to mount this volume in a location that doesn't exist, go ahead and create the directory with mkdir:

[user@localhost]$ sudo mkdir -p /mnt/backups

With this info you can now modify /etc/fstab to have it auto mounted. Edit it with your preferred editor, which in this example will be vim and add a line towards the bottom like so:

UUID=51751b87-a583-42b3-8d61-27ed586ba8da   /mnt/backups   ext4   defaults   0   2

Once that is added, you can test your setup with the following:

[user@localhost]$ sudo mount -a

If all succeeded, you should see no output or only output about the file system. You can check that all is well with df:

[user@localhost]$ df -h /mnt/backups
Filesystem      Size  Used Avail Use% Mounted on
/dev/vdb        976M  1.3M  908M   1% /mnt/backups

Checking specifically for the /dev/vdb device at the front.

That's it. When you reboot your instance, your volume will be re-mounted and ready for use.

Did this article answer your questions?

Article last updated PST.