Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nefelim4ag/systemd-swap
Script for creating hybrid swap space from zram swaps, swap files and swap partitions.
https://github.com/nefelim4ag/systemd-swap
btrfs shell swap systemd systemd-swap zram zswap
Last synced: about 2 months ago
JSON representation
Script for creating hybrid swap space from zram swaps, swap files and swap partitions.
- Host: GitHub
- URL: https://github.com/nefelim4ag/systemd-swap
- Owner: nefelim4ag
- License: gpl-3.0
- Created: 2014-04-09T00:51:38.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-01-19T12:12:28.000Z (almost 3 years ago)
- Last Synced: 2024-08-02T19:55:46.482Z (5 months ago)
- Topics: btrfs, shell, swap, systemd, systemd-swap, zram, zswap
- Language: Python
- Homepage:
- Size: 388 KB
- Stars: 551
- Watchers: 23
- Forks: 81
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# systemd-swap
[![Code Style: Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)## ⚠️ Current code quality and commit frequency is low ⚠️
### Users should migrate to [systemd/zram-generator](https://github.com/systemd/zram-generator) since zram should be enough in most systems
Script to manage swap on:
- [zswap](https://www.kernel.org/doc/Documentation/vm/zswap.txt) - Enable/Configure
- [zram](https://www.kernel.org/doc/Documentation/blockdev/zram.txt) - Autoconfigurating for swap
- files - (sparse files for saving space, supports btrfs)
- block devices - auto find and do swapon:information_source: It is configurable in `/etc/systemd/swap.conf`.
Additional terms:
- **SwapFC** (File Chunked) - provides a dynamic swap file allocation/deallocation
## File location
```text
/etc/systemd/swap.conf
/usr/lib/systemd/system/systemd-swap.service
/usr/bin/systemd-swap
```## Please don't forget to enable and start with
```shell
sudo systemctl enable --now systemd-swap
```## Install
- **Arch Linux**: in the [community](https://www.archlinux.org/packages/community/any/systemd-swap/) repo.
- **Debian based distros**
```shell
git clone https://github.com/Nefelim4ag/systemd-swap.git
cd systemd-swap
make deb
sudo apt install ./systemd-swap_*_all.deb
```- **Fedora based distros**
```shell
sudo dnf copr enable zeno/systemd-swap
sudo dnf install systemd-swap
```
or
```shell
git clone https://github.com/Nefelim4ag/systemd-swap.git
cd systemd-swap
make rpm
sudo dnf install ./systemd-swap-*noarch.rpm- **Manual**
Install dependencies:
- `python3` >= 3.7
- `python3` packages: `systemd-python` and `sysv_ipc````shell
git clone https://github.com/Nefelim4ag/systemd-swap.git
cd systemd-swap
sudo make install# or into /usr/local:
sudo make prefix=/usr/local install
```## About configuration
**Q**: Do we need to activate both zram and zswap?\
**A**: Nope, it's useless, as zram is a compressed RAM DISK, but zswap is a compressed _"writeback"_ CACHE on swap file/disk. Also having both activated can lead to inverse LRU as noted [here](https://askubuntu.com/questions/471912/zram-vs-zswap-vs-zcache-ultimate-guide-when-to-use-which-one/472227#472227)**Q**: Do I need to use `swapfc_force_use_loop` on swapFC?\
**A**: Nope, as you wish really, native swapfile should work faster and it's safer in OOM condition in comparison to loop backed scenario.**Q**: When would we want a certain configuration?\
**A**: In most cases zram is enough since it on average compresses 2-3x and is much faster than disk based swap.**Q**: How many zram devices should one use?
**A**: If you are not using an ancient kernel (pre 4.7) there's no benefit from using multiple zram devices.**Q**: Can we use this to enable hibernation?\
**A**: Nope as hibernation wants a persistent fs blocks and wants access to swap data directly from disk, this will not work on: _swapfc_ (without some magic of course, see [#85](https://github.com/Nefelim4ag/systemd-swap/issues/85)).## Switch on systemd-swap:s automatic swap management
- Enable swapfc if wanted (note, you should **never** use zram and zswap at the same time)
```shell
vim /etc/systemd/swap.conf.d/overrides.conf
``````ini
swapfc_enabled=1
```- Stop any external swap:
```shell
sudo swapoff -a
```- Remove swap entry from fstab:
```shell
vim /etc/fstab
```- Remove your swap
```shell
# For Ubuntu
sudo rm -f /swapfile# For Centos 7 (if using a swap partition and lvm)
lvremove -Ay /dev/centos/swap
lvextend -l +100%FREE centos/root
```- Remove swap from Grub:
```shell
# For Ubuntu remove resume* in grub
vim /etc/default/grub# For Centos 7 remove rd.lvm.lv=centos/swap*
vim /etc/default/grub# For Manjaro remove resume* in grub & mkinitcpio
vim /etc/default/grub
vim /etc/mkinitcpio.conf
``````shell
# For Ubuntu
update-grub# For Centos 7
grub2-mkconfig -o /boot/grub2/grub.cfg# For Manjaro
update-grub
mkinitcpio -P
```