|
The previous sections discussed a simple way to handle workstations'specific files and directories like /var. Most of them are simply build on the fly and put on ramdisks, you may however prefer to deal with this problem on the NFS server. The clusternfs project provides a network filesystem server that can serve different files based on several criteria including the client's IP address or host name. The basic idea is that if the client whose IP address is 10.2.12.42 requests a file named, for instance, myfile, the server will look for a file named myfile$$IP=10.2.12.42$$ and serve this file instead of myfile if it is available.
One simple way to reduce memory consumption is to put several dynamically created directories on the same ramdisk. For instance, let's say the first ramdisk will contain the /tmp directory. Then, one may move the /var/tmp directory on that ramdisk with the following commands issued on the server:
# 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.
Although I have never tried it personally, I got report that the trick described below works, at least with recent kernels.
The general principle for swapping over network block devices is the same than to swap over NFS. The good point is you won't have to patch the kernel. But most of the same drawbacks also apply to the NBD method.
To create a 20 MB swap file, you will have to first create it on the server, export it to the client, and do an mkswap on the file. Note that the mkswap must be done on the server, because mkswap uses system calls which are not handled by NBD. Moreover, this command must be issued after the server starts exporting the file, because the data on the file may be destroyed when the server starts exporting it. If we assume the server's name is NBDserver, the client's name is NBDclient, and the TCP port used for the export is 1024, the commands to issue on the server are the following:
# 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 |
A simple way to do so is to use, on the server, a chroot and then execute your favourite installation commands normally. To chroot to the appropriate place, use the following command:
# 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.
Hosting by: Hurra Communications Ltd.
Generated: 2007-01-26 17:58:22