# FreeBSD 10 won't add swap file



## Pushrod (Jul 9, 2014)

I was following the instructions in the handbook. I have a swap file, and it is set to 0600 permissions. I also added this line to fstab:


```
md99    none    swap    sw,file=/swap   0       0
```

Running `swapon -aq` returns with exit status 0, and no error message. The swap file is not mounted. Any ideas?


----------



## wblock@ (Jul 9, 2014)

How was the swap created?  (If it is a sparse file, expect problems.)  How big is it, and who owns it?


----------



## Pushrod (Jul 9, 2014)

1 GB, root, /dev/zero.


----------



## wblock@ (Jul 9, 2014)

Tested here, and it does not mount the swap file unless the -L option is given (`swapon -aL`)  This should only be needed for /etc/fstab swap entries marked as "late".  But I'm sure this worked when I wrote those swapfile instructions, so this is a regression.  Please enter a bug report at https://bugs.freebsd.org/bugzilla/.


----------



## sametsis (Nov 19, 2014)

Add late in fstab. Worked with me. 


```
md99    none    swap    sw,file=/swap,late   0       0
```


----------



## wblock@ (Nov 19, 2014)

This should be fixed in 10.1.


----------



## Justin Cook (Nov 28, 2014)

Hi there. I've just installed 10.1-RELEASE and had the exact same issue.


```
FreeBSD fbsdg-1 10.1-RELEASE FreeBSD 10.1-RELEASE #0 r274401: Tue Nov 11 21:02:49 UTC 2014     root@releng1.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64
```


```
% cat /etc/fstab 
# Device    Mountpoint    FStype    Options            Dump    Pass#
/dev/ada0a    /        ufs    rw            1    1
md99        none        swap    sw,file=/usr/swap0,late    0    0
```


----------



## zsero (Nov 12, 2015)

I can confirm that the issue is still present in 10.2. `swapon -aL` mounts the file but after reboot it's not present. I tried both md99 and md42.


----------



## zsero (Nov 12, 2015)

A temporary workaround while this gets fixed is to put the swap line in a separate fstab file and mount it manually in rc.local:


```
echo "md99 none swap sw,file=/usr/swap0 0 0" >> /etc/fstab_fix
echo "swapon -F /etc/fstab_fix -aL" > /etc/rc.local
```


----------

