Mounting Block Devices

This guide explains how to attach block storage volumes to virtual machines and mount them with a filesystem in Thalassa Cloud. Block storage provides persistent, high-performance storage that survives VM lifecycle events.

Prerequisites

  • A virtual machine running in Thalassa Cloud
  • A block storage volume created in Thalassa Cloud
  • SSH access to the VM with root or sudo privileges
  • API token or CLI access for volume attachment

Overview

The process involves two main steps:

  1. Attach the volume to the VM using the Thalassa Cloud API or CLI
  2. Mount the volume in the Linux filesystem using standard Linux commands

Step 1: Attach the Volume

Option A: Using Thalassa Cloud CLI

List Available Volumes

List all volumes in your organisation:

tcloud storage volumes list

Note the volume ID you want to attach.

Attach Volume to VM

Attach the volume to your virtual machine:

tcloud storage volumes attach <volume-id> --instance <vm-id>

Replace:

  • <volume-id> with your volume identifier
  • <vm-id> with your virtual machine identifier

You can attach multiple volumes in a single command:

tcloud storage volumes attach <volume-id-1> <volume-id-2> --instance <vm-id>

Verify Volume Attachment

Check that the volume is attached in the Thalassa Cloud console or using the CLI:

tcloud storage volumes list

The volume should show as attached to your VM.

Step 2: Identify the Block Device

After attaching the volume, identify the block device in the VM.

List Block Devices

List all block devices:

lsblk

You should see a new device (e.g., vdb, vdc, nvme0n1) that wasn’t present before.

Check Device Details

Get detailed information about block devices:

sudo fdisk -l

Or for a specific device:

sudo fdisk -l /dev/vdb

Step 3: Create a Filesystem

If the volume is new or doesn’t have a filesystem, create one.

Choose a Filesystem Type

Common options:

  • ext4: Default for most Linux systems, good general-purpose choice
  • xfs: Better for large files and high-performance workloads
  • btrfs: Advanced features like snapshots and compression

Create the Filesystem

For ext4 (recommended for most use cases):

sudo mkfs.ext4 /dev/vdb

Replace /dev/vdb with your actual device name.

For xfs:

sudo mkfs.xfs /dev/vdb

Warning

Creating a filesystem will erase all data on the device. Ensure the volume is empty or you have backups before proceeding.

Step 4: Mount the Volume

Mount the volume to make it accessible in the filesystem.

Create Mount Point

Create a directory where the volume will be mounted:

sudo mkdir -p /mnt/data

Use a descriptive name that indicates the volume’s purpose (e.g., /mnt/database, /mnt/app-storage).

Mount the Volume

Mount the device to the mount point:

sudo mount /dev/vdb /mnt/data

Verify Mount

Verify the volume is mounted correctly:

df -h

You should see your mounted volume in the output. Also check:

mount | grep /mnt/data

Step 5: Configure Automatic Mounting

To ensure the volume mounts automatically after VM reboots, add it to /etc/fstab.

Get the Volume UUID

Get the UUID of the filesystem:

sudo blkid /dev/vdb

Note the UUID value (e.g., UUID="12345678-1234-1234-1234-123456789abc").

Edit fstab

Edit the /etc/fstab file:

sudo nano /etc/fstab

Add a line with the following format:

UUID=12345678-1234-1234-1234-123456789abc /mnt/data ext4 defaults 0 2

Replace:

  • UUID=... with your actual UUID
  • /mnt/data with your mount point
  • ext4 with your filesystem type

Test fstab Configuration

Test the fstab configuration without rebooting:

sudo mount -a

If there are no errors, the configuration is correct.

Complete Example

Here’s a complete example workflow:

# 1. Attach volume using CLI
tcloud storage volumes attach vol-12345 --instance vm-67890

# 2. SSH into the VM and identify the device
ssh user@vm-ip
lsblk

# 3. Create filesystem (if new volume)
sudo mkfs.ext4 /dev/vdb

# 4. Create mount point and mount
sudo mkdir -p /mnt/app-data
sudo mount /dev/vdb /mnt/app-data

# 5. Get UUID and add to fstab
sudo blkid /dev/vdb
sudo nano /etc/fstab
# Add: UUID=... /mnt/app-data ext4 defaults 0 2

# 6. Test fstab
sudo mount -a

Detaching Volumes

To detach a volume:

Unmount First

Always unmount the filesystem before detaching:

sudo umount /mnt/data

Detach Using CLI

tcloud storage volumes detach <volume-id> --instance <vm-id>

Detach Using API

curl -X POST \
  https://api.thalassa.cloud/v1/storage/volumes/<volume-id>/detach \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "instance_id": "<vm-id>"
  }'

Warning

Always unmount the filesystem before detaching the volume to prevent data corruption.

References