Introduction To AWS Elastic Block Store - Part Four

In the previous article Introduction to Elastic Block Storage-Part 3, we learned about volumes, partitions, and mounting.
In this article, we are going to learn the below topics.
  •  Listing and formatting a partition.
  •  Mounting a partition.
  •  Adding data to the partition via a directory.
  •  Unmounting directory.
  •  Permanent mounting.
Let’s get started!

Listing and formatting partition

In the previous article, we created a partition on the hard disk. Now, it is time to see if the partition table has been altered successfully and then, we will format the partition to mount it to a directory.
We can use the below command to see.
fdisk -l
AWS Elastic Block Store
Here, we can see that we have 2 disks, each having 1 partition.
After creating the partition, you have to format it with a filesystem of your choice. We have a few utilities that can help us format the partition.
Type the below command and hit the tab key twice; it will show us all other utilities available for formatting.
AWS Elastic Block Store
Here, I have chosen ext4 filesystem.
Run the below command.
mkfs.ext4 /dev/xvdf1
This will format the newly created partition.
AWS Elastic Block Store
So, we are done with the formatting partition. Next is to mount the partition.


Once formatting is done, we can mount that partition to a directory. For that, we first need to create a directory and mount it to a partition with the below commands.
  1. mkdir /opt/devdata  
  2. mount /dev/xvdf1 /opt/devdata  
  3. df -h   
AWS Elastic Block Store
We can see that our partition /dev/xvdf1 has been mounted successfully to the /opt/devdata directory.


Now, let’s go to /opt/devdata and create some files and directories with the below commands.
  1. cd /opt/devdata  
  2. mkdir testDir{1..7}  
  3. touch testFile{8..14]  
AWS Elastic Block Store


We can also unmount the directory from the partition and after unmounting we will see that we don’t have any data inside the directory /opt/devdata.
AWS Elastic Block Store
This is because all the data has been stored in the partition and we can thus mount the partition to some other directory if we want to recover the data. So the data is still with us. 😊
So far what we have seen is TEMPORARY MOUNTING which means that if we reboot the machine then this mount point will be unmounted.


If we really want to mount a directory permanently to a partition, then we will need to make some changes in the /etc/fstab file.
So, open the file using the vim editor using the below command.
  1. vim /etc/fstab  
and add the below line of code.
  1. /dev/xvdf1 /opt/devdata ext4 defaults 0 0  
AWS Elastic Block Store
Save the file and exit.
Now if we again run df-h , then also we would not see the mounting of directory /opt/devdata to the partition /dev/xvdf1.
AWS Elastic Block Store
For that we need to run the below command.
  1. mount -a  
  2. df -h  
AWS Elastic Block Store
Now we can see that mount point. This happened because the machine has read the file /etc/fstab and has generated the mounting as per the details mentioned there.
We can also see that our data which got disappeared from the directory is now visible as we have again mounted it to the partition /dev/xvdf1.
This is called Permanent mounting.
Now we can see that if we don’t delete the volumes then we can attach it to any instance and can mount it there and thus it will behave like a pen drive.
People may accidentally delete the data or EBS volume itself may get corrected for some reasons.
So, there should be ways to recover from the data loss and with backups, we can recover the loss.


In this article, we learned a lot of things on mounting, unmounting. We also saw temporary and permanent mounting. In the next article, we are going to see how we can safeguard ourselves from the loss of corrupted volumes by using snapshots.
I hope you find this article helpful. Stay tuned for more … Cheers!!