Make your Block Storage volume available for use on Linux¶
After you attach a block storage volume to your node, it is exposed as a block device. You can format the volume with any file system and then mount it to your nodes. Once the Volume is mounted you can access this volume in the same way as others. Data written to this file system is written to the block storage volume which is attached to the node.
Suppose that you have an SDC node with a volume for the root device as /dev/vda1, and that you have just attached an empty EBS volume to the instance using /dev/vdb. Use the following procedure to make the newly attached volume available for use.
- Login to your instance using ssh
- On you are on command line,Use the lsblk command to view your available disk devices and their mount points (if applicable) to help you determine the correct device name to use
- New volumes are raw block devices, and you must create a file system on them before you can mount and use them, But before creating a Filesystem, make sure your block device is raw. Use the file -s command to determine the same. Volumes that were created from snapshots likely have a file system on them already. If the device has a file system, You will probably get the output of file type, If the output shows simply data, as in the following example output, there is no file system on the device
- Use sudo lsblk -f command to get information about all of the devices attached to the instance.
- If you discovered that there is a file system on the device in the previous step, skip this step. If you have an empty volume, use the mkfs -t command to create a file system on the volume.
sudo mkfs -t xfs /dev/vdb
Do not use this command if you’re mounting a volume that already has data on it (for example, a volume that was created from a snapshot). Otherwise, you’ll format the volume and delete the existing data.
- If you get an error that mkfs.xfs is not found, use the following command to install the XFS tools and then repeat the previous command
sudo yum install xfsprogs
- Use the mkdir command to create a mount point directory for the volume. The mount point is where you read and write files to after you mount the volume. The following example creates a directory named /data.
sudo mkdir /data
- Use the following command to mount the volume at the directory you created in the previous step.
sudo mount /dev/vdb /data
You can now verify if the filesystem successful mounted using the command df -h
You can unmount the block storage using the below command
The mount point is not automatically preserved after rebooting your instance. To automatically mount this EBS volume after reboot. Please make sure to add an entry for the device to the /etc/fstab file.