EBS is a AWS service design to use with EC2, EBS volumes are replicated within an Availability Zone (AZ) and can be escalate to petabytes of data.

You can choose from six different volume types to balance optimal price and performance.

In this post we going to create an EBS and use it in a instance, and we going to test the portability between instances.

Requirements

  • AWS account

Hands-On

  1. On the AWS Management Console go to EC2

2. Go to Volumes

3. Click on Create Volume

4. Select General Purpose SSD (gp2), 1GB size, 100 IOPS, and any Availability Zone is fine, but remember it for later click on Create Volume,

5. Close and you will have the volume listed on Volumes

6. Ok now create a new instance, go to instances

7. Click on Launch instances

8. Select Amazon Linux 2 AMI 64-bits

9. Select t2.micro and click on Next: Configure instance Details

10. In the next page, select 1 instance, you can leave all on defaults except the subnet, this need to be the same AZ as the volume, and check that you have Auto-Assign Public IP enabled, click on Review and Launch

11. Review the configuration and click on Launch

12. In the next window, create a new key pair, give it a name, and download it, then click on Launch Instances

13. You will see the Launch Status, click on View instances

14. In the instances page, remember the last 4 digits of the instance ID you just launch, in my case is dd8a

15. Go to Volumes

16. And you will have two volumes, the instance volume and the 1 GB volume we create, select the 1GB volume, click on Actions and then select Attach Volume

17. On the next page, select the Instance ID, and the Device, this last one, you can leave it as default and click on attach

18. Now go back to instances

19. Select the Instance ID, and click on Connect

20. Copy the command to connect via ssh client

21. Open a ssh client and connect to the instance with the pem file we downloaded, make sure you have the pem file on the terminal working directory.

chmod 400 ebs-lab.pem
ssh -i "ebs-lab.pem" ec2-user@ec2-3-16-70-36.us-east-2.compute.amazonaws.com
remember to use your key pair file name and command, this is not going to be the same

22. Excecute sudo lsblk to see the devices attach to the instance

sudo su -
lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   8G  0 disk 
└─xvda1 202:1    0   8G  0 part /
xvdf    202:80   0   1G  0 disk

In this example, I have two devices, the first called xvda it have 1 partition called xvda1 and is mounted on /, and I have the 1GB device and is not mounted

23. Format the new device so we can use it

mkfs.xfs /dev/xvdf
meta-data=/dev/xvdf              isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, 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

24. Create a folder and mount the volume

mkdir /ebs-mount
mount /dev/xvdf /ebs-mount/

25. Go to the folder and create a file for testing.

cd /ebs-mount
touch testing.txt
echo "this is a simple text" > testing.txt

26. In the AWS Management Console, go to Volumes

27. Selec the 1GB volume Click on Actions and click on Detach Volume

28. Confirm the detach

29. Go to EC2, instances, select the instance, select Instance state and click on Terminate instance.

30. Now lets launch another instance, click on Launch instances

31. Selec the Amazon Linux AMI 64-bits

32. Select the t2.micro type and select Next

33. in the instance details as before select the AZ of the Volume, make sure you have Auto-assign Public IP enabled and all the other by default, and click on Review and Launch

34. Review the configuration and click on Launch

35. Select the existing key pair we created the last time, check the checkbox and click on Launch instances

36. Click on View Instances and like the last time see what are the last 4 digits, in my case 0a8d

37. Go to Volumes

38. Select the EBS of 1 GB and click on Actions, and select Attach Volume

39. Select the new instances and click on Attach

40. As before, go to Instances, select the instance and click on Connect

41. Copy the command to connect the instance

42. Use the command to connect using a terminal o a ssh client

ssh -i "ebs-lab.pem" ec2-user@ec2-18-219-28-105.us-east-2.compute.amazonaws.comThe authenticity of host 'ec2-18-219-28-105.us-east-2.compute.amazonaws.com (18.219.28.105)' can't be established.
ECDSA key fingerprint is SHA256:w9uFJH3R/V9wgX8VgB/1MXZQVnrGPyw3qONsmAHoYEo.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ec2-18-219-28-105.us-east-2.compute.amazonaws.com,18.219.28.105' (ECDSA) to the list of known hosts.

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
7 package(s) needed for security, out of 19 available
Run "sudo yum update" to apply all updates.

43. From the instance repeat the process of creating a folder and mount the partition, this time it doest not need to be format

sudo su -
mkdir /ebs-mount
lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   8G  0 disk 
└─xvda1 202:1    0   8G  0 part /
xvdf    202:80   0   1G  0 disk
mount /dev/xvdf /ebs-mount/

44. Go to the folder and confirm the data is there.

cd /ebs-mount
cat testing.txt
This is a simple text

Great with this we finish this lab, in the next post we going deeper in the AWS Services.

Clean-UP

  1. In EC2 Instances, Select running the instances and terminate

2. In EC2, Volumes, select the volumes and click on Delete Volume and confirm

3. On EC2, Security groups, delete the security groups used for the lab (usually named launch-wizard-N) and confirm

4. On EC2 Key Pairs, delete the key pairs used in the lab