2. Create a swap file in Linux
A swap file is an ordinary file to the Linux kernel.
The only difference between a swap file and an ordinary file is that it
has no holes, and it is prepared for use with command mkswap.
It must reside on a local disk, however, it cannot reside in a filesystem
that has been mounted over NFS.
It is important that a swap file contains no holes. The purpose to create a swap file is that the kernal can swap out a page quickly without having to go through all the things that are necessary when allocating a disk sector to a file. The kernal only uses any ssectors that have already been allocated to the file. But a hole in a file means that there are no disk sectors allocated.
One good way to create a swap file without holes is through the following commands:
% dd if=/dev/zero of=/etc/swapfile bs=1000 count=10
- Create a file named swapfile in
the directory /etc with block size 1K, 10 blocks and no holes.
% mkswap /etc/swapfile 1000
- Make the "swapfile " a swap
file.
% swapon /etc/swapfile
- Initialize the use of this
swap file.
3. Share a swap area with other operating systems
Virtual memory is built to many operating systems.
Since these operating systems will not run at the same time, and they need
the virtual memory only when they are running, the swap areas for them
except the currently active one is wasted. It will be more efficient
if the operating systems can share the common swap area.
1)Format the partition as a dos partition, and create
the Windows swap file on it, but don't run windows yet.
(You want to keep the swap file
completely empty for now, so that it compresses well).
2)Boot linux and save the partition into a file. For example
if the partition was /dev/hda8:
dd if=/dev/hda8 of=/etc/dosswap
3)Compress the dosswap file; since it is virtually all
0's it will compress very well:
gzip -9 /etc/dosswap
4)Add the following to the /etc/rc file to prepare and
install the swap space under Linux: XXXXX is the number of blocks in the
swap partition
mkswap /dev/hda8 XXXXX
swapon -av
Make sure you add an entry for the swap partition in
your /etc/fstab file
5)If your init/reboot package supports /etc/brc or /sbin/brc
add the following to /etc/brc, else do this by hand when you want to boot
to dos|os/2 and you want to convert the swap partition back to the dos/windows
version:
swapoff
-av
zcat
/etc/dosswap.gz | dd of=/dev/hda8 bs=1k count=100