2022-01-16 18:20:39 +00:00
|
|
|
---
|
|
|
|
title: "swap"
|
|
|
|
tags: [ "Documentation", "basics" ]
|
|
|
|
---
|
2020-01-02 00:04:35 +00:00
|
|
|
# Making a Swap File
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
cd /var/cache/
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo dd if=/dev/zero of=swapfile bs=1K count=4M
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
This creates a swapfile of (1k x 4M) 4 Gigs.
|
|
|
|
Change 4M to XM for an XGig swap.
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo chmod 600 swapfile
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo mkswap swapfile
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo swapon swapfile
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
Test it's working with top
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
top -bn1 | grep -i swap
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
or:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
echo "/var/cache/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
Test it'll work at boot with:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo swapoff swapfile
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo swapon -va
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
# Partition Swaps
|
|
|
|
|
|
|
|
Put this in /etc/fstab:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
> UUID=blah-blah none swap sw 0 0
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
Then test it works with:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo swapon -va
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
Test other partitions in fstab with:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo mount -a
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|