AWS EC2 - EBS volume and snapshot creation for Linux AMI

Sri
4 min readMar 18, 2024

--

Source: AWS Documentation

1.Create an EBS volume

Login to AWS Management Console > in the Search bar >enter and choose EC2 to open the EC2 Management Console.

  1. In the left navigation pane, choose Instances> your EC2 instance for which EBS has to be attached.
  2. Note the Availability Zone for your EC2 instance instance
  3. In the left navigation pane, for Elastic Block Store, choose Volumes.
  4. Choose Create volume, and configure the following options:
  • Volume type: <your choice> Eg : Volume1
  • Size (GiB): <your choice>
  • Availability Zone: Choose the same as the Availability Zone of your EC2 instance
  • Click Create volume

A new EBS volume is created.

2.Attach and mount an EBS volume to an EC2 instance

1.Attach the new volume to an EC2 instance
  1. Select <your choice> Eg : Volume1 as created above
  2. From the Actions menu, choose Attach volume.
  3. From the Instance dropdown list, choose the the EC2 instance of your choice.
  4. The Device name field is set to /dev/sdf.
  5. Choose Attach volume.
  6. The Volume state of your new volume is now In-use.
2.Mount the new volume to an EC2 instance
  1. Login to your EC2 instance where the volume was attached.
  2. In EC2 terminal, Format the above /dev/sdf device with new Linux file system.
  3. Create a directory to mount the new device
  4. Make an entry in the /etc/fstab file .
# disk free in human readable format
df -h

# make file system of type ext3 on the new volume /dev/sdf
sudo mkfs -t ext3 /dev/sdf

# create a directory
sudo mkdir /mnt/data-store

# mount the new volume
sudo mount /dev/sdf /mnt/data-store

# make an entry in the /etc/fstab file so the volume is
# mounted even after a restart
echo "/dev/sdf /mnt/data-store ext3 defaults,noatime 1 2" |
sudo tee -a /etc/fstab

# view config file
cat /etc/fstab

# create a new file in the mounted new volume
sudo sh -c "echo some text has been written > /mnt/data-store/file.txt"

# display the file
cat /mnt/data-store/file.txt


:'

/dev/sdf /mnt/data-store ext3 defaults,noatime 1 2

• /dev/sdf: specifies the device or disk partition to be mounted.
• /mnt/data-store: specifies the mount point, which is the directory
where the device will be mounted.
• ext3: specifies the file system type of the device.
• defaults,noatime: These are mount options specifying
default mount options along with the noatime option, which disables
access time updates to improve performance.
• 1: This field specifies whether the file system should be dumped
by the dump command. A value of 1 indicates that it should be backed up.
• 2: This field specifies the order in which file systems should be
checked by the fsck command during system boot.
'

Note : /etc/fstab is a system configuration file in Linux used to define how disk partitions and storage devices should be mounted during system boot.

3.Create a snapshot of an EBS volume

Amazon EBS snapshots are stored in Amazon Simple Storage Service (Amazon S3) for durability. New EBS volumes can be created out of snapshots for cloning or restoring backups. Amazon EBS snapshots can also be shared among Amazon Web Services (AWS) accounts or copied over AWS Regions.

  1. On the EC2 Management Console> choose Volumes, > select Volume1 <Your_choice>.
  2. From the Actions menu, choose Create snapshot.
  3. In the left navigation pane, choose Snapshots.
  4. Snapshot status :After completion, the status changes to Completed.

Only used storage blocks are copied to snapshots, so empty blocks do not use any snapshot storage space.

4.Create an EBS volume from a snapshot

Data stored in a snapshot can be retrieved , by restoring the snapshot to a new EBS volume.

 1. Create a volume by using the snapshot

On the EC2 Management Console, select My Snapshot >From the Actions menu>choose Create volume from snapshot> <your_choice_name > eg:RestoredVolume

2.Attaching the restored volume to the EC2 instance

Select RestoredVolume > From the Actions menu, choose Attach volume>From the Instance dropdown list, choose the EC2 instance of your choice> set the Device name to /dev/sdg >Choose Attach volume.

3.Mounting the restored volume to the EC2 instance

Login to the Ec2 instance where the restored new voume is mounted.In the Linux terminal of EC2 instance,

1. Create a directory for mounting the new restored volume

sudo mkdir /mnt/data-store2

2. mount the new volume

sudo mount /dev/sdg /mnt/data-store2

--

--