
# mkdir /nfsroot/tmp/var
# chmod 0 /nfsroot/tmp/var
# ln -s /tmp/var /nfsroot/var/tmp
|
Another good way to reduce memory consumption if you don't have local hard drives and do not swap over a network block device is to disable the Swapping to block devices option during kernel compilation.
If your stations do not have enough memory and do not have local drives, you may want to swap over NFS. You have to be warned the cod eto do so is still under development and this method is generally quite slow. The full documentation for this can be found at http://www.instmath.rwth-aachen.de/~heine/nfs-swap/.
The first thing to do if you want to apply this solution is to patch your kernel (you need a kernel version 2.2 or above). First download the patch at the above url, and cd to /usr/src/linux. I assume the patch is in /usr/src/patch. Then issue the following command:
# cat ../patch | patch -p1 -l -s
|
Then export a directory read-write and no_root_squash from the NFS server. Setup the clients so that they will mount it somewhere (say on /mnt/swap). It should be mounted with a rsize and wsize smaller than the page size used by the kernel (ie. 4 kilobytes on Intel architectures), otherwise your machine may run out of memory due to memory fragmentation; see the nfs manual page for details about rsize and wsize. Now, to create a 20 MB swap file, issue the following commands (which should be placed in the clients'initialization scripts):
# dd if=/dev/zero of=/mnt/swap/swapfile bs=1k count=20480
# mkswap /mnt/swap/swapfile
# swapon /mnt/swap/swapfile
|
Let's say a word about the drawbacks of NFS swapping: the first drawback is that it is generally slow, except you have specially fast network cards. Then, this possibility has not been very well tested yet. At last, this is not secure at all: anyone on the network is able to read the swapped data.
# dd if=/dev/zero of=/swap/swapfile bs=1k count=20480
# nbd-server NBDclient 1024 /swap/swapfile
# mkswap /swap/swapfile
|
# swapon /dev/nd0
|
Again, this was just to show the general principle. The files'names should also be dependant on the workstations'names or IPs.
Another solution to swap over a network block device is to create an ext2 filesystem on the NBD, then create a regular file on this filesystem, and at last, use mkswap and swapon to start swapping on this file. This second method method is closer to the swap over NFS method than the first solution.
The following commands, issued on the server may solve the problem:
# ln -s /proc/mounts /nfsroot/etc/mtab
# touch /nfsroot/proc/mounts
|
# chroot /nfsroot
|
Debian users will be particularly interested in the --root option of dpkg, which simply tells dpkg where the root of the target system is.