Last active
August 20, 2018 20:53
-
-
Save swamibluedata/4234788e1fa8383478a6af73f2b0a750 to your computer and use it in GitHub Desktop.
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
# Launch the container from bd_mgmt and invoke the following through a bdconfig command. Two parameters NEW_SIZE and INSTANCE_NAME | |
# docker run -d --name test bluedata/centos6 | |
INSTANCE_NAME="test" | |
NEW_SIZE_GB="30" | |
NEW_SIZE=$(( $NEW_SIZE_GB*1024*1024*1024 )) | |
CONT_ID=$(docker inspect -f {{.Id}} $INSTANCE_NAME) | |
DEVMAPPER_POOL=$(docker info | grep pool | awk '{print $3}') | |
DEV=$(docker inspect -f {{.GraphDriver.Data.DeviceName}} $INSTANCE_NAME) | |
METADATA_ID=$(echo $DEV | awk -F "-" '{print $NF}') | |
# The actual metadata files for this container. We will use this to fetch the current information | |
# as well as updating after rezize | |
METADATA_FILE="/var/lib/docker/devicemapper/metadata/$METADATA_ID" | |
METADATA_INIT_FILE="/var/lib/docker/devicemapper/metadata/$METADATA_ID-init" | |
# Fetch the current size and the actual device id from the metadata file | |
OLD_SIZE=$(cat $METADATA_FILE | python -c "import json,sys;obj=json.load(sys.stdin);print obj['size']") | |
DEVICE_ID=$(cat $METADATA_FILE | python -c "import json,sys;obj=json.load(sys.stdin);print obj['device_id']") | |
# We got all the information, we can stop the container now. This also deletes the actual | |
# dm device. | |
docker stop $INSTANCE_NAME | |
# Create the same device with the old size | |
dmsetup create "$DEV" --table "0 $(($OLD_SIZE / 512)) thin /dev/mapper/$DEVMAPPER_POOL $DEVICE_ID" | |
dmsetup suspend $DEV | |
# Adjust to new size | |
dmsetup table $DEV | sed "s/0 [0-9]* thin/0 $(($NEW_SIZE/512)) thin/" | dmsetup load $DEV | |
# resume. Is this good enough? | |
dmsetup resume $DEV | |
# Update metadata | |
NEW_METADATA_FILE=$(cat $METADATA_FILE | python -c "import json,sys;obj=json.load(sys.stdin);obj['size']=$NEW_SIZE;print json.dumps(obj)") | |
NEW_METADATA_INIT_FILE=$(cat $METADATA_INIT_FILE | python -c "import json,sys;obj=json.load(sys.stdin);obj['size']=$NEW_SIZE;print json.dumps(obj)") | |
if [ -n "$NEW_METADATA_FILE" ] | |
then | |
echo -n $NEW_METADATA_FILE > $METADATA_FILE | |
fi | |
if [ -n "$NEW_METADATA_INIT_FILE" ] | |
then | |
echo -n $NEW_METADATA_INIT_FILE > $METADATA_INIT_FILE | |
fi | |
# Mount the device under some folder and grow the xfs file system | |
mkdir -p /mnt/test | |
mount /dev/mapper/$DEV /mnt/test | |
xfs_growfs /dev/mapper/$DEV | |
umount /mnt/test | |
# Start the container | |
docker start $INSTANCE_NAME | |
# To verify after increasing | |
docker exec -it $INSTANCE_NAME bash -c "df -h /" | |
# After verifying the new size as 30GB, reboot the box. This is required for future docker start and docker stop of the same | |
# container |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment