2

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
5
  • Is the file disappearing after reboot? Or are you asking for the format of the /etc/fstab line?
    – Jesusaur
    Aug 9, 2017 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, 2017 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, 2017 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, 2017 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, 2017 at 1:38

1 Answer 1

3

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .