星期二, 4月 12, 2005

FreeBSD: 增加 Swap 空間

增加Swap空間的方法有三:
  1. Swap On A New Hard Disk
  2. Swap Over NFS
  3. Swapfiles
若有方便的話,新的硬碟或直接利用Swapfiles應該都會蠻方便的。
以下列出增加 Swapfile 方式:(4.X和5.X方式不一樣)

Example 11-1. Creating a Swapfile on FreeBSD 4.X

1.Be certain that your kernel configuration includes the vnode driver. It is not in recent versions of GENERIC.
pseudo-device vn 1 #Vnode driver (turns a file into a device)
2.Create a vn-device:
# cd /dev
# sh MAKEDEV vn0

3.Create a swapfile (/usr/swap0):
# dd if=/dev/zero of=/usr/swap0 bs=1024k count=64

4.Set proper permissions on (/usr/swap0):
# chmod 0600 /usr/swap0

5.Enable the swap file in /etc/rc.conf:
swapfile="/usr/swap0" # Set to name of swapfile if aux swapfile desired.

6.Reboot the machine or to enable the swap file immediately, type:
# vnconfig -e /dev/vn0b /usr/swap0 swap

Example 11-2. Creating a Swapfile on FreeBSD 5.X

1.Be certain that your kernel configuration includes the memory disk driver (md(4)). It is default in GENERIC kernel.
device md# Memory "disks"

2.Create a swapfile (/usr/swap0):
# dd if=/dev/zero of=/usr/swap0 bs=1024k count=64

3.Set proper permissions on (/usr/swap0):
# chmod 0600 /usr/swap0

4.Enable the swap file in /etc/rc.conf:
swapfile="/usr/swap0"# Set to name of swapfile if aux swapfile desired.

5.Reboot the machine or to enable the swap file immediately, type:
# mdconfig -a -t vnode -f /usr/swap0 -u 0 && swapon /dev/md0