Skip to content

Update calamares-settings-blankon to implement swapfile on targetted root system #54

@herpiko

Description

@herpiko

System without swap is super slow, especially when your app is RAM-hungry. Maybe we need to make the swapfile size dynamic, like

  • < 30 GB root partition, use 4GB.
  • 30 GB root partition, use half of the size of the RAM.

#!/bin/bash

# Swap file setup script for Calamares
# Usage: setup-swap.sh [ROOT_PATH]

set -e

# Calamares mounts target at this path, or pass as argument
ROOT="${1:-@@ROOT@@}"

SWAP_SIZE="16G"
SWAP_FILE="${ROOT}/swapfile"

echo "Setting up ${SWAP_SIZE} swap file at ${SWAP_FILE}..."

# Create swap file
fallocate -l ${SWAP_SIZE} "${SWAP_FILE}" || dd if=/dev/zero of="${SWAP_FILE}" bs=1G count=16 status=progress

# Set permissions
chmod 600 "${SWAP_FILE}"

# Format as swap
mkswap "${SWAP_FILE}"

# Add to target fstab (path without ROOT prefix)
if ! grep -q '/swapfile' "${ROOT}/etc/fstab"; then
    echo '/swapfile none swap sw 0 0' >> "${ROOT}/etc/fstab"
    echo "Added swap entry to fstab"
else
    echo "Swap entry already exists in fstab"
fi

echo "Swap file setup complete"

Then in shellprocess module,

script:
  - command: "/usr/lib/calamares/scripts/setup-swap.sh @@ROOT@@"
    timeout: 300

Metadata

Metadata

Assignees

Type

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions