Skip to main content

Attach Block Storage to Instance

DewaVPS Block Storage provides network-based block devices, functionally identical to virtual hard drives, that you can attach to your Instances. Attaching a Block Storage volume is an effective way to add more storage capacity to an Instance beyond its primary root disk.

Benefits of Using Block Storage:

  • Expand Storage: Increase the available disk space for your applications and data.
  • Data Separation: Keep application data or user files separate from the operating system disk, simplifying backups and OS upgrades.
  • Persistence: Block Storage volumes exist independently of Instances. You can detach them from one Instance and reattach them to another within the same region (data persists on the volume).

Prerequisites

Before you can attach a Block Storage volume:

  1. You must have an existing DewaVPS Block Storage volume created in your account.
  2. The volume must be located in the same datacenter region as the target Instance.
  3. The volume must be available – it cannot be currently attached to another Instance.

Attaching a Volume via the DewaVPS Control Panel

Follow these steps to attach an available Block Storage volume to your Instance:

  1. Log in to your DewaVPS account.
  2. Navigate to the Instances section in the sidebar menu.
  3. Click on the name of the Instance to which you want to attach the volume.
  4. Select the Block Storage tab on the Instance's management page.
  5. A modal window will appear:
    • A dropdown list shows all available Block Storage volumes in the same region. If no volumes are available, this list will be empty.
    • A link to create new block storage is present if you need to provision a volume first.
  6. From the dropdown list, select the Block Storage volume you wish to attach.
  7. Press the Confirm button.
  8. Wait for the attachment process to complete. This takes a few moments.
  9. Done. The control panel now shows the volume attached to the Instance.

Crucially, the volume is now visible to the Instance's operating system, but it is not yet ready for use. You must perform actions within the Instance's OS to format and mount the volume.

Important: Making the Attached Volume Usable within the Operating System

After attaching the volume via the control panel, you need to connect to your Instance (using SSH) and perform the following steps to make the storage usable. These commands are typical for Linux distributions.

1. Identify the Device Name

The newly attached volume appears as a block device. You need to find its name.

  • Run the command:
    lsblk
  • Look for a new device in the output that matches the size of the Block Storage volume you attached. It will have a name like /dev/sda, /dev/sdb, /dev/vda, /dev/vdb, etc., without any partitions listed under it yet. Note this device name (replace /dev/device_name in the following commands with the actual name you found).

2. Create a Filesystem (Format the Volume)

Warning: This step will permanently erase all data on the selected device (/dev/device_name). Only proceed if this is a new volume or you intend to wipe any existing data on it.

  • Choose a filesystem type. ext4 is common for Linux.
  • Format the volume using the mkfs command:
    sudo mkfs.ext4 /dev/device_name
    (Replace /dev/device_name with the actual device name identified in step 1).

3. Mount the Volume

Create a directory where the volume's filesystem will be accessible and then mount it.

  • Create a mount point directory:
    sudo mkdir /mnt/myvolume
    (You can choose a different path than /mnt/myvolume).
  • Mount the formatted volume to the directory:
    sudo mount /dev/device_name /mnt/myvolume
    (Use the correct device name and mount point path).

The volume is now accessible at /mnt/myvolume. However, this mount will not persist after the Instance reboots.

To automatically mount the volume every time the Instance boots, add an entry to the /etc/fstab file.

  • First, get the UUID (Universally Unique Identifier) of the newly formatted volume. This is more reliable than using the device name, which can sometimes change.
    sudo blkid /dev/device_name
    Copy the UUID="..." value from the output.
  • Edit the /etc/fstab file using a text editor (like nano or vim):
    sudo nano /etc/fstab
  • Add the following line at the end of the file, replacing the placeholders:
    UUID=YOUR_COPIED_UUID /mnt/myvolume ext4 defaults,nofail 0 0
    • Replace YOUR_COPIED_UUID with the actual UUID you copied.
    • Replace /mnt/myvolume with your chosen mount point directory.
    • Replace ext4 with the filesystem type you used if different.
    • The defaults,nofail options ensure the system boots even if the volume has issues mounting.
  • Save the file and exit the editor.
  • Test the /etc/fstab entry by running:
    sudo mount -a
    If this command completes without errors, the entry is correct. The volume will now mount automatically on boot.

Detaching Volumes

You can detach Block Storage volumes from an Instance when they are no longer needed (provided the volume is properly unmounted within the OS first). This action is performed via the same Block Storage tab on the Instance management page, where you will find an option to detach the volume.