> ## Content Index
> Fetch the complete content index at: https://iiong.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# 腾讯云开启 swap 分区
- URL: https://iiong.com/qcloud-opens-swap-partition/
- Published: 2021-03-30T12:55:13.000Z
- Updated: 2026-06-22T15:31:49.000Z
- Description: 自从使用 MySQL8 大版本后，每次升级 ghost 就会提示内存不够的错误。但如果你要执行 ghost update --no-mem-check 来无视内存检测的话，你会发现在编译依赖包终端直接卡死。
- Author: 淮城一只猫
- Tags: 奇技淫巧

### 前言

自从使用 `MySQL8` 大版本后，每次升级 `ghost` 就会提示内存不够的错误：

```bash
Message: You are recommended to have at least 150 MB of memory available for smooth operation.
It looks like you have ~90.246093375MB available

```

但如果你要执行 `ghost update --no-mem-check` 来无视内存检测的话，你会发现在编译依赖包终端直接卡死，也就是说内存增大是必须的，群里的腾讯云工程师告诉我腾讯云默认是不开启 `swap` 功能，所以这里简单做一下开启 `swap` 过程。

### 开启 swap

先使用 `free -m` 命令查看 `swap` 是否开启：

```bash
11:20:29 ubuntu@VM-104-68-ubuntu ~ → free -m
              total        used        free      shared  buff/cache   available
Mem:            980         671          64           2         244         157
Swap:             0           0           0

```

创建在 `/root/swap` 的 2G 目录来作为交换分区的文件：

```bash
dd if=/dev/zero of=/root/swap bs=2048 count=1048576

```

设置改文件为交换文件：

```bash
mkswap /root/swap

```

修改权限：

```bash
chmod 600 /root/swap

```

启用交换分区文件

```bash
swapon /root/swap

```

设置自启动，否则服务器无法进入系统，修改 `/etc/fstab` 文件，在最后一行添加：

```bash
/root/swap swap swap defaults 0 0

```

查看是否开启交换分区：

```bashh
11:20:29 ubuntu@VM-104-68-ubuntu ~ → free -m
              total        used        free      shared  buff/cache   available
Mem:            980         671          64           2         244         157
Swap:          2047          59        1988

```

类似上述说明正常使用了，期间升级 `ghost` 也不会出现内存不足的问题。

如果后期升级配置或者不再需要删除分区如下：

```bash
swapoff /root/swap
rm -f /root/swap

```