Swap: 

$ dd if=/dev/zero of=/path/to/swapfile bs=1M count=1024 # For 1GB swap file. Wouldn't fallocate -l 1G /swapfile be better?
$ sudo chmod 600 /swapfile # optional
$ mkswap /path/to/swapfile
$ swapon /path/to/swapfile
From http://raspberrypi.stackexchange.com/questions/70/how-to-set-up-swap-space

read only filesystem: http://blog.pi3g.com/2014/04/make-raspbian-system-read-only/