Browse Source

Create 4GB swapfile on external storage (#180)

update-git
Luke Childs 4 years ago
committed by GitHub
parent
commit
4e517c636b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      scripts/umbrel-os/external-storage/mount
  2. 45
      scripts/update/01-run.sh

16
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"
SWAP_DIR="/swap"
SWAP_FILE="${SWAP_DIR}/swapfile"
check_root () {
if [[ $UID != 0 ]]; then
@ -169,6 +171,10 @@ main () {
echo "Bind mounting external storage over local Umbrel installation..."
mount --bind "${EXTERNAL_UMBREL_ROOT}" "${UMBREL_ROOT}"
echo "Bind mounting external storage to ${SWAP_DIR}"
mkdir -p "${MOUNT_POINT}/swap" "${SWAP_DIR}"
mount --bind "${MOUNT_POINT}/swap" "${SWAP_DIR}"
echo "Bind mounting SD card root at /sd-card..."
[[ ! -d "/sd-root" ]] && mkdir -p "/sd-root"
mount --bind "/" "/sd-root"
@ -178,6 +184,16 @@ main () {
sleep 1
df -h "${UMBREL_ROOT}" | grep --quiet '/dev/sd'
echo "Checking ${SWAP_DIR} is now on external storage..."
df -h "${SWAP_DIR}" | grep --quiet '/dev/sd'
echo "Setting up swapfile"
rm "${SWAP_FILE}" || true
fallocate -l 4G "${SWAP_FILE}"
chmod 600 "${SWAP_FILE}"
mkswap "${SWAP_FILE}"
swapon "${SWAP_FILE}"
echo "Checking SD Card root is bind mounted at /sd-root..."
df -h "/sd-root${UMBREL_ROOT}" | grep --quiet "/dev/root"

45
scripts/update/01-run.sh

@ -102,11 +102,48 @@ EOF
cd "$UMBREL_ROOT"
./scripts/start
# Delete unused Docker images on Umbrel OS
# Make Umbrel OS specific post-update changes
if [[ ! -z "${UMBREL_OS:-}" ]]; then
echo "Deleting previous images"
# Delete unused Docker images on Umbrel OS
echo "Deleting previous images"
cat <<EOF > "$UMBREL_ROOT"/statuses/update-status.json
{"state": "installing", "progress": 90, "description": "Deleting previous images", "updateTo": "$RELEASE"}
EOF
docker image prune --all --force
# Uninstall dphys-swapfile since we now use our own swapfile logic
# Remove this in the next breaking update
if command -v dphys-swapfile >/dev/null 2>&1; then
echo "Removing unused dependency \"dphys-swapfile\""
cat <<EOF > "$UMBREL_ROOT"/statuses/update-status.json
{"state": "installing", "progress": 95, "description": "Removing unused dependencies", "updateTo": "$RELEASE"}
EOF
apt-get remove -y dphys-swapfile
fi
# Setup swap if it doesn't already exist
# Remove this in the next breaking update
MOUNT_POINT="/mnt/data"
SWAP_DIR="/swap"
SWAP_FILE="${SWAP_DIR}/swapfile"
if ! df -h "${SWAP_DIR}" 2> /dev/null | grep --quiet '/dev/sd'; then
cat <<EOF > "$UMBREL_ROOT"/statuses/update-status.json
{"state": "installing", "progress": 90, "description": "Deleting previous images", "updateTo": "$RELEASE"}
{"state": "installing", "progress": 97, "description": "Setting up swap", "updateTo": "$RELEASE"}
EOF
docker image prune --all --force
echo "Bind mounting external storage to ${SWAP_DIR}"
mkdir -p "${MOUNT_POINT}/swap" "${SWAP_DIR}"
mount --bind "${MOUNT_POINT}/swap" "${SWAP_DIR}"
echo "Checking ${SWAP_DIR} is now on external storage..."
df -h "${SWAP_DIR}" | grep --quiet '/dev/sd'
echo "Setting up swapfile"
rm "${SWAP_FILE}" || true
fallocate -l 4G "${SWAP_FILE}"
chmod 600 "${SWAP_FILE}"
mkswap "${SWAP_FILE}"
swapon "${SWAP_FILE}"
fi
fi

Loading…
Cancel
Save