# System hangs on reboot due to swap error



## gariac (Oct 31, 2015)

FreebsdFreeBSD 10.1 on a virtual private server.

http://www.inplanesight.org/bootissue.png

I can't figure out where this message is stored on the system, hence the above screen capture. It appears that this was a bug in FreeBSD 9 but patched in 10.
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=168544

It looks like swap doesn't have to be specified in rc.conf in 10.1.

```
# swapinfo -k
Device          1K-blocks     Used    Avail Capacity
/dev/gpt/swapfs   1048576   473340   575236    45%
/dev/md99         2097152   122348  1974804     6%
Total             3145728   595688  2550040    19%
```


```
# cat fstab
# Custom /etc/fstab for FreeBSD VM images
/dev/gpt/rootfs /       ufs     rw      2       2
/dev/gpt/swapfs none    swap    sw      0       0
fdesc /dev/fd fdescfs rw 0 0
fdesc   /dev/fd         fdescfs         rw      0       0
md99 none swap sw,file=/swapfile,late 0 0
```


```
# vmstat -h
procs      memory      page                    disks     faults         cpu
r b w     avm    fre   flt  re  pi  po    fr  sr vt0 md99   in   sy   cs us sy id
1 0 1   3184M   175M    30   0   0   0    43 150   0   0    2  103   79  0  0 99
```
---------------------------------

Also does pi=po=0 indicate no swapping was done?


----------



## wblock@ (Oct 31, 2015)

This was happening when using a swap file (as you are) because the filesystem containing that swap file was unmounted before swap was turned off.  The scripts in that bug report were made unnecessary because Hiroki Sato greatly revised the capabilities of /etc/fstab and added different code to handle that situation.  I use swap files on several systems, and do not see that error.  On the other hand, those systems rarely use swap.


----------



## gariac (Nov 1, 2015)

The lack of problems similar to mine makes me wonder if this is related to the use of freebsdFreeBSD in a virtual machine.
https://www.freebsd.org/releases/10.1R/errata.htm
Adding KVM to the search led me to the link above, though I doubt Digital Ocean uses Virtual Box. But the problem could be similar.

I see that freebsdFreeBSD has a swapon(8) and swapoff(8) command. What do you think about making reboot into a script and putting `swapoff` as the first part of the script? Would the swap turn back on automatically as the system boots?

PS: thanks to I guess the administrator for applying "code" to my fields. I will do that in the future.


----------



## wblock@ (Nov 1, 2015)

If you are using `reboot`, we have found the problem.  Use `shutdown -r now`.


----------



## gariac (Nov 2, 2015)

wblock@ said:


> If you are using `reboot`, we have found the problem.  Use `shutdown -r now`.


Here is a snapshot of the shutdown as pulled off the console. This doesn't appear in /var/log/messages
http://www.inplanesight.org/images/shutdownhang.png
As you can see, the problem is still there when using `shutdown -r now`. Digital Ocean believes that the swap has to be empty upon shutdown, hence my questions about `swapoff`. I suppose the script would need to stop mail and web services prior to turning off the swap.


----------



## gariac (Nov 5, 2015)

The problem was solved by doing a `swapoff -a` prior to the reboot command. I wrote a small script to kill all the services that I figured would lead to a potential use of swap (postfix, dovecot, nginx, etc). I suppose you could go into a single user mode, but that would require me to use the Digital Ocean console rather than use the ssh session already open.


----------

