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
  • Is the file disappearing after reboot? Or are you asking for the format of the /etc/fstab line? – Jesusaurus Aug 9 '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 9 '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 9 '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 9 '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 1:38
up vote 3 down vote accepted

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
  • 989000000 is this normal? – jnbdz Aug 9 '17 at 21:02
  • 1
    That is the size of the file in bytes. – Jesusaurus Aug 9 '17 at 21:08

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.