2026-04-02 23:12:36 +08:00

48 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Ubuntu设置swap分区
createTime: 2022/11/02 16:22:28
tags:
- Ubuntu
categories:
- 随记
---
**通常Ubuntu Server 安装完成后已经自动配置了 swap 分区,使用`sudo swapon --show`或者`free -m`查看**
```bash
# 建立swapfile
sudo fallocate -l 4G /swap.img
# 设置权限
sudo chmod 600 /swap.img
# 配置分区生效
sudo mkswap /swap.img
sudo swapon /swap.img
# sudo cp /etc/fstab /etc/fstab.bak
echo '/swap.img none swap sw 0 0' | sudo tee -a /etc/fstab
# 查看分区生效情况
# sudo swapon --show
# free -m
```
分区大小参考:
| RAM(GB) | No hibernation | With Hibernation | Maximum |
| ------- | -------------- | ---------------- | ------- |
| 1 | 1 | 2 | 2 |
| 2 | 1 | 3 | 4 |
| 3 | 2 | 5 | 6 |
| 4 | 2 | 6 | 8 |
| 5 | 2 | 7 | 10 |
| 6 | 2 | 8 | 12 |
| 8 | 3 | 11 | 16 |
| 12 | 3 | 15 | 24 |
| 16 | 4 | 20 | 32 |
| 24 | 5 | 29 | 48 |
| 32 | 6 | 38 | 64 |
| 64 | 8 | 72 | 128 |
| 128 | 11 | 139 | 256 |
| 256 | 256 | 512 | 512 |
| 512 | 512 | 1024 | 1024 |
| 1024 | 1024 | 2048 | 2048 |