How to mount a new volume to a cloud instance
This article provides a step-by-step guide on how to create a file system on a newly created volume that’s attached to an instance. You will then be able to mount the volume to the instance so that it’s accessible.
Steps
-
1First, ensure that the volume is attached to an instance.
-
2Connect to the instance’s command line interface (CLI) using your preferred SSH client and ensure you are logged in.
-
3Check to see if the operating system has detected the new volume. This can be done by issuing the following command:
This will display a list of all the available storage devices on your machine, including the attached volume. Confirm that the volume is present and that the size matches the volume you have attached.sudo lsblk -p
-
4Next, you need to create the filesystem on the newly attached volume. In this example we will be creating an ext4 partition (one of many available partitions in Linux). To create the file system, run the following command, replacing /dev/vdb with the name of your volume as displayed on the terminal:
This command will format the volume with the ext4 file system. For large files, run the following command:sudo mkfs -t ext4 /dev/vdb
mkfs.ext4 -E nodiscard /dev/vdb1
-
5Once the file system has been created, you will need to create a directory in order to mount the volume. In this example we have created the myvolume directory within the operating system’s mnt directory. To create a directory you need to run the following command:
sudo mkdir /mnt/myvolume
-
6Now that you have created the directory to which you can mount the volume, you can mount it by using the following command:
sudo mount /dev/vdb /mnt/myvolume
If you want the volume to be mounted automatically every time the system starts up, you’ll need to add an entry to the /etc/fstab file. Open the file in your preferred text editor. In this example we are making use of nano:
sudo nano /etc/fstab
Add the following line to the end of the file:
/dev/vdb /mnt/myvolume ext4 defaults 0 0
This line tells the system to mount the /dev/vdb device to the /mnt/myvolume directory using the ext4 file system with the default mount options. Save the /etc/fstab file and exit the text editor.