Skip to content

Instantly share code, notes, and snippets.

@kamermans
Last active September 22, 2022 18:32
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save kamermans/176c190670a163b1147e to your computer and use it in GitHub Desktop.
Save kamermans/176c190670a163b1147e to your computer and use it in GitHub Desktop.
AWS EC2 script to mount Instance Store 0 and 1 as Docker temp and volume storage
#!/bin/sh -e
# This script will DESTROY /dev/xvdb and /dev/xvdc and remount them
# for Docker temp and volume storage.
# It is intended for EC2 instances with 2 ephemeral SSD instance stores
# like the c3.xlarge instance type.
service docker stop || true
# Setup Instance Store 0 for Docker Temp
# (set in /etc/default/docker)
DEV="/dev/xvdb"
umount $DEV 2>/dev/null || true
mkdir /mnt/docker-temp 2>/dev/null || rm -rf /mnt/docker-temp/*
mkfs.ext4 $DEV
mount -t ext4 -o noatime $DEV /mnt/docker-temp
# Setup Instance Store 1 for Docker volume storage
DEV="/dev/xvdc"
umount $DEV 2>/dev/null || true
mkdir /mnt/docker-volumes 2>/dev/null || rm -rf /mnt/docker-volumes/*
mkfs.ext4 $DEV
rm -rf /var/lib/docker/vfs
rm -rf /var/lib/docker/volumes
mount -t ext4 -o noatime $DEV /mnt/docker-volumes
mkdir /mnt/docker-volumes/vfs
ln -s /mnt/docker-volumes/vfs /var/lib/docker/vfs
mkdir /mnt/docker-volumes/volumes
ln -s /mnt/docker-volumes/volumes /var/lib/docker/volumes
service docker start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment