Skip to content

Mount a volume on Linux

View as Markdown

After you attach a volume to a Linux node, it appears as a block device. To use it, you format it with a file system (if it is empty) and mount it at a directory. Once mounted, everything you write to that directory is stored on the volume. The examples assume the volume shows up as /dev/vdb and your node’s own root disk is /dev/vda1; your device names can differ, so check them first.

  • A volume attached to the node. See Attach a volume.
  • Access to the node over SSH.

On the node, list the block devices:

lsblk

The attached volume is the unmounted device, for example /dev/vdb. Check its device name before doing anything else.

An empty volume has no file system and must be formatted; a volume created from a snapshot often already has one. Check which you have:

sudo file -s /dev/vdb

If it prints data, the volume has no file system. If it prints a type such as XFS or ext4, it is already formatted, skip the formatting step and do not format it again, or you erase its data.

An empty volume needs a file system. This example uses XFS; ext4 also works if you prefer it.

sudo mkfs -t xfs /dev/vdb

Formatting erases all data on the volume. Run it only on an empty volume, never on one created from a snapshot or one that already holds data. If the command is not found, install the XFS utilities: sudo yum install -y xfsprogs, or on Ubuntu sudo apt install -y xfsprogs.

  1. Create a directory to mount it at, for example /data:

    sudo mkdir /data
  2. Mount the volume to that directory:

    sudo mount /dev/vdb /data
  3. Confirm the mount:

    df -h

You can read and write to /data now, and the volume stores it.

To keep the mount across reboots, add it to /etc/fstab by the device’s UUID.

  1. Find the UUID:

    sudo blkid /dev/vdb

    The output shows a line like UUID="e7c5b2f2-..." TYPE="xfs". Copy the UUID value.

  2. Edit /etc/fstab:

    sudo nano /etc/fstab
  3. Add a line at the end, using your own UUID and mount point:

    UUID=e7c5b2f2-8b2a-4e13-b9a9-bb3f122a91f1 /data xfs defaults,nofail 0 2
  4. Apply the configuration and check for errors:

    sudo mount -a

If mount -a prints no errors, the setup is correct. Reboot the node and run df -h again to confirm /data mounts automatically.

The volume is mounted and stays mounted across reboots. When you later detach it, unmount it and remove its /etc/fstab line first; see Detach a volume. If it will not mount, see Troubleshooting Volumes.