Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 4GB swapfile on external storage #180

Merged
merged 12 commits into from Aug 27, 2020
16 changes: 16 additions & 0 deletions scripts/umbrel-os/external-storage/mount
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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}"
mayankchhabra marked this conversation as resolved.
Show resolved Hide resolved
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"

Expand Down
11 changes: 10 additions & 1 deletion scripts/update/02-run.sh
Expand Up @@ -12,4 +12,13 @@ echo "========= Stage: Post-update =========="
echo "======================================="
echo

# Nothing here for now
# Make Umbrel OS specific post-update changes
if [[ ! -z "${UMBREL_OS:-}" ]]; then
mayankchhabra marked this conversation as resolved.
Show resolved Hide resolved

# Remove dphys-swapfile since we now use our own swapfile logic
if command -v dphys-swapfile >/dev/null 2>&1; then
mayankchhabra marked this conversation as resolved.
Show resolved Hide resolved
echo "Removing unused dependency \"dphys-swapfile\""
apt-get remove -y dphys-swapfile
fi

fi