Browse Source

Move docker data to the SSD (#589)

Co-authored-by: Lounès Ksouri <dev@louneskmt.com>
Co-authored-by: Luke Childs <lukechilds123@gmail.com>
log-to-ssd
Aaron Dewes 4 years ago
committed by GitHub
parent
commit
0b31ec7688
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      scripts/umbrel-os/external-storage/mount
  2. 1
      scripts/umbrel-os/services/umbrel-external-storage.service
  3. 37
      scripts/update/01-run.sh

22
scripts/umbrel-os/external-storage/mount

@ -16,6 +16,8 @@ set -euo pipefail
UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../../..)"
MOUNT_POINT="/mnt/data"
EXTERNAL_UMBREL_ROOT="${MOUNT_POINT}/umbrel"
DOCKER_DIR="/var/lib/docker"
EXTERNAL_DOCKER_DIR="${MOUNT_POINT}/docker"
SWAP_DIR="/swap"
SWAP_FILE="${SWAP_DIR}/swapfile"
@ -112,6 +114,15 @@ setup_new_device () {
"${UMBREL_ROOT}" "${EXTERNAL_UMBREL_ROOT}"
}
# Copy Docker data dir to external storage
copy_docker_to_external_storage () {
mkdir -p "${EXTERNAL_DOCKER_DIR}"
cp --recursive \
--archive \
--no-target-directory \
"${DOCKER_DIR}" "${EXTERNAL_DOCKER_DIR}"
}
main () {
echo "Running external storage mount script..."
check_root
@ -174,9 +185,17 @@ main () {
setup_new_device $block_device $partition_path
fi
if [[ ! -d "${EXTERNAL_DOCKER_DIR}" ]]; then
echo "Copying Docker data directory to external storage..."
copy_docker_to_external_storage
fi
echo "Bind mounting external storage over local Umbrel installation..."
mount --bind "${EXTERNAL_UMBREL_ROOT}" "${UMBREL_ROOT}"
echo "Bind mounting external storage over local Docker data dir..."
mount --bind "${EXTERNAL_DOCKER_DIR}" "${DOCKER_DIR}"
echo "Bind mounting external storage to ${SWAP_DIR}"
mkdir -p "${MOUNT_POINT}/swap" "${SWAP_DIR}"
mount --bind "${MOUNT_POINT}/swap" "${SWAP_DIR}"
@ -190,6 +209,9 @@ main () {
sleep 1
df -h "${UMBREL_ROOT}" | grep --quiet '/dev/sd'
echo "Checking ${DOCKER_DIR} is now on external storage..."
df -h "${DOCKER_DIR}" | grep --quiet '/dev/sd'
echo "Checking ${SWAP_DIR} is now on external storage..."
df -h "${SWAP_DIR}" | grep --quiet '/dev/sd'

1
scripts/umbrel-os/services/umbrel-external-storage.service

@ -3,6 +3,7 @@
[Unit]
Description=External Storage Mounter
Before=docker.service
[Service]
Type=oneshot

37
scripts/update/01-run.sh

@ -121,6 +121,43 @@ EOF
cd "$UMBREL_ROOT"
./scripts/stop
# Move Docker data dir to external storage now if this is an old install.
# This is only needed temporarily until all users have transitioned Docker to SSD.
DOCKER_DIR="/var/lib/docker"
MOUNT_POINT="/mnt/data"
EXTERNAL_DOCKER_DIR="${MOUNT_POINT}/docker"
if [[ ! -z "${UMBREL_OS:-}" ]] && [[ ! -d "${EXTERNAL_DOCKER_DIR}" ]]; then
echo "Attempting to move Docker to external storage..."
cat <<EOF > "$UMBREL_ROOT"/statuses/update-status.json
{"state": "installing", "progress": 72, "description": "Migrating Docker install to external storage", "updateTo": "$RELEASE"}
EOF
echo "Stopping Docker service..."
systemctl stop docker
# Copy Docker data dir to external storage
copy_docker_to_external_storage () {
mkdir -p "${EXTERNAL_DOCKER_DIR}"
cp --recursive \
--archive \
--no-target-directory \
"${DOCKER_DIR}" "${EXTERNAL_DOCKER_DIR}"
}
echo "Copying Docker data directory to external storage..."
copy_docker_to_external_storage
echo "Bind mounting external storage over local Docker data dir..."
mount --bind "${EXTERNAL_DOCKER_DIR}" "${DOCKER_DIR}"
# Ensure fs changes are registered
sync
sleep 1
echo "Starting Docker service..."
systemctl start docker
fi
# Overlay home dir structure with new dir tree
echo "Overlaying $UMBREL_ROOT/ with new directory tree"
rsync --archive \

Loading…
Cancel
Save