Skip to content

Attach Block Storage to an Instance

Instances usually come with a root disk, but for persistent data storage that exists independently of the instance's lifecycle (and can be moved between instances), you should use Volumes (Block Storage).

This guide walks you through creating a volume, attaching it to a running instance, and configuring it within the Linux operating system.

Prerequisites

  • A running Compute Instance (Linux).
  • Access to the Horizon Dashboard.
  • Available Volume storage quota.

Steps

Track your progress. Data is saved locally in your browser.
Checklist: None

Sign in to Horizon

  1. Use your browser to navigate to the Stud I/O Cloud Compute Control Panel (Horizon) or use the button below:

    🌐Open Horizon
  2. Sign in and choose the appropriate Project.

Create a Volume

First, create the storage volume in the same availability zone as your instance.

  1. Navigate to Volumes > Volumes.
  2. Click Create Volume.
  3. Volume Name: Give it a descriptive name (e.g., db-data-vol).
  4. Size (GiB): Enter the desired size (e.g., 50).
  5. Availability Zone: Ensure this matches the zone where your instance is running.
  6. Click Create Volume.

Attach Volume to Instance

Once the volume status is Available:

  1. In the Volumes list, find your new volume.
  2. Click the arrow/dropdown in the Actions column and select Manage Attachments.
  3. Attach to Instance: Select your target instance from the dropdown list.
  4. Click Attach Volume.
  5. Note the Device Name provided (usually /dev/vdb or similar).

Verify Device in Instance

Now, log in to your instance to configure the storage.

  1. SSH into your instance:
    bash
    ssh ubuntu@<your-instance-ip>
  2. List block devices to confirm the new disk is attached:
    bash
    sudo lsblk
    You should see a device (e.g., vdb) with the size of your volume, likely without partitions.

Format the Volume

Warning: This step erases all data on the volume. Only do this for new volumes. If attaching an existing volume with data, skip to the Mount step.

  1. Create an ext4 filesystem on the device:
    bash
    sudo mkfs.ext4 /dev/vdb

Mount the Volume

  1. Create a directory to serve as the mount point:
    bash
    sudo mkdir /mnt/data
  2. Mount the volume manually to test:
    bash
    sudo mount /dev/vdb /mnt/data
  3. Verify it's mounted:
    bash
    df -h | grep vdb

Configure Automount (fstab)

To ensure the volume mounts automatically after a reboot, add it to /etc/fstab.

  1. Get the UUID of the new volume:

    bash
    sudo blkid /dev/vdb

    Copy the UUID string (excluding quotes).

  2. Open /etc/fstab for editing:

    bash
    sudo nano /etc/fstab
  3. Add a new line at the end (replace <UUID> with your actual UUID):

    text
    UUID=<your-uuid-here>   /mnt/data   ext4   defaults,nofail   0   2
  4. Save and exit (Ctrl+O, Enter, Ctrl+X).

  5. Verify the configuration by unmounting and mounting all:

    bash
    sudo umount /mnt/data
    sudo mount -a

    If no errors occur, your configuration is correct.

Troubleshooting

  • Volume stuck in "Attaching": Wait a few moments. If it persists, check the instance logs.
  • "Device busy" when unmounting: Ensure no open files or shells are currently inside the /mnt/data directory.
  • Permission denied: Remember to use sudo for administrative commands like mount and editing /etc/fstab.