In this post we will learn how we can Attach And Mount EBS Volume To EC2 Linux Instance in AWS. You might be knowing that EC2 is nothing but an Elastic compute cloud which is a virtual computing environment (similar to virtual machine in vmware ). EBS(Elastic block store) is nothing but an extra volume or disk that can be attach to Ec2(virtual compute) for mounting extra mount point in linux.
So Lets begin with the steps to Attach And Mount EBS Volume To EC2 Linux Instance.
Step 1 : Click on “ELASTIC BLOCK STORE–> Volumes” from the left pane in the Ec2 managment console.
Step 2: Now click on create volume button on the top. Select space as per your requirement. I have selected 2 Gb of space , that means we are assigning Lun of 2Gb to our Ec2 Linux instance. Make sure you select same AZ as of the Ec2 instance to avoid the latency.
Step 3. You will notice new EBS volume being created with status as available.
Step 4: Now Next step is to attach And mount EBS Volume To EC2 Linux Instance. For this select newly created EBS volume right click on it and select the “attach volume” option. Select instance and click attach button.
Step 4: Now login to Linux Ec2 instance to check and confirm newly attached EBS volume with fdisk -l or lsblk command as below:
[root@ip-XXXXXX ~]# fdisk -l WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. Disk /dev/xvda: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: gpt # Start End Size Type Name 1 2048 4095 1M BIOS boot parti 2 4096 20971486 10G Microsoft basic Disk /dev/xvdf: 2147 MB, 2147483648 bytes, 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes [root@ip-XXXX~]# 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 2G 0 disk
You will notice that we have new xvdf disk with capacity 2G is added to linux server.
Step 5: Format the EBS volume as ext4 filesystem using the following command.
[root@ip-XXXXXXX ~]# mkfs.ext4 /dev/xvdf 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 131072 inodes, 524288 blocks 26214 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=536870912 16 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
However if you would like to use LVM volume instead of above whole disk approach you can follow steps here.
Step 6: Create one directory say “/EBS_volume” as an mount point and mount it using mount command as below:
# mkdir /EBS_volume # mount /dev/xvdf /EBS_volume # df -h /EBS_volume Filesystem Size Used Avail Use% Mounted on /dev/xvdf 2.0G 6.0M 1.8G 1% /EBS_volume
To unmount the volume, you have to use the following command.
# umount /EBS_volume
How to mount it automatically in next reboot?
You can see that in step 6 df command shows that new mount point is successfully mounted , however this mount point is not persistent across reboot meaning that , /EBS_volume will not mounted automatically after next reboot. To avoid this case follow next step.
Step 7: Add below entry in the /etc/fstab file as below:
/dev/xvdf /EBS_volume ext4 defaults,nofail 0
To learn more about /etc/fstab file follow steps here.
Step 8: Now mount it using below command
# mount -a
If you do not come across any error after this commands means all is Ok. Now, on every reboot this /EBS_volume will get mounted automatically.
That’s how we can Attach And Mount EBS Volume To EC2 Linux Instance.
Leave a Reply