Categories

How to Swap to NFS Mount

Let’s say we have a computer booted over network and “/” is mounted over NFS.

The best sutuation is if we have enough RAM for all running programs. But sometimes we need to swap. No local disk – swap to remote.

Make an empty file (fill with zeros from /dev/zero):

root@kamera:/# dd if=/dev/zero of=/swap bs=1024 count=1048576

Simply swap to file over NFS may not work. So make a loop device:

root@kamera:/# losetup /dev/loop0 /swap

Make it suitable for swapping:

root@kamera:/# mkswap /dev/loop0
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=931d6e04-78ec-41fd-ab2c-22522ac2711d

And swap:

root@kamera:/# swapon /dev/loop0

Write a script to make this swap permanent. /etc/init.d/swap may be like this:

#!/bin/sh

set -e

case "$1" in
start)
losetup /dev/loop0 /swap
swapon /dev/loop0
;;
stop)
swapoff /dev/loop0
losetup -d /dev/loop0
;;
restart)
swapoff /dev/loop0
swapon /dev/loop0
;;
*)
echo "Naudojimas: swap { start | stop | restart }" >&2
exit 1
;;
esac

exit 0

Make the file executable:

root@kamera:/# chmod +x /etc/init.d/swap

Enable it:

root@kamera:/# update-rc.d swap defaults

1 comment to How to Swap to NFS Mount

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>