Skip to content

Instantly share code, notes, and snippets.

@ebr
Created May 8, 2017 18:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ebr/94ada3841e7de90a73704fa0336bc657 to your computer and use it in GitHub Desktop.
Save ebr/94ada3841e7de90a73704fa0336bc657 to your computer and use it in GitHub Desktop.
ZFS zpool for docker
#!/bin/bash
## This will only work on Ubuntu 16.04 and up
DEVNAME=/dev/xvdg
# Install ZFS if we don't have it
if [[ -z $(which zfs) ]]; then
apt -y update
apt -y install zfs
fi
# Create zpool
# Check that the zpool doesn't already exist
zpool_success=false
if [[ $(zfs list | grep docker) -eq 0 ]]; then
# check that the device exists
if [[ -e "$DEVNAME" ]]; then
# and isn't mounted
if [[ $(mount | grep -c "$DEVNAME") -eq 0 ]]; then
zpool create -f zpool-docker $DEVNAME
zpool_success=true
else
echo "FATAL: device $DEVNAME is already mounted"
exit 1
else
echo "FATAL: device $DEVNAME does not exist"
exit 1
fi
fi
# Create and mount the filesystem
if [[ $zpool_success == true ]]; then
unset $zpool_success
zfs create -o mountpoint=/var/lib/docker zpool-docker/docker
else
echo "FATAL: zpool was not created; check previous messages"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment