aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/linux/swap.md
blob: 1a458839bd9a02470cb92229201c5bc6f9108079 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# swap

## List active swap areas

```sh
# procfs
cat /proc/swaps

# cli tool
swapon --show
```

## Manual swapfile setup

```sh
# One time:
#   Create and initialize swapfile.
#   mkswap will initialize swap area over full filesize by default.
sudo dd if=/dev/zero of=/swapfile bs=1G count=1
mkswap /swapfile

# Enable swap file (until next reboot).
swapon /swapfile

# Persistent setup of swap file.
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab

# Disable swap file (until next reboot).
swapoff /swapfile
```
> Recommended file permissions `0600` and file owner `uid=0 (root)`.

## Using `dphys-swapfile` service.

Dynamically computes size of swap file based on installed RAM.

```sh
# Setup and enable swap based on /etc/dphys-swapfile.
dphys-swapfile setup
dphys-swapfile swapon

# Disable swap on configured file.
dphys-swapfile swapoff
```

> Usually comes with a script to be automatically run at system startup and shutdown.
> For example as `systemd` service:
> ```
> systemctl status dphys-swapfile
> ```