Map EBS Storage with Linux EC2 instance in AWS

Map EBS Storage with Linux EC2 instance in AWS

In this blog, we are going to configure the EBS Storage to the redhat linux EC2 instance in Amazon web services.

Following are the steps

1. Create an EC2 instance of Redhat linux from AWS Console.

2. Create addition volume of EBS storage from AWS Console.

3. Attach the EC2 instance with EBS volume from EBS tab by right click on EBS Storage which is created in step 2.
Note: Both EC2 instance and EBS volume should be in same availability zone.

4. Open the putty session with private key.

5. Now first step is to check the disk present as shown below before attached the new EBS volume in step 3

-- command executed before step 3 it show only one volume
[ec2-user@ip-172-31-7-21 ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 10G 0 disk
├─xvda1 202:1 0 1M 0 part
└─xvda2 202:2 0 10G 0 part /

6. After step 3 executed, command show the volume is attached

[ec2-user@ip-172-31-7-21 ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 10G 0 disk
├─xvda1 202:1 0 1M 0 part
└─xvda2 202:2 0 10G 0 part /
xvdf 202:80 0 1G 0 disk

7. Switch to root user

sudo su -

8. Check the file system type which need to be formatted and already existed/used by Linux system

[root@ip-172-31-7-21 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 10G 0 disk
├─xvda1 202:1 0 1M 0 part
└─xvda2 202:2 0 10G 0 part /
xvdf 202:80 0 1G 0 disk
[root@ip-172-31-7-21 ~]#
[root@ip-172-31-7-21 ~]# file -s /dev/xvda
/dev/xvda: x86 boot sector; partition 1: ID=0xee, active, starthead 0, startsector 1, 20971519 sectors, code offset 0x63
[root@ip-172-31-7-21 ~]#
[root@ip-172-31-7-21 ~]# file -s /dev/xvda1
/dev/xvda1: data
[root@ip-172-31-7-21 ~]# file -s /dev/xvda2
/dev/xvda2: SGI XFS filesystem data (blksz 4096, inosz 512, v2 dirs)
[root@ip-172-31-7-21 ~]#

Note: It show that linux system is using XFS filesystem.

8. Make a file system XFS as shown below example:

[root@ip-172-31-7-21 data1]# mkfs.xfs /dev/xvdf
meta-data=/dev/xvdf isize=512 agcount=4, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=262144, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

Note: You can make other filesystem also like ext4 of one partition

[root@ip-172-31-7-21 ~]# mkfs -t ext4 /dev/xvdg
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
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

9. Mount the device to a new folder

mkdir /data1
mount /dev/xvdf /data1

10. Now check the lsblk command for output

[root@ip-172-31-7-21 data1]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 10G 0 disk
├─xvda1 202:1 0 1M 0 part
└─xvda2 202:2 0 10G 0 part /
xvdf 202:80 0 1G 0 disk /data1

11. You can check with df -Th command for file format:

[root@ip-172-31-7-21 data2]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/xvda2 xfs 10G 925M 9.1G 10% /
devtmpfs devtmpfs 474M 0 474M 0% /dev
tmpfs tmpfs 496M 0 496M 0% /dev/shm
tmpfs tmpfs 496M 13M 483M 3% /run
tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup
tmpfs tmpfs 100M 0 100M 0% /run/user/1000
tmpfs tmpfs 100M 0 100M 0% /run/user/0
/dev/xvdf xfs 976M 2.6M 907M 1% /data1

12. For make change permanent add entry in /etc/fstab file.
vi /etc/fstab

# /etc/fstab
# Created by anaconda on Fri Mar 23 17:41:14 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=50a9826b-3a50-44d0-ad12-28f2056e9927 / xfs defaults 0 0
/dev/xvdf /data1 xfs defaults 0 0

13. Check the entry is good

mount -a
Example:
[root@ip-172-31-7-21 data2]# mount -a
[root@ip-172-31-7-21 data2]#

Note: If you type wrong name like /dev/svdf then you got following message
[root@ip-172-31-7-21 data2]# mount -a
mount: special device /dev/svdg does not exist

14. Now your drive is ready to use.

For Unmount the drive

[root@ip-172-31-7-21 data2]# umount /data1
[root@ip-172-31-7-21 data2]#

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.