AWS - EBS
Elastic Block Storages (EBS) are like hard drives with specific type (I/O performance) and capacity (GB).
- Root volume is the EBS where the main operating system resides (
- Root volume device is always
- One EC2 can have multiple EBSs mounted, but only one as root.
- You can find additional attached EBSs at
# shows all attached volumes
sudo fdisk -l
# non-root volumes must be formatted and mounted so they can be used
sudo mkfs -t ext4 /dev/xvdf
sudo mkdir /mnt/my-volume
sudo mount /dev/xvdf /mnt/my-volume
# before detaching a volume, unmount it
# all data stored in the volume will be kept intact
sudo umount /mnt/my-volume
# shows all mounted (usable) volumes
They can be attached to or detached from EC2 instances.
EBS volumes are comparable with RAID1. Your data is saved to multiple disks in the background so the risk of losing data is minuscule. Even though EBS volumes officially offer 99.999% availability, it's a good idea to create backups from time to time.
EBS volumes allow snapshots. This is the easiest way to backup EBS volume. Don't create snapshots of attached and mounted volumes though, might cause problems with writes.
# if you ever have to snapshot a attached volume though:
fsfreeze -f /mnt/my-volume # stop writes
# create the snapshot
fsfreeze -u /mnt/my-volume # resume writes
You can create new volumes based on snapshots. Snapshots are not volumes themselves, they are just compressed data to create new volumes. This is how AMIs work, they are just snapshots that are create to volumes when instance is started; with some metadata like suggested instance type.
EC2 snapshots are regional. They are stored in S3 so you can easily use snapshot to duplicate a specific server to another availability zone.
You can benchmark volume performance with
# the `MB/s`on responses indicates read or write performance
sudo dd if=/dev/zero of=/mtn/my-volume/tempfile bs=1M count=1024 # write
echo 3 | sudo tee /proc/sys/vm/drop_caches # flushes cache for the read test
sudo dd if=/mtn/my-volume of=/dev/null bs=1M count=1024 # read
There are three EBS volume types:
- Magnetic: legacy tier.
- General Purpose: default you should be using, they go a long way.
- Provisioned IOPS: for I/O intensive computation.
Some EC2 instances types also have instance stores. These are temporary hard drives that are always destroyed on termination. The cannot be detached and usually offer good I/O performance. The performance is 3 - 4 times what general purpose usually offers.
# the easiest way to backup an instance store is S3
aws s3 sync /media/ephemeral0 s3://bucket/backups
- AWS in Action, Michael Wittig and Andreas Wittig