Create and Attach EBS Volumes
- Authors
- Name
- Michael Bui
Overview
EBS volumes are block level storage devices that can attach to instances. You can use these volumes similar to how you would use a physical hard drive. EBS volumes must be in the same availability zone of the EC2 instance it attaches to.
In this lab, we'll create an EBS volume & attach it to an EC2 instance. We'll then detach it from the EC2 instance and connect it to another EC2 instance.
Creating the EBS Volume
- From
EC2
go toVolumes
->Create Volume
- Give the volume a size - 8 GiB
- Select the availabiliy zone this EBS Volume will reside in - us-west-2a
- Create the volume
Attaching to EC2 Instances
- We have 3 instances:
Lab-1
,Lab-2
, andLab-3
Lab-1
andLab-2
are in availability zone 2a &Lab-3
is in availability zone 2b
- We'll first attach the EBS Volume to
Lab-1
- Navigate to the EBS volume and select
Attach volume
- Select an instance to attach the volume to
- Notice that
Lab-3
is not listed because it is not running in the same availability zone as the EBS volume
Verify EBS Volume is Attached
- SSH into the
Lab-1
Instance - Use
lsblk
command to list disks available on the EC2 instance - The attached EBS volume is /dev/xvdf which contains no partitions
Using the EBS Volume
Documentation for making EBS volumes available for use here
- New volumes are raw block devices and need a file system before we can mount and use them
- Format the EBS volume as xfs by running
sudo mkfs -t xfs /dev/xvdf
- Mount the volume
- Create a directory with
sudo mkdir /data
- Mount with
sudo mount /dev/xvdf /data
- Go into
/data
and create some files
Moving EBS Volume
- Go into the EBS Volume and select
Detach volume
- We'll now reattach the volume to
Lab-2
- Inside
Lab-2
we can runlsblk
to see our attached volumes - Create a mount point with
sudo mkdir /data
and mount the volume - Inside our
Lab-2
instance we see that the files we made when the EBS volume was attached toLab-1
have carried over