Dear Readers,
In this article,we will see Mounting an EBS Volume on a Linux EC2 Instance.

Implementation Steps
- View your existing Instance.
- Connect to Linux EC2 Instance through putty.
- Mount an EBS Volume to your Linux EC2 Instance.
First, we need to AWS Console page by using below link.
https://aws.amazon.com/console/
Click on sign in to Console button.

Logging to aws account
Login using username & password and click on sign in.

Enter to AWS Management Console
We can see the AWS Management Console Dashboard.

Go to Services, under the compute module click EC2 service to open.

I have already launched Instance.
View your existing Instance
We can see Linux Server “My Linux” which was created earlier.

Verify volumes of your Linux EC2 Instance.
Go volumes,we can see two volumes attached to Linux EC2 Instance.
The first one is root volume and second one is EBS volume.

Note
If you want to store the files inside the EBS volume, you need to mount EBS volume to your Linux EC2 Instance.Manually.
Connect to Linux EC2 Instance through putty

Mount an EBS Volume to your Linux EC2 Instance.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | login as: ec2-user Authenticating with public key "imported-openssh-key" Last login: Wed Nov 27 10:17:56 2019 from 123.201.77.64        __|  __|_  )        _|  (     /   Amazon Linux 2 AMI       ___|\___|___| https://aws.amazon.com/amazon-linux-2/ 5 package(s) needed for security, out of 13 available Run "sudo yum update" to apply all updates. [ec2-user@ip-172-31-34-108 ~]$ | 
Switch to root user
| 1 2 3 4 | [ec2-user@ip-172-31-34-108 ~]$ sudo su [root@ip-172-31-34-108 ec2-user]# | 
Verify Available disks in your Linux Server
| 1 2 3 4 5 6 7 8 9 10 | [root@ip-172-31-34-108 ec2-user]# lsblk NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda    202:0    0   8G  0 disk └─xvda1 202:1    0   8G  0 part / xvdb    202:16   0  10G  0 disk | 
Verify the volume has any data by using the following command.
| 1 2 3 4 | [root@ip-172-31-34-108 ec2-user]#file -s /dev/xvdb data | 
Format the volume to ext4 filesystem
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | [root@ip-172-31-34-108 ec2-user]# mkfs -t ext4 /dev/xvdb mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 2621440 blocks 131072 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2151677952 80 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks:         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done | 
Create a directory to mount our new ext4 volume (use any directory name you like)
Make Directory
| 1 2 | [root@ip-172-31-34-108 ec2-user]# mkdir /ktexperts | 
Mount the volume to “ktexperts” directory
| 1 2 | [root@ip-172-31-34-108 ec2-user]# mount /dev/xvdb /ktexperts | 
Verify the disk space in your Linux Server
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | [root@ip-172-31-34-108 ec2-user]# df -h Filesystem      Size  Used Avail Use% Mounted on devtmpfs        475M     0  475M   0% /dev tmpfs           492M     0  492M   0% /dev/shm tmpfs           492M  404K  492M   1% /run tmpfs           492M     0  492M   0% /sys/fs/cgroup /dev/xvda1      8.0G  1.3G  6.8G  16% / tmpfs            99M     0   99M   0% /run/user/1000 /dev/xvdb       9.8G   37M  9.2G   1% /ktexperts | 
Go to Mount Directory and verify files.
| 1 2 3 4 5 6 7 8 9 10 | [root@ip-172-31-34-108 ec2-user]# cd /ktexperts/ [root@ip-172-31-34-108 ktexperts]# ls -l total 16 drwx------ 2 root root 16384 Nov 27 10:25 lost+found [root@ip-172-31-34-108 ktexperts]# | 
Make Files and Directories inside mount directory
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | [root@ip-172-31-34-108 ktexperts]# ls aws  ktexpers1  ktexperts2  ktexperts3  ktexperts4  lost+found [root@ip-172-31-34-108 ktexperts]# touch ktexpers1 ktexperts2 ktexperts3 ktexperts4 [root@ip-172-31-34-108 ktexperts]# ls ktexpers1  ktexperts2  ktexperts3  ktexperts4  lost+found [root@ip-172-31-34-108 ktexperts]# mkdir aws [root@ip-172-31-34-108 ktexperts]# ls ktexpers1  ktexperts2  ktexperts3  ktexperts4  lost+found aws | 
EBS Automount on Reboot
By default on every reboot the EBS volumes other than root volume will get unmounted.
To enable automount, you need to make an entry in the /etc/fstab file
| 1 2 3 4 5 6 | [root@ip-172-31-34-108 ktexperts]# vi /etc/fstab Enter the below command inside the fstab file /dev/xvdf       /newvolume   ext4    defaults,nofail        0       0 | 
Execute the following command to check id the fstab file has any error
| 1 2 | [root@ip-172-31-34-108 ktexperts]# sudo mount -a | 
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates
KTEXPERTS is always active on below social media platforms.
Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform
 
 
		
 Loading...
Loading...


