diff --git a/buildroot-external/package/hassio/create-data-partition.sh b/buildroot-external/package/hassio/create-data-partition.sh index e24ef9cf2..8c8ee8073 100755 --- a/buildroot-external/package/hassio/create-data-partition.sh +++ b/buildroot-external/package/hassio/create-data-partition.sh @@ -23,11 +23,14 @@ container=$(docker run --privileged -e DOCKER_TLS_CERTDIR="" \ -v "${build_dir}/data/":/data \ -v "${build_dir}/data/docker/":/var/lib/docker \ -v "${build_dir}":/build \ - -d "docker:${docker_version}-dind" --storage-driver overlay2) + -d "docker:${docker_version}-dind" --feature containerd-snapshotter) docker exec "${container}" sh /build/dind-import-containers.sh "${channel}" docker stop "${container}" +# Indicator for docker-prepare.service to use the containerd snapshotter +sudo touch "${build_dir}/data/.docker-use-containerd-snapshotter" + # Unmount data image sudo umount "${build_dir}/data/" diff --git a/buildroot-external/rootfs-overlay/etc/docker/daemon.json b/buildroot-external/rootfs-overlay/etc/docker/daemon.json index 5a19d56de..4d0f7c752 100644 --- a/buildroot-external/rootfs-overlay/etc/docker/daemon.json +++ b/buildroot-external/rootfs-overlay/etc/docker/daemon.json @@ -1,5 +1,4 @@ { - "storage-driver": "overlay2", "log-driver": "journald", "log-opts": { "tag": "{{.Name}}" diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/docker-prepare.service b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/docker-prepare.service new file mode 100644 index 000000000..5457ff0d0 --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/docker-prepare.service @@ -0,0 +1,11 @@ +[Unit] +Description=Docker environment and config initialization +Before=docker.service +RequiresMountsFor=/mnt/data + +[Service] +Type=oneshot +ExecStart=/usr/libexec/docker-prepare + +[Install] +WantedBy=multi-user.target diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/docker.service.d/hassos.conf b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/docker.service.d/hassos.conf index 4e6014da7..92380f429 100644 --- a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/docker.service.d/hassos.conf +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/docker.service.d/hassos.conf @@ -2,4 +2,8 @@ RequiresMountsFor=/etc/docker /mnt/data /var/lib/docker [Service] +# env file must be created by docker-prepare.service +EnvironmentFile=/run/dockerd.env +ExecStart= +ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock $DOCKERD_FLAGS OOMScoreAdjust=-400 diff --git a/buildroot-external/rootfs-overlay/usr/libexec/docker-prepare b/buildroot-external/rootfs-overlay/usr/libexec/docker-prepare new file mode 100755 index 000000000..bc6f4d2fb --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/libexec/docker-prepare @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +if [ ! -d /mnt/data/docker ] || [ -z "$(ls -A /mnt/data/docker)" ]; then + echo "[INFO] Docker data is wiped, creating containerd snapshotter flag" + touch /mnt/data/.docker-use-containerd-snapshotter +fi + +DOCKERD_FLAGS="" + +if [ -f /mnt/data/.docker-use-containerd-snapshotter ]; then + echo "[INFO] Using Docker containerd snapshotter" + DOCKERD_FLAGS="${DOCKERD_FLAGS} --feature containerd-snapshotter" + + if [ -d /mnt/data/docker/overlay2 ]; then + echo "[INFO] Removing no longer used overlay2 directory" + # Allow the removal to fail without failing the service + rm -rf /mnt/data/docker/overlay2 || true + fi +fi + +echo "DOCKERD_FLAGS=\"${DOCKERD_FLAGS}\"" > /run/dockerd.env