Categories
AWS

How to Mount a Disk in AWS EC2?

Home » AWS » How to Mount a Disk in AWS EC2?

In our last post, we talked about how to check for unreleased cursors in SQL Server. Today, let’s see how to mount a disk in AWS.

Steps to mount a disk in AWS

1. Create an EC2 instance.

2. Create an EBS volume and associate it with the EC2 instance via the console (Make sure the EBS and EC2 are in the same availability zone, i.e., within the same subnet).

3. SSH into the EC2 instance and create a mount directory. 

4. Perform the mount operation as follows:

##Run the following commands in the root directory:
 
mkdir /data
 
 
 
[root@ip ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  468M     0  468M   0% /dev
tmpfs          tmpfs     477M     0  477M   0% /dev/shm
tmpfs          tmpfs     477M  408K  476M   1% /run
tmpfs          tmpfs     477M     0  477M   0% /sys/fs/cgroup
/dev/xvda1     xfs        20G  1.8G   19G   9% /
tmpfs          tmpfs      96M     0   96M   0% /run/user/1000
 
 
 
[root@ip ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   20G  0 disk 
└─xvda1 202:1    0   20G  0 part /
xvdb    202:16   0  100G  0 disk 
 
 
## Check if the volume has a file system. If the file system is missing, the volume cannot be mounted.
 
## Use the file -s command to get information about a specific device, such as its file system type. If the output only shows "data" (as in the example output below), it indicates that the device does not have a file system.
[root@ip ~]# file -s /dev/xvdb
/dev/xvdb:data
 
 
##Use Case: Mounting an empty volume.
 
mkfs -t xfs /dev/xvdb
 
 
##Mount the volume
 
mount /dev/xvdf /data
 
##After restarting the instance, the mount point will not persist. Add the following entry to /etc/fstab to ensure the device is mounted at the specified mount point upon reboot.
/dev/xvdb     /data       xfs    defaults,noatime  0   2
 
##Once configured, you can reboot the server to test the setup.

By Jaxon Tisdale

I am Jaxon Tisdale. I will share you with my experience in Network, AWS, and databases.

Leave a Reply

Your email address will not be published. Required fields are marked *