Skip to main content

Mounting a Volume to a VM

Mount a volume to your virtual machine, including the necessary commands.

Learn how to successfully mount a volume to your virtual machine in Hyperstack. For detailed step-by-step instructions, including the necessary commands, please refer to the complete instructions below.

Prerequisites

Verify your VM is running

  • On the My Virtual Machines page in Hyperstack, ensure the VM is displaying an ACTIVE status. It may take some time for all services to initialize after the VM is deployed. If there is a connection error, retry after a few minutes.

Ensure your volume is attached to the VM in Hyperstack

  • To confirm that your volume is attached to the VM, navigate to the VM's details page, select the Volumes tab, and verify that the volume's status is listed as ATTACHED. If no volume is attached, click Attach Volume, choose the appropriate volume, and then click Attach.
    • If you need to create a volume, follow this guide to learn how.
Volume Attachment Limit

Each virtual machine can have a maximum of 10 volumes attached at any given time.

Mounting the volume and creating a file system

  1. Connect to VM via SSH

    To access your virtual machine via SSH, execute the following command in a terminal:

    ssh -i [path_to_ssh_key] [os_username]@[vm_ip_address]
    • '[path_to_ssh_key]' is replaced with the path to the SSH key that was generated in the Create SSH key step.

    • '[os_username]' is replaced with the username of the operating system running on your virtual machine.

      • For Ubuntu, the username is ubuntu
    • '[vm_ip_address]' is replaced with the IP address of your virtual machine, which you can find on the Hyperstack My Virtual Machines page under the PUBLIC IP column.

    For a complete guide on connecting to your VM via SSH, click here.

  2. Reformat the volume

    Execute the command below to format your volume, replacing [file-system-format] with your desired file system type:

    sudo mkfs.[file-system-format] /dev/vdb

    Depending on your needs, you can format your volume with one of several file systems. The most common ones are ext4 and xfs:

    • ext4: A robust, journaling file system that is very common in Linux distributions.
    • xfs: Suitable for large file systems and large files, often used in data centers and servers.

    For example:

    sudo mkfs.ext4 /dev/vdb
  3. Create the mount point directory

    To create a directory for mounting the file system, execute the command below, replacing [volume name] with the name of your volume as listed in Hyperstack. To find the volume name, navigate to the Hyperstack Virtual Machines section, select the VM to which the volume is attached, and then click on the Volumes tab to see the volume's name displayed.

    sudo mkdir -p /mnt/[volume name]
  4. Mount the volume

    Now mount the volume to the directory you just created:

    sudo mount /dev/vdb /mnt/[volume name]
  5. Verify the mount

    Confirm that the volume is mounted correctly using one of the following commands:

    mount | grep "[volume name]"

    This checks the current mount list for your volume name, ensuring it is mounted.

    or

    lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,LABEL | grep "[volume name]"

    This provides a detailed list of block devices, including the name, size, file system type, mount point, and label, filtered by your volume name.

  6. (Optional) Automatically mount the volume on boot

    By default, volumes mounted using the mount command are not automatically reattached after a reboot or VM restore. To ensure the volume is mounted automatically at boot, you must add an entry to your /etc/fstab file.

    a. First, identify the UUID of the volume:

    sudo blkid

    b. Open the /etc/fstab file:

    sudo nano /etc/fstab

    c. Add a line similar to the following, replacing with your volume's UUID and mount point:

    UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/[volume name] ext4 defaults,nofail 0 2
    Important

    If the volume isn't always attached, add the nofail option to your /etc/fstab entry. Without it, your VM may fail to boot.


Back to top