• Usually, on our plaform, when we attach volume to the instance, it is automatically formatted and mounted. However, sometimes this process does not occur automatically, requiring manual intervention. This article provides step-by-step instructions on how to format and mount volumes, both HDD and SSD. 

  • It includes formatting and mounting volumes manually, checking volume availability and persistent mounting to ensure volumes remain mounted after instance reboots.

  • Additionally, it also provides a script to automate this entire process.


Please follow the below steps and execute the commands in the terminal where required.


  • Create an instance
  • Create volume and attach it to instance
  • Log into instance
  • List available block devices to ensure the volume is detected by executing the below command.
    lsblk
    executing 'lsblk' command
    • Identify your volume by its size and device name (e.g., /dev/vdb). 

    • You can verify the device name in the instance's details page (instance to which you have attached the volume) under volume section. There, you can identify the volume & check device name. 


  • Format the volume using the desired file system (e.g., ext4).
    sudo mkfs.ext4 /dev/vdb
    executing 'sudo mkfs.ext4 /dev/vdb' command
    • Replace /dev/vdb with the device name of your volume.


  • Make sure your filesystem is correctly created. 
    lsblk -f
    executing 'lsblk -f' command
    • Check that the FSTYPE field matches ext4 for your Block volume.


  • Create a directory to serve as the mount point for your volume.
    sudo mkdir /mnt/vol_b
    • You can replace /mnt/vol_b with any directory path of your choice.


  • Mount the formatted volume to the mount point.
    sudo mount -o defaults /dev/vdb /mnt/vol_b


  • Verify that the volume is successfully mounted by checking its status.
    df -h
    executing 'df -h' command
    • You should see your volume listed among the mounted file systems.

  • In the current configuration, the block device will not be automatically mounted when you stop and start the instance again. 

  • To ensure that stopping and starting the instance does not affect your filesystem, please use the fstab file.

  • You can achieve this by editing the /etc/fstab file of your instance to configure persistent mounting. Run the below command to open the file in the text editor.

    sudo vim /etc/fstab


  • Add the following line to the end of the file and save it. 
    /dev/vdb    /mnt/vol_b   ext4   defaults,nofail   0   2
    • Change device name and mount point according to your device name and mount point.


  • Now, when you stop and start the instance again, the block device will be automatically mounted.

  • If you prefer to automate this process using a script, you have the option to do so. This eliminates the need to manually perform the steps outlined above.

  • Simply create an instance, attach a volume to it, log in to the instance, and execute the following commands one by one. This streamlined approach can save time and effort, providing a more efficient workflow.

    sudo wget -O /usr/local/bin/auto-format-mount https://gist.github.com/skirsten/e5aa8f739afbfc6b1e230bc96509620f/raw/auto-format-mount.py

    sudo chmod +x /usr/local/bin/auto-format-mount
    sudo auto-format-mount # run this after attaching a new volume or run it periodically