# 关闭docker
$ systemctl stop docker
# 创建一个物理卷
$ pvcreate /dev/xvdf
# 创建一个逻辑卷组,命名为docker
$ vgcreate docker /dev/xvdf
# 创建名为thinpool和thinpoolmeta的逻辑卷,分别占用95%和1%的逻辑卷组空间(剩余空间用于逻辑# 卷自动扩容)
$ lvcreate --wipesignatures y -n thinpool docker -l 95%VG
$ lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG
# 将逻辑卷转换成精简池
$ lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta
# 通过lvm profile为精简池配置自动扩容
$ cat >> /etc/lvm/profile/docker-thinpool.profile << EOF \
activation { \
thin_pool_autoextend_threshold=80 \
thin_pool_autoextend_percent=20 \
} \
EOF
# 使lvm profile生效
$ lvchange --metadataprofile docker-thinpool docker/thinpool
# 备份之前的docker存储目录,用以故障还原
$ mkdir /var/lib/docker.bk
$ mv /var/lib/docker/* /var/lib/docker.bk
# 修改/etc/docker/daemon.json文件将devicemapper存储指向精简池
$ vi /etc/docker/daemon.json
{
"storage-driver": "devicemapper",
"storage-opts": [
"dm.thinpooldev=/dev/mapper/docker-thinpool",
"dm.use_deferred_removal=true",
"dm.use_deferred_deletion=true"
]
}
# 重载系统配置
$ systemctl daemon-reload
# 启动docker
$ systemctl start docker
# 启动成功后,删除之前的备份
$ rm -rf /var/lib/docker.bk