By the end you'll know
- The three kinds of storage beside a server, EBS, EFS and instance store, and when each fits
- How to add, format, mount and grow an EBS disk, and why Linux calls it something else
- Why an EBS disk can't move between zones, and how a snapshot gets around that
- What LVM and RAID do, when each is worth using on AWS, and how to snapshot several disks at once
- The EBS disk types and what they cost
- How two servers in two zones share one EFS file system, and the two traps that caught this lab
- What gets left behind, and billed, when a server is deleted
Before you start
- You need: the
juniper-ryeprofile from Lesson 4, signed in, and Lessons 10 and 11: the lab talks to its servers with Run Command. - The script:
disk-lab.shfrom the practice folder'slesson-16. Everything it creates is namedjr-lesson16-*and taggedlesson=16, and itsdeletestep removes it. - How the script talks to AWS: only through the AWS CLI. The few lines of Python in it just turn the CLI's JSON into readable tables and never connect to AWS; boto3, AWS's Python library, comes in Lesson 20.
- To see every call the script makes, put
SHOW=1in front of any step, such asSHOW=1 ./disk-lab.sh disk. The lesson's "By hand" section lists them all too. - Where you run things: your own machine, labeled (Your machine). The commands the script runs on the servers are labeled (On the server) where they're shown.
- Every output below is from real runs on November 10, 2026. The EFS step took four runs to get right, and the lesson shows what went wrong in the first; the LVM and RAID steps are from a fifth and sixth.
Disks and snapshots outlive the server
Deleting a server deletes its root disk, but not the disks you added, and never its snapshots. Those keep billing every month, attached to nothing, and nobody notices because the server is gone. This lab's delete step removes them, and its check counts any unattached disks in the Region. Run it.
The short version
- EBS (Elastic Block Store) is a disk for one server, in one zone. It survives the server, grows while in use, and comes in types priced by speed.
- A snapshot is a copy of an EBS disk, kept across the whole Region, so it can become a new disk in any zone. After the first, each snapshot stores only what changed.
- EFS (Elastic File System) is a shared folder that many Linux servers in many zones use at once, and it grows and shrinks by itself.
- Instance store is a disk inside the host machine: fast, free with the server, and wiped when the server stops.
- LVM pools several disks into one file system, for more size or speed than one disk, or to move data between disks while it's in use. RAID 0 stripes them for speed; RAID 1, 5 and 6 aren't worth it on EBS.
- Always check a mount worked. If it didn't, the folder is still there, on the wrong disk.
What this lesson costs
| Part | Cost |
|---|---|
| Two small servers with public IPv4 addresses and 8 GiB root disks | About $0.03 an hour together |
| EBS gp3 data disks, 2 to 4 GiB | $0.08 per GB a month, by the hour: fractions of a cent |
| A snapshot | $0.05 per GB a month, for the blocks used: a few MB |
| EFS Standard | $0.30 per GB a month, for what's stored: a few KB |
| This lesson | A few cents a run, from credits |
Three kinds of storage beside a server
Lesson 15's S3 holds files you fetch over the internet. A server also needs storage it can use as a disk: to boot from, to run a database on, to write logs to. AWS has three kinds:
| EBS | EFS | Instance store | |
|---|---|---|---|
| What it is | A network disk for one server | A shared network folder | A disk in the physical host |
| Servers at once | One (a few, for special types) | Thousands | Its own only |
| Where it lives | One zone | Every zone in the Region | That one host |
| Survives the server stopping | Yes | Yes | No: wiped |
| Size | You choose, and can grow it | Grows and shrinks with what's stored | Fixed by the instance type |
| Paid for | Size provisioned, used or not | What's stored | Included in the server's price |
| Fits | Boot disks, databases, almost everything | Files several servers need at once | Caches and scratch space |
The Linux track's Disks, storage and memory lesson covers what's happening on the server's side: block devices, file systems and mounting.
Is it allowed, and what does it cost?
(Your machine)
cd ~/Apps/aws-practice/lesson-16
chmod +x disk-lab.sh
./disk-lab.sh fence
== Is this allowed in us-east-2? (dry runs: nothing is created)
launch a t4g.micro server allowed
create a 2 GiB gp3 disk allowed
snapshot a disk allowed (the made-up disk ID was rejected, as expected)
EFS allowed (EFS has no dry run; this reads instead)
== What it costs, in us-east-2
2 small servers, public IPv4, 8 GiB root disks: about $0.03 an hour together
EBS gp3 disk: $0.08 per GB a month, by the hour: a 4 GiB disk is about $0.0004 an hour
EBS snapshot: $0.05 per GB a month, for the blocks actually used: a few MB here
EFS Standard: $0.30 per GB a month, for what's stored: a few KB here
this lab: a few cents, if delete runs the same day
Note the last two prices. A GB on EFS costs nearly four times a GB on EBS, and thirteen times a GB in S3 Standard. It's priced for convenience, so it holds what needs sharing, not everything.
Two servers, and the disk each came with
(Your machine)
./disk-lab.sh build
== A VPC with a public subnet in each of two zones
== A server in each zone: public address for its own updates, no inbound rules (Run Command reaches it)
jr-lesson16-server-a: t4g.micro in us-east-2a
us-east-2b has no t4g.micro capacity to spare: trying the next Free Tier size
jr-lesson16-server-b: t4g.small in us-east-2b
== Waiting for each to check in with Systems Manager
jr-lesson16-server-a: online
jr-lesson16-server-b: online
== The disk each server came with
/dev/xvda: vol-0e9d3385e06efdd16, deleted with the server: True
8 GiB gp3, 3000 IOPS, 125 MB/s, encrypted: False
us-east-2b was short of t4g.micro servers again, as in Lessons 12 and 13, and the script kept the zone and took the next size. The servers sit in public subnets so they can download updates without a NAT gateway, but their security group has no inbound rules: Run Command reaches them, as in Lesson 11, and nothing else can.
Every server boots from an EBS disk, its root volume. Two things in the last lines matter:
- "Deleted with the server: True" is the
DeleteOnTerminationsetting. Root disks default to true. Disks you attach yourself default to false, which is why they outlive the server. - "Encrypted: False". EBS encrypts for free, with no speed cost, but only if asked. EC2 > Settings > EBS encryption > Always encrypt new EBS volumes turns it on for every new disk in the Region; in real accounts, it's the first thing to switch on. The lab's data disk asks for it.
3,000 IOPS and 125 MB/s are gp3's included speed: 3,000 reads or writes a second, and 125 MB a second, whatever the size. More of either can be bought separately.
An EBS disk
In the console: EC2 > Volumes > Create volume, in the same Availability Zone as the server. Then select it > Actions > Attach volume, and pick the server.
(Your machine)
./disk-lab.sh disk
== A 2 GiB gp3 disk in us-east-2a, attached to jr-lesson16-server-a
vol-0c840c73504d3838d, attached as /dev/sdf
== On the server: what Linux sees, then format it, mount it, and write a file
Linux calls it /dev/nvme1n1
NAME SIZE TYPE MOUNTPOINTS
nvme0n1 8G disk
├─nvme0n1p1 8G part /
└─nvme0n1p128 10M part /boot/efi
nvme1n1 2G disk
Filesystem Size Used Avail Use% Mounted on
/dev/nvme1n1 2.0G 47M 1.9G 3% /data
total 4
-rw-r--r--. 1 root root 58 Nov 11 03:42 recipe.txt
== Attaching the same disk to jr-lesson16-server-b, in us-east-2b
(InvalidVolume.ZoneMismatch): The volume 'vol-0c840c73504d3838d' is not in the same availability zone as instance 'i-0516ca22bcb3bf364'
== Growing it from 2 GiB to 4 GiB, while it's mounted and in use
AWS: optimizing
Linux before growing the file system:
NAME SIZE
nvme1n1 4G
/dev/nvme1n1 2.0G 47M 1.9G 3% /data
after xfs_growfs:
/dev/nvme1n1 4.0G 62M 3.9G 2% /data
The AWS side was two calls, then the server did the rest:
aws ec2 create-volume --availability-zone us-east-2a --size 2 --volume-type gp3 --encrypted
aws ec2 attach-volume --volume-id vol-0c840c73504d3838d --instance-id "$SERVER_A" --device /dev/sdf
(On the server)
D=$(lsblk -dno NAME,SERIAL | grep vol0c840c73504d3838d | cut -d' ' -f1)
mkfs.xfs /dev/$D # format it: only ever on a new, empty disk
mkdir -p /data && mount /dev/$D /data # make a folder, and put the disk there
| Step | Does |
|---|---|
create-volume | Makes an empty disk in one zone. --encrypted because the account default is off. |
attach-volume ... --device /dev/sdf | Connects it to the server, under a name that turns out not to matter |
lsblk -dno NAME,SERIAL | Lists the server's disks with serial numbers. An EBS disk's serial is its volume ID without the dash. |
mkfs.xfs | Formats it with XFS, Amazon Linux's default file system. Running it on a disk with data wipes the data. |
mount /dev/$D /data | Makes the disk appear at /data |
Linux calls it something else
The script asked for /dev/sdf, and Linux called it /dev/nvme1n1. Current EC2 servers connect EBS disks as NVMe devices, and Linux numbers those in the order it finds them, so the numbers can change after a reboot. Amazon Linux adds the name you asked for as a link to the real device, which is why LVM, later, lists /dev/sdg; most other distributions don't. That's why the script finds the disk by its serial number instead, which works everywhere. In a real server, the line in /etc/fstab that mounts the disk at every boot uses the file system's UUID, from blkid, for the same reason, plus the nofail option, so a missing disk doesn't stop the server booting.
One zone, and no further
An EBS disk lives in one Availability Zone and can only attach to servers in that zone. AWS said so plainly: ZoneMismatch. The disk is a network device inside one zone's data centers, close to the servers that use it, which is what makes it fast. The snapshot section is how data gets to the other zone.
Growing it while it's in use
modify-volume grew the disk from 2 to 4 GiB while it was mounted, with no restart. Then two things happened, and both are on the exam:
- AWS said
optimizing, and the disk was usable straight away. Optimizing means AWS is still moving data in the background; it can take hours on big disks, but nothing waits for it. - Linux saw a 4 GiB disk, but the file system was still 2 GiB. The disk grew; the file system on it didn't, until
xfs_growfsstretched it. For ext4 file systems, the command isresize2fs, and for a root disk with partitions,growpartfirst.
Disks only grow. To shrink one, you make a smaller disk and copy the data across. And after a change, a disk can't be changed again for six hours.
The types of EBS disk
| Type | Kind | Per GB a month | Speed | Fits |
|---|---|---|---|---|
| gp3 | SSD | $0.08 | 3,000 IOPS and 125 MB/s included; up to 80,000 IOPS and 2,000 MiB/s sold separately | Almost everything: the default |
| gp2 | SSD | $0.10 | Rises with size: 3 IOPS per GB | Nothing new. gp3 is cheaper and faster. |
| io2 Block Express | SSD | $0.125, plus each IOPS | Up to 256,000 IOPS, set exactly | Busy databases that need steady, guaranteed speed |
| st1 | Hard disk | $0.045 | Fast for long reads and writes, slow for small ones | Big logs, data processing |
| sc1 | Hard disk | $0.015 | The slowest | Cold data read rarely, in bulk |
The exam's patterns: gp3 unless told otherwise; io2 for the database that needs guaranteed IOPS; st1 for big sequential work; sc1 for the cheapest. Hard-disk types can't be boot disks.
Snapshots
In the console: EC2 > Volumes > select the disk > Actions > Create snapshot. Then Snapshots > select it > Actions > Create volume from snapshot, and pick any zone.
(Your machine)
./disk-lab.sh snap
== A snapshot of jr-lesson16-data-a (sync first, so everything written is on the disk)
synced
snap-0e0428866c45ad2e6: completed after 61 seconds
state completed, from a 4 GiB disk, tier standard, encrypted True
== A new disk from the snapshot, in us-east-2b this time, attached to jr-lesson16-server-b
vol-057008e1805f1a467, made from snap-0e0428866c45ad2e6
== On jr-lesson16-server-b: mount it (no formatting) and read the recipe
/dev/nvme1n1 4.0G 62M 3.9G 2% /data
Sourdough: 500g flour, 350g water, 100g starter, 10g salt
aws ec2 create-snapshot --volume-id vol-0c840c73504d3838d --description "Juniper & Rye data disk"
aws ec2 create-volume --availability-zone us-east-2b --snapshot-id snap-0e0428866c45ad2e6 --volume-type gp3
A snapshot is a point-in-time copy of an EBS disk, stored by AWS across the whole Region rather than in one zone. That's what got the recipe from us-east-2a to us-east-2b: snapshot in one zone, new disk from it in another, mounted without formatting, and the file was there.
| Snapshots are | Means |
|---|---|
| Incremental | The first copies every used block; each one after copies only blocks that changed. Delete an old one and AWS keeps whatever the others still need. |
| Of used blocks only | A 4 GiB disk holding 62 MB makes a snapshot of about 62 MB, billed at $0.05 per GB a month |
| Point in time | Whatever's on the disk when it starts. The lab ran sync first, so nothing still in memory was missed. |
| Encrypted like their disk | And disks made from them are encrypted too |
| Loaded lazily | A disk from a snapshot is usable at once, but each block is fetched on first read, so it starts slow. Fast Snapshot Restore pays to skip that. |
| The basis of AMIs | A machine image, Lesson 10's starting point, is snapshots plus settings |
Snapshots can also be copied to another Region or account, for disaster recovery; the free plan's one-Region rule stops that here. Old snapshots can go to the archive tier, at a quarter of the price, if you can wait a day or more to restore them. And nobody takes snapshots by hand for long: AWS Backup or Data Lifecycle Manager takes them on a schedule and deletes old ones, which is Lesson 19.
LVM: several disks as one
LVM (Logical Volume Manager) is a layer of Linux between disks and file systems. Disks become physical volumes, pooled into a volume group, which is carved into logical volumes, and each logical volume gets a file system like any disk. The file system no longer cares how many disks are underneath, or which.
(Your machine)
./disk-lab.sh lvm
From a fifth run, with new servers:
== Two 1 GiB disks for LVM, attached to jr-lesson16-server-a
vol-0ec1ab0524bdf761b and vol-0ae8a33b25e173142
== On the server: both disks into one volume group, one logical volume across them, one file system
Physical volume "/dev/nvme1n1" successfully created.
Physical volume "/dev/nvme2n1" successfully created.
Volume group "bakery-vg" successfully created
Logical volume "orders" created.
-- the disks, and what sits on them:
NAME SIZE TYPE MOUNTPOINTS
nvme1n1 1G disk
└─bakery--vg-orders 2G lvm /orders
nvme2n1 1G disk
└─bakery--vg-orders 2G lvm /orders
-- physical volumes:
PV VG PSize PFree
/dev/sdg bakery-vg 1.00g 0g
/dev/sdh bakery-vg 1.00g 0g
-- the file system:
/dev/mapper/bakery--vg-orders 2.0G 47M 1.9G 3% /orders
== Running low: add a third 1 GiB disk, and grow the volume onto it while it's mounted
vol-09f593921ad1426b1
Physical volume "/dev/nvme3n1" successfully created.
Volume group "bakery-vg" successfully extended
-- the volume group:
VG #PV VSize VFree
bakery-vg 3 2.99g 0g
-- the logical volume:
LV VG LSize Devices
orders bakery-vg 2.99g /dev/sdg(0)
orders bakery-vg 2.99g /dev/sdh(0)
orders bakery-vg 2.99g /dev/sdi(0)
-- the file system:
/dev/mapper/bakery--vg-orders 3.0G 54M 2.9G 2% /orders
-- still there:
order,item,qty
== A snapshot of every data disk on the server, all at the same moment
synced
snap-0989df22d2ae5e778 of vol-09f593921ad1426b1 1 GiB started 2026-11-11T04:33:26.903000+00:00
snap-05e8758ff1b267e72 of vol-0ae8a33b25e173142 1 GiB started 2026-11-11T04:33:26.903000+00:00
snap-0d58dfa8bdd38e327 of vol-0ec1ab0524bdf761b 1 GiB started 2026-11-11T04:33:26.903000+00:00
(On the server), after attaching the disks:
pvcreate /dev/nvme1n1 /dev/nvme2n1 # mark both disks for LVM
vgcreate bakery-vg /dev/nvme1n1 /dev/nvme2n1 # pool them
lvcreate -n orders -l 100%FREE bakery-vg # one volume, all the space
mkfs.xfs /dev/bakery-vg/orders && mount /dev/bakery-vg/orders /orders
pvcreate /dev/nvme3n1 # later: a third disk
vgextend bakery-vg /dev/nvme3n1 # add it to the pool
lvextend -l +100%FREE --resizefs /dev/bakery-vg/orders # grow the volume and its file system, mounted
| Command | Does | See it with |
|---|---|---|
pvcreate | Marks a disk as a physical volume, LVM's raw material | pvs |
vgcreate, vgextend | Pools physical volumes into a volume group, or adds one to it | vgs |
lvcreate -l 100%FREE | Carves a logical volume from the group: here, all of it | lvs |
lvextend --resizefs | Grows the logical volume, and the file system on it, in one step, while mounted | df -h |
Two 1 GiB disks became one 2 GiB file system: lsblk shows the same logical volume, bakery--vg-orders, on both. A third disk took it to 3 GiB without unmounting, and the file written first was still there. lvs shows the volume spread across all three, /dev/sdg, /dev/sdh and /dev/sdi.
When LVM earns its place on AWS
On a server in a data center, LVM is how you grow anything. On AWS, a single EBS disk grows by itself, so LVM is for the cases a single disk doesn't cover:
| Use | Why one EBS disk isn't enough |
|---|---|
| A file system bigger than one disk | A gp3 disk stops at 64 TiB, raised from 16 TiB in 2025 |
| More speed than one disk | A gp3 disk stops at 80,000 IOPS and 2,000 MiB/s. Striping, with lvcreate -i, spreads every write across several disks to add theirs together. |
| Grow again within hours | An EBS disk can only be changed once every six hours; adding another disk can happen any time |
| Moving data to a new disk while it's in use | pvmove copies a volume's data from one disk to another, mounted and running. It's the standard way onto an encrypted disk, since EBS can't encrypt a disk in place, or onto a different type. |
Separate mounts for /var, /var/log, /tmp | Hardened builds, like the CIS benchmarks, require them, so a runaway log can't fill the root disk. LVM carves them from one disk and moves space between them later. Red Hat family images set up LVM by default. |
And when not to bother: one disk that just needs to grow. modify-volume and xfs_growfs, as above, is simpler, and one fewer layer to understand at 3 a.m.
RAID on EBS
RAID (redundant array of independent disks) combines disks at a lower level than LVM, with mdadm on Linux. Its levels do different jobs, and on EBS only one of them is worth it:
| Level | Does | On EBS |
|---|---|---|
| RAID 0, striping | Splits every write across the disks, adding their speed together. Lose one disk and the whole array is lost. | Yes, for speed, as AWS's own guidance says. LVM striping is the same idea. |
| RAID 1, mirroring | Writes everything to two disks | No. Every EBS disk is already copied within its zone, so mirroring doubles every write for little gain. Snapshots are the protection. |
| RAID 5 and 6, parity | Spreads data plus check information so one or two disks can fail | No. The parity writes use up a large share of the disks' IOPS. |
(Your machine)
./disk-lab.sh raid
From a sixth run:
== Three empty 1 GiB gp3 disks on jr-lesson16-server-a: one alone, two to stripe (each includes 125 MB/s)
alone: vol-06aeb2858b9f4f28f striped: vol-0ef03b3822d4ac14a and vol-009a592dd2ca9afdd
== On the server: write 512 MB straight to each, skipping the memory cache (oflag=direct)
-- one disk, /dev/nvme1n1:
536870912 bytes (537 MB, 512 MiB) copied, 3.09265 s, 174 MB/s
-- the RAID 0 array:
md0 : active raid0 nvme3n1[1] nvme2n1[0]
2093056 blocks super 1.2 512k chunks
-- two disks striped, /dev/md0:
536870912 bytes (537 MB, 512 MiB) copied, 1.70363 s, 315 MB/s
(On the server)
dd if=/dev/zero of=/dev/nvme1n1 bs=1M count=512 oflag=direct # one disk
mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/nvme2n1 /dev/nvme3n1
cat /proc/mdstat # the array
dd if=/dev/zero of=/dev/md0 bs=1M count=512 oflag=direct # two disks striped
Two disks striped wrote at 315 MB/s, against 174 MB/s for one: about 1.8 times as fast. oflag=direct skipped the server's memory cache, so the numbers are the disks', not the RAM's. The single disk also beat gp3's 125 MB/s: that's the speed AWS guarantees for sustained use, and a three-second test can run above it, so a real benchmark runs for minutes. The server's own connection to its disks is a limit too: stripe enough disks and the instance type, not the disks, sets the ceiling.
RAID 0 is common on instance store disks, whose data is temporary anyway: striping two or four of them makes one fast scratch area. On EBS, it's for the rare workload that needs more than one disk's 80,000 IOPS. And like LVM, an array over several EBS disks needs create-snapshots to snapshot them all at once.
The snapshot catch
A file system spread over three disks is only consistent if all three are copied at the same instant. Snapshot them one after another, and the later ones include writes the earlier ones missed, and the restored file system may not mount. create-snapshots, plural, snapshots every disk on a server at the same moment: the three start times above match to the millisecond.
aws ec2 create-snapshots --instance-specification InstanceId="$SERVER_A",ExcludeBootVolume=true
ExcludeBootVolume=true left the root disk out, so the set is the three LVM disks. AWS Backup takes multi-disk snapshots the same way.
EFS: one folder, many servers
In the console: EFS > Create file system, in the VPC. Then the file system > Network to see a mount target in each zone, and Attach for the mount command.
(Your machine)
./disk-lab.sh efs
From the fourth run:
== An EFS file system, encrypted, with a mount target in each zone
fs-0d2267c57b8db8b10: both mount targets available after 83 seconds
mount target in us-east-2a at 10.16.1.113
mount target in us-east-2b at 10.16.2.191
== jr-lesson16-server-a mounts it, and writes today's orders
ip-10-16-1-130: by name: Failed to resolve server fs-0d2267c57b8db8b10.efs.us-east-2.amazonaws.com: Name or service not known
ip-10-16-1-130: mounted by the mount target's IP in this zone, 10.16.1.113
ip-10-16-1-130: EFS mounted: 10.16.1.113:/ 8.0E 0 8.0E 0% /shared
1001 sourdough x2 (from server-a)
== jr-lesson16-server-b, in the other zone, mounts the same file system, reads, and adds one
ip-10-16-2-184: by name: Failed to resolve server fs-0d2267c57b8db8b10.efs.us-east-2.amazonaws.com: Name or service not known
ip-10-16-2-184: mounted by the mount target's IP in this zone, 10.16.2.191
ip-10-16-2-184: EFS mounted: 10.16.2.191:/ 8.0E 0 8.0E 0% /shared
1001 sourdough x2 (from server-a)
== Back on jr-lesson16-server-a
1001 sourdough x2 (from server-a)
1002 rye x1 (from server-b)
Server A wrote an order, server B in the other zone read it and added one, and server A saw both. That's what EFS is for: one set of files, many servers, every zone.
| Part | Does |
|---|---|
| File system | The shared storage itself, kept across every zone in the Region |
| Mount target | A network address for it inside one subnet, one per zone. Servers connect to the one in their own zone. |
| Security group on the mount targets | jr-lesson16-efs-sg: port 2049, NFS, from the servers' security group only. Lesson 9's pattern. |
| NFS | The Network File System protocol, how Linux talks to EFS. EFS is Linux only; Windows servers use FSx. |
| 8.0E | df's way of saying 8 exabytes: EFS has no size to fill |
aws efs create-file-system --encrypted --performance-mode generalPurpose --throughput-mode elastic
aws efs create-mount-target --file-system-id fs-0d2267c57b8db8b10 --subnet-id "$SUBNET_A" --security-groups "$EFS_SG"
(On the server)
mount -t nfs4 -o nfsvers=4.1 fs-0d2267c57b8db8b10.efs.us-east-2.amazonaws.com:/ /shared
EFS bills for what's stored: $0.30 per GB a month in Standard, and much less in its Infrequent Access and Archive classes, which lifecycle rules move files into after they go unread, as with S3. Elastic throughput, the lab's choice, scales speed up and down with use and is the default for new file systems.
Trap one: the mount that failed silently
The first run's EFS step looked like this:
== jr-lesson16-server-a mounts it, and writes today's orders
ip-10-16-1-110 mounted: /dev/nvme0n1p1 8.0G 1.8G 6.2G 22% /
1001 sourdough x2 (from server-a)
== jr-lesson16-server-b, in the other zone, mounts the same file system, reads, and adds one
ip-10-16-2-191 mounted: fs-0fc083d78598a2a78.efs.us-east-2.amazonaws.com:/ 8.0E 0 8.0E 0% /shared
cat: /shared/orders.txt: No such file or directory
Server A's "mounted" line shows /dev/nvme0n1p1 ... /: its own root disk, not EFS. The mount had failed, and the order was written anyway, into an ordinary folder called /shared on server A's own disk. No error appeared, because writing to a folder is always allowed. Server B mounted EFS properly and found it empty.
This catches people in production too: the shared folder fails to mount after a reboot, the app writes into the empty folder underneath, and other servers stop seeing new files. The script now checks with mountpoint -q /shared and refuses to write unless it's really mounted. In /etc/fstab, the same protection is ordering the app to start only after the mount.
Trap two: a new file system's name
In every run, the file system's name, fs-...efs.us-east-2.amazonaws.com, failed to resolve for the first few minutes after AWS said the mount targets were available. Clearing the server's own DNS cache didn't help, so it wasn't a stale answer on the server. In the earlier runs, server B, which asked a few minutes later, resolved it fine; in the fourth, it asked within seconds of server A and failed too. A new file system's DNS name takes a few minutes to start working.
The lab's answer is AWS's documented alternative: mount by the IP address of the mount target in the server's own zone, which needs no DNS. Servers that start later, as they do in real systems, use the name. And Amazon's own mount helper, amazon-efs-utils, used with mount -t efs, can fall back to the mount target's IP address by itself.
Instance store, described
Some instance types come with disks physically inside the host: their names have a d, like m7gd or c7gd. Instance store is very fast and costs nothing extra, but its data is lost when the server stops, is terminated, or its host fails. It survives a reboot. It suits caches, scratch space and copies of data kept safely elsewhere, never the only copy of anything. The t4g servers in this lab don't have it; the exam asks about it.
Take it down
In the console: EC2 > Instances > Terminate instance; Volumes > select the data disks > Delete volume; Snapshots > Delete snapshot; EFS > the file system > Delete, which deletes its mount targets first; then the VPC.
(Your machine)
./disk-lab.sh delete
From the first run:
== Terminated the servers (their root disks went with them)
== Deleted EFS file system fs-0fc083d78598a2a78
== Deleted disk vol-057008e1805f1a467
== Deleted disk vol-0c840c73504d3838d
== Deleted snapshot snap-0e0428866c45ad2e6
== Deleted role jr-lesson16-ssm-role
== Deleted jr-lesson16-vpc and everything in it
== Left over from this lab (tagged lesson=16)
servers: 0
disks: 0
snapshots: 0
file systems: 0
VPCs: 0
== Storage that bills monthly, anywhere in us-east-2
disks: 0 (0 not attached to anything)
snapshots: 0
EFS file systems: 0
The root disks went with the servers; the two data disks didn't. They had DeleteOnTermination false, the default for any disk you attach, so after the servers were gone, they were sitting there, available, billing. The script deleted them by name. The last section looks across the whole Region for any disk attached to nothing, the most common forgotten cost in EBS.
EFS deletes in order too: mount targets first, which take a little while to go, then the file system.
By hand: every command the script runs
The same lab without the script, in order. It leaves out tags, the capacity fallback and waiting loops; SHOW=1 ./disk-lab.sh disk prints the exact calls as they run. (Your machine), with the commands for the servers sent through Run Command as in Lesson 11.
export AWS_PROFILE=juniper-rye AWS_REGION=us-east-2
# Network and servers: as Lesson 13, with public subnets in us-east-2a and us-east-2b, and an EFS
# security group allowing port 2049 from the servers' group
aws ec2 authorize-security-group-ingress --group-id "$EFS_SG" --protocol tcp --port 2049 --source-group "$WEB_SG"
# An EBS data disk
VOL=$(aws ec2 create-volume --availability-zone us-east-2a --size 2 --volume-type gp3 --encrypted --query VolumeId --output text)
aws ec2 wait volume-available --volume-ids "$VOL"
aws ec2 attach-volume --volume-id "$VOL" --instance-id "$SERVER_A" --device /dev/sdf
# on the server: find it by serial, mkfs.xfs, mount at /data
aws ec2 attach-volume --volume-id "$VOL" --instance-id "$SERVER_B" --device /dev/sdg # refused: ZoneMismatch
aws ec2 modify-volume --volume-id "$VOL" --size 4
aws ec2 describe-volumes-modifications --volume-ids "$VOL"
# on the server: xfs_growfs -d /data
# A snapshot, and a new disk from it in the other zone
SNAP=$(aws ec2 create-snapshot --volume-id "$VOL" --query SnapshotId --output text)
aws ec2 wait snapshot-completed --snapshot-ids "$SNAP"
VOL_B=$(aws ec2 create-volume --availability-zone us-east-2b --snapshot-id "$SNAP" --volume-type gp3 --query VolumeId --output text)
aws ec2 attach-volume --volume-id "$VOL_B" --instance-id "$SERVER_B" --device /dev/sdf
# on the server: mount, without formatting
# LVM: three more 1 GiB disks on server A, then one snapshot of them all
aws ec2 attach-volume --volume-id "$LVM_1" --instance-id "$SERVER_A" --device /dev/sdg # and sdh, then sdi
# on the server: pvcreate, vgcreate, lvcreate, mkfs.xfs, mount; later pvcreate, vgextend, lvextend --resizefs
aws ec2 create-snapshots --instance-specification InstanceId="$SERVER_A",ExcludeBootVolume=true
# RAID 0: three more empty 1 GiB disks; on the server, dd to one, mdadm --level=0 across two, dd again
# EFS, with a mount target in each zone
FS=$(aws efs create-file-system --encrypted --throughput-mode elastic --query FileSystemId --output text)
aws efs create-mount-target --file-system-id "$FS" --subnet-id "$SUBNET_A" --security-groups "$EFS_SG"
aws efs create-mount-target --file-system-id "$FS" --subnet-id "$SUBNET_B" --security-groups "$EFS_SG"
aws efs describe-mount-targets --file-system-id "$FS"
# on each server: mount -t nfs4 -o nfsvers=4.1 by name, or by its zone's mount target IP
# Taking it down, in this order
aws ec2 terminate-instances --instance-ids "$SERVER_A" "$SERVER_B"
aws efs delete-mount-target --mount-target-id "$MT_A"
aws efs delete-mount-target --mount-target-id "$MT_B"
aws efs delete-file-system --file-system-id "$FS" # once the mount targets are gone
aws ec2 delete-volume --volume-id "$VOL"
aws ec2 delete-volume --volume-id "$VOL_B"
aws ec2 delete-snapshot --snapshot-id "$SNAP"
# then the role and the VPC, as in Lesson 13
In real systems
- EBS encryption by default is switched on in every Region of every account, often by the organization (Lesson 36).
- Snapshots run on a schedule from AWS Backup, with copies in a second Region or account in case the first is lost (Lesson 19).
- Databases rarely sit on a team's own EBS disks now. RDS runs them on EBS for you, with the snapshots built in (Lesson 17).
- Shared folders are the exception, not the rule. Apps that share files usually put them in S3 instead, which is cheaper and works from anywhere; EFS is for software that expects a real file system.
- Containers use EFS for data that must outlive any one container, and EBS for data tied to one (Lessons 27 and 28).
- An unattached-disk check runs regularly, often as a scheduled script or an AWS Config rule (Lesson 35), because forgotten disks add up.
Spot the problem
Work out what's wrong before you read the explanation.
"We shut down the old servers last month, and we're still paying for storage." A team terminated twenty servers after a migration. Each had a 100 GB data disk the team had attached when the servers were set up. The EC2 bill dropped, but the EBS line is still about $160 a month. What's wrong? The data disks were attached by hand, so DeleteOnTermination was false: terminating the servers left twenty 100 GB gp3 disks sitting available, at $0.08 per GB a month. The fix: snapshot any that matter, then delete the disks, and next time set DeleteOnTermination true for disks that should go with their server. Then check: does EC2 > Volumes, filtered on state available, show none?
Keep this
| Remember | Why |
|---|---|
| EBS: one server, one zone | The other zone said ZoneMismatch |
| Find disks by serial, mount by UUID | Linux names them in its own order |
| Grow the disk, then the file system | A bigger disk doesn't make a bigger file system |
| gp3 by default; io2 for guaranteed IOPS | gp2 costs more for less |
| Snapshots cross zones; they're incremental | How data moves, and why they're cheap |
LVM: past one disk's size or speed, or pvmove | For one disk that just grows, EBS resizing is simpler |
| RAID 0 on EBS for speed; never RAID 1, 5 or 6 | EBS already copies every disk; striping nearly doubled the speed here |
Several disks, one file system: create-snapshots | All at the same instant, or the copies don't match |
| EFS: many servers, every zone, priced per GB stored | Nearly four times EBS per GB |
| Check the mount before writing | A failed mount writes to the wrong disk silently |
| Instance store is wiped on stop | Never the only copy |
| Attached disks and snapshots outlive servers | And bill until deleted |
Where you are now
The bakery's server has had a second disk it formatted, filled and grew while it was running; the server in the next zone refused that disk, and a snapshot carried the recipe across anyway. Two servers in two zones shared one folder of orders, after two traps you'll now recognize: a mount that failed without a word, and a name that took minutes to exist. Next, Lesson 17 hands the database to AWS: RDS and Aurora, built on the same disks and snapshots.
Check yourself
The disk in us-east-2a wouldn't attach to the server in us-east-2b. Why?
The script attached the disk as /dev/sdf. What did lsblk list it as?
After growing the disk to 4 GiB, df still said 2.0G. What was missing?
How did the recipe get from us-east-2a to us-east-2b?
Which RAID level does AWS recommend on EBS, and why?
An LVM file system spans three EBS disks. How should it be snapshotted?
In the first run, server A wrote an order, but server B couldn't see it. Why?
Which storage is wiped when the server stops?
After terminating the servers, what was still there, and billing?
Key terms
- EBS (Elastic Block Store): a network disk for one server, in one zone.
- Root volume: the EBS disk a server boots from.
- DeleteOnTermination: whether a disk is deleted with its server.
- gp3, io2, st1, sc1: EBS types, from everyday SSD to cold hard disk.
- IOPS: input/output operations per second: how many reads and writes a disk can do.
- Mount: making a disk or shared folder appear at a path, like
/data. - Snapshot: a point-in-time, incremental copy of an EBS disk, kept across the Region.
- EFS (Elastic File System): a shared file system for many Linux servers in many zones.
- Mount target: EFS's address in one subnet; one per zone.
- LVM (Logical Volume Manager): pools disks into volume groups and carves logical volumes from them.
- Physical volume, volume group, logical volume: a disk given to LVM, a pool of them, and a slice of the pool with a file system.
- RAID 0, 1, 5, 6: striping for speed, mirroring, and parity for surviving a failed disk.
- mdadm: the Linux tool that builds RAID arrays.
- Multi-volume snapshot: snapshots of several disks taken at the same instant.
- NFS (Network File System): the protocol Linux uses to talk to EFS.
- Instance store: fast disks in the physical host, wiped when the server stops.
- FSx: AWS's file systems for Windows and other uses EFS doesn't cover.
Go deeper
- Linux track: Disks, storage and memory, for block devices, file systems, mounting and
/etc/fstab. - AWS: EBS volume types (opens in a new tab), extending a file system after resizing (opens in a new tab), and EBS pricing (opens in a new tab).
- AWS: how EBS snapshots work (opens in a new tab), mounting EFS with the IP address of a mount target (opens in a new tab), and EFS pricing (opens in a new tab).
- Try: run
buildanddisk, then on server A, add the disk to/etc/fstabby UUID withnofail, reboot the server withaws ec2 reboot-instances, and use Run Command to check/datacame back on its own. Rundeletewhen you're done.