返回顶部
s

swap

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

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
79
下载量
0
收藏
概述
安装方式
版本历史

swap

# 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: ```bash # 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 容量: | RAM | Swap 大小 | |-----|----------| | <= 2 GB | 2x 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`: ```bash # 根据上表确定 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. ```bash # Add to /etc/fstab echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab ``` Verify the entry: ```bash 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. ```bash # 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 的规则表确定新容量,然后先禁用再重建: ```bash # 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.

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 swap-1775917217 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 swap-1775917217 技能

通过命令行安装

skillhub install swap-1775917217

下载 Zip 包

⬇ 下载 swap v1.0.0

文件大小: 2.85 KB | 发布时间: 2026-4-12 11:34

v1.0.0 最新 2026-4-12 11:34
- Initial release of the swap skill for Linux.
- Supports creating, resizing, and configuring swap files.
- Guides persisting swap via /etc/fstab.
- Includes steps for setting and persisting the swappiness parameter.
- Offers verification commands after each operation.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部