Add swap memory without repartitioning the disk
From OpenFSG
These are the steps to add more swap memory to the FSG without repartitionning the disk.
Contents |
Introduction
Before adding more swap memory, you should investigate whether you actually need more swap memory: Linux uses all RAM that is not used by processes as buffer, e.g. for caching disk accesses. Hence, the fact that almost all RAM is used, is not an indicator that you need more swap memory. Instead, you better check how much from your already existing swap memory is used: Only, if almost all swap memory is used, you may want to add further swap memory.
Example: In the output of the "free" command below, you see that that almost all "mem" (=RAM) is used (60352 out of 61940). However, none of the swap memory is used. Hence, absolutely no additional swap is required in that case.
Procedure
Preparation
Check the initial swap memory with the "free" command to compare in the last step the new available amount of free swap memory.
[root@FSG:~]# free
total used free shared buffers
Mem: 61940 60352 1588 0 12948
Swap: 72284 0 72284
Total: 134224 60352 73872
As you could see, the initial available swap is about 70Mb (72284 bytes).
Procedure
In this example, we will create a 64Mb swap file. Calculate the bytes in 64 Mb = 1024*64 = 65536.
- Create the directory where the swap will be allocated:
mkdir /home/.swap/
- Create the swap file:
dd if=/dev/zero of=/home/.swap/swapfile bs=1024 count=65536
- Give swap format to the file:
mkswap /home/.swap/swapfile
- Activate the swap file as swap memory:
swapon /home/.swap/swapfile
- Check the new amount of available swap memory with the "free" command.
[root@FSG:~]# free
total used free shared buffers
Mem: 61940 60412 1528 0 12292
Swap: 137812 680 137132
Total: 199752 61092 138660
As you can see, now we've got around 134MB of swap memory (137132 bytes).
Finally, if you want to start the swap on every boot, you only have to execute the step 4 in a startup script.
