脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#!/bin/bash size=$1 if [[ $size != *GB ]]; then echo "size must be nGB";exit 1 fi new_size=$((${size/GB/*1024*1024*1024})) data_file=`docker info 2>/dev/null|grep "Data file"|awk '{print $NF}'` data_loop_file=`docker info 2>/dev/null|grep "Data loop file"|awk '{print $NF}'` truncate -s $new_size $data_loop_file #blockdev --getsize64 $data_file losetup -c $data_file #blockdev --getsize64 $data_file pool=`dmsetup status | grep pool|awk '{print $1}' |sed -e s/:$//` old_table_info=`dmsetup table $pool` new_table_info=`echo $old_table_info|(read a b c; echo $a $((new_size/512)) $c)` dmsetup suspend $pool dmsetup reload $pool --table "$new_table_info" dmsetup resume $pool |
参考:
https://docs.docker.com/engine/userguide/storagedriver/device-mapper-driver/
http://jpetazzo.github.io/2014/01/29/docker-device-mapper-resize/ 翻译版: https://segmentfault.com/a/1190000002931564
https://segmentfault.com/a/1190000004302467 这里的扩容方式比较低级,是丢失数据的扩容方式
https://docs.docker.com/engine/userguide/
https://developerblog.redhat.com/2014/09/30/overview-storage-scalability-docker/
http://blog.opskumu.com/docker-storage-setup.html