AWS EBS Volume Stuck in 'Attaching' State – Fix
An EBS volume that won't attach usually means the instance or volume is in a bad state. This fix covers the real causes.
Quick Answer for Advanced Users
If you know your way around AWS: stop the instance, force detach the volume using aws ec2 detach-volume --force, wait 30 seconds, then reattach. If that fails, you'll need to delete the volume (after snapshot) and create a new one.
Why This Happens
I've seen this dozens of times. An EBS volume gets stuck in 'attaching' state when the EC2 instance can't talk to the volume controller. This usually happens after a network timeout, the instance being in a bad state (like a stuck syscall), or if the volume was previously attached to another instance and not properly detached.
Common triggers: rebooting an instance while a volume is mid-attach, using an outdated AMI, or hitting the 20,000 IOPS limit on gp2 volumes during heavy I/O. The AWS console will show 'attaching' for more than 5 minutes – that's when you know something's wrong.
Here's the thing: most AWS support articles tell you to wait and check logs. But in my experience, waiting doesn't fix it. You need to force the system to let go.
Step-by-Step Fix
- Stop the EC2 instance – not reboot. Go to the EC2 console, select your instance, click 'Instance state' > 'Stop'. Wait until it shows 'stopped'. This interrupts any pending I/O operations.
- Check the volume state – In the console, go to 'Volumes', find your stuck volume. It'll show 'attaching' or 'in-use'. Don't panic if it says 'in-use' but the instance is stopped – that's normal.
- Force detach the volume – Open the AWS CLI on your local machine or cloud shell. Run:
aws ec2 detach-volume --volume-id vol-xxxxxxxx --force --region us-east-1
Replace the volume ID and region. The--forceflag tells AWS to skip the normal detach checks. You should see a JSON response with"State": "detaching". - Wait 30 seconds – then check the volume status again. It should show 'available'. If it still shows 'detaching', wait another minute. If it's stuck for 2+ minutes, skip to the alternative fixes.
- Attach the volume again – Select the volume, click 'Actions' > 'Attach volume'. Choose your stopped instance and the device name (like
/dev/sdf). Click 'Attach'. The state should change to 'attaching' then 'in-use' within 10 seconds. - Start the instance – Go back to your instance, click 'Instance state' > 'Start'. Wait for it to show 'running'. SSH in and check the volume is mounted.
lsblkshould show your device, likexvdf.
Alternative Fixes If the Main One Fails
Fix A: Restart the EC2 Service on the Instance
If you can still SSH into the instance (even with the volume stuck), try:sudo systemctl restart ec2
Wait 30 seconds, then check lsblk. If the volume appears, you can mount it. This works maybe 20% of the time.
Fix B: Delete and Recreate the Volume
This is the nuclear option, but it works every time. Take a snapshot first:aws ec2 create-snapshot --volume-id vol-xxxxxxxx --description "Backup before recreate"
Wait for the snapshot to complete (check status in console). Then delete the stuck volume: select it, 'Actions' > 'Delete volume'. Create a new volume from the snapshot – same size and type. Attach it fresh. You'll lose the device name mapping, so update /etc/fstab if needed.
Fix C: Use a Different Availability Zone
Sometimes the AZ's storage controller is flaky. Create the new volume in a different AZ (like us-east-1b instead of us-east-1a). Then launch a new instance in that AZ and attach there. This helps if you keep seeing attachment failures on the same volume.
Prevention Tips
- Never attach a volume while the instance is booting – wait until the instance shows 'running' and you can SSH in. Attaching during PXE or kernel load often causes this.
- Use EBS multi-attach only with cluster-aware filesystems – like XFS with GFS2. Don't try to attach the same volume to two Windows instances – it corrupts the filesystem.
- Always detach volumes from the console – don't just stop an instance and yank the volume. Use the 'Detach volume' action, even if the instance is stopped.
- Monitor volume state with CloudWatch – set an alarm on
VolumeQueueLength. If it goes above 1000 for 5 minutes, you're probably hitting an I/O limit that can cause attachment timeouts. - Switch to
gp3volumes – they have higher baseline IOPS (3000 vs 100 forgp2) and don't have burst bucket issues that can trigger stuck attachments.
One more thing – if you're using an AWS SDK (like boto3 in Python), make sure your code waits for the 'available' state before calling attach. I've seen scripts fail because they tried to attach a volume that was still detaching. Add a
waitercall:ec2_client.get_waiter('volume_available').wait(VolumeIds=['vol-xxx'])
Was this solution helpful?