swap

Configure Linux swap — create swap file, set swappiness, persist via fstab, resize swap.

MIT-0 · Free to use, modify, and redistribute. No attribution required.
0 · 14 · 0 current installs · 0 all-time installs
MIT-0
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
Purpose & Capability
Name/description match the instructions: all commands and file edits (swapon, mkswap, swapoff, fallocate/dd, sysctl, /etc/fstab) are exactly what a swap-management helper would need. No unrelated binaries, credentials, or network endpoints are requested.
Instruction Scope
Instructions are explicit and stay within swap configuration (checking swap, creating files, formatting, enabling, editing /etc/fstab, setting vm.swappiness). However several operations are potentially destructive (swapoff, dd, recreating /swapfile) and the guidance appends to /etc/fstab without idempotency checks or backups. The skill does not instruct verifying existing fstab entries or backing up /etc/fstab before appending, which is a reliability/safety concern rather than an incoherence.
Install Mechanism
Instruction-only skill with no install spec and no downloads — lowest-risk install mechanism. The metadata correctly lists binaries the instructions reference.
Credentials
No environment variables, secrets, or unrelated service credentials are requested. The skill operates on local system files and commands as expected for its function.
Persistence & Privilege
Skill does modify a system file (/etc/fstab) and kernel parameter (vm.swappiness) which is appropriate for its purpose. It does not request permanent platform-level privileges or always-on inclusion.
Assessment
This skill appears to do what it says, but it runs root-level commands that can be destructive. Before using it: (1) run the 'check current swap status' commands yourself and back up /etc/fstab (sudo cp /etc/fstab /etc/fstab.bak) so you can revert changes, (2) prefer verifying there isn't already a swap entry before appending to fstab to avoid duplicates, (3) be aware dd can be slow and fallocate may not be safe on all filesystems (e.g., some CoW filesystems), (4) ensure you have console/SSH access in case disabling swap impacts system stability, and (5) only run these steps on systems you control. If you want safer automation, add idempotency checks and fstab validation steps (or use a tool like systemd-swap or a configuration management tool) before applying changes.

Like a lobster shell, security has layers — review code before you run it.

Current versionv1.0.0
Download zip
latestvk978bper3r5b5sedazefjpkwpn83zw76

License

MIT-0
Free to use, modify, and redistribute. No attribution required.

SKILL.md

Linux Swap Configuration Skill

You are a Linux swap configuration assistant. When a user needs to create, resize, or tune swap on a Linux system, use this skill.

Typical scenarios:

  • Server has no swap, user wants to add one
  • User wants to resize existing swap
  • User wants to tune swappiness
  • Swap is lost after reboot (not persisted in fstab)

Workflow

  1. First check the current swap status to understand the starting point
  2. Then execute the appropriate operation section based on the user's request
  3. Always verify the result after any change

1. Check Current Swap Status

Before any operation, check the current state:

# Show active swap devices
swapon --show

# Show memory including swap
free -h

# Check fstab for swap persistence
grep -v '^#' /etc/fstab | grep swap

# Current swappiness value
sysctl vm.swappiness

2. Create Swap File

First根据 RAM 大小确定 swap 容量:

RAMSwap 大小
<= 2 GB2x RAM
> 2 GB -- 8 GB与 RAM 相等
> 8 GB -- 64 GB>= 4 GB

例如:RAM 为 2 GB 时创建 4G swap,RAM 为 4 GB 时创建 4G swap,RAM 为 16 GB 时创建 4G swap。

两种创建方式,优先用 fallocate(快);ext3 或不支持 fallocate 的文件系统用 dd

# 根据上表确定 SIZE,例如 4G

# Method 1: fallocate (preferred)
sudo fallocate -l <SIZE> /swapfile

# Method 2: dd (fallback)
# 例如 4G = 4096M
sudo dd if=/dev/zero of=/swapfile bs=1M count=<SIZE_IN_MB>

# Set permissions — swap files must be 0600
sudo chmod 600 /swapfile

# Format as swap
sudo mkswap /swapfile

# Enable
sudo swapon /swapfile

# Verify
swapon --show
free -h

3. Persist Swap Across Reboots

Without this step, swap will be lost after reboot.

# Add to /etc/fstab
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Verify the entry:

grep swap /etc/fstab

4. Set Swappiness

vm.swappiness controls how aggressively the kernel uses swap (0-100, default 60). Value of 20 is recommended for most servers.

# Set immediately
sudo sysctl -w vm.swappiness=20

# Persist across reboots
echo 'vm.swappiness=20' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

5. Resize Swap

按 Section 2 的规则表确定新容量,然后先禁用再重建:

# Disable current swap
sudo swapoff /swapfile

# Recreate with new size
sudo fallocate -l <SIZE> /swapfile
# or: sudo dd if=/dev/zero of=/swapfile bs=1M count=<SIZE_IN_MB>

# Re-format and enable
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

# Verify
swapon --show
free -h

The fstab entry does not need to change if the file path stays the same.

Files

2 total
Select a file
Select a file to preview.

Comments

Loading comments…