大网数据广告活动
服务器运维问答

I loose the swap every time I restart my Ubuntu server

· 52CE 我爱测

Here is how I set the swap: sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1MB count="1000" sudo /sbin/mkswap /var/swap.1 sudo /sbin/swapon /var/swap.1 Every time I reboot/restart the swap is gone. The command free gives me zeros fo…

问题原文

原帖链接 · jnbdz · CC BY-SA 3.0

Here is how I set the swap:

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1MB count="1000"
sudo /sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1

Every time I reboot/restart the swap is gone.

The command free gives me zeros for swap. But the file /var/swap.1 is still there.

swap.1 file details:

-rw-r--r-- 1 root root 989000000 Aug 9 20:55 swap.1

The number 989000000 seems a bit big...

How can I make it persistent?

lsb_release -a

LSB Version:    core-9.20160110ubuntu5-amd64:core-9.20160110ubuntu5-noarch:security-9.20160110ubuntu5-amd64:security-9.20160110ubuntu5-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 17.04
Release:    17.04
Codename:   zesty

已采纳解答

原帖链接 · Jesusaur · CC BY-SA 3.0

In order for the system to automatically use the swap file as swap space on boot, it needs an entry in /etc/fstab similar to:

/var/swap.1 swap swap defaults 0 0

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。