Created
May 8, 2017 18:28
-
-
Save ebr/94ada3841e7de90a73704fa0336bc657 to your computer and use it in GitHub Desktop.
ZFS zpool for docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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