1

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
jnbdz
  • 897
  • 5
  • 22
  • 43
  • Is the file disappearing after reboot? Or are you asking for the format of the /etc/fstab line? – Jesusaur Aug 09 '17 at 20:49
  • The /var/swap.1 file is still there. But when I run `free` it's all zeros for swap. – jnbdz Aug 09 '17 at 20:54
  • `The number 989000000 seems a bit big` - Why do you think that? It seems a bit small to me given the commands you posted should be creating a file that is 1000*1MB (1048576000 bytes). – Zoredache Aug 09 '17 at 21:06
  • 1
    Hrm, apparently 1MB in dd is `10^6` not the `2**20` I was expecting. Stupid SI vs binary prefixes. – Zoredache Aug 09 '17 at 21:14
  • 1
    @Zoredache, still too small, though: 1000 1MB chunks shouldn't be less than 1 000 000 000 bytes no matter which version of "M" you use. – Mark Aug 10 '17 at 01:38

1 Answers1

2

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
Jesusaur
  • 184
  • 3