(轉) linux下增加swap分割槽

polestar123發表於2009-05-06
方法一
一、檢視系統當前的分割槽情況:

>free -m
二、建立用於交換分割槽的檔案:

>dd if=/dev/zero of=/whatever/swap bs=block_size count=number_of_block

三、設定交換分割槽檔案:
>mkswap /whatever/swap

四、立即啟用交換分割槽檔案:
>swapon /whateever/swap

五、若要想使開機時自啟用,則需修改檔案/etc/fstab中的swap行:

/whatever/swap swap swap defaults 0 0


方法二
增加交換分割槽空間的方法:
1.檢視一下/etc/fstab確定目前的分割槽
2.swapoff /dev/hd**
3.free 看一下是不是停了.
4.fdisk 刪了停掉的swap分割槽
5.重新用FDISK建一個新的SWAP分割槽
6.mkswap /dev/hd**把新的分割槽做成swap
7.swapon /dev/hd**開啟swap
8.修改/etc/fstab



操作例項:
1.檢視系統Swap空間使用
# free
total used free shared buffers cached
Mem: 513980 493640 20340 0 143808 271780
-/+ buffers/cache: 78052 435928
Swap: 1052248 21256 1030992

2.在空間合適處建立swap檔案
# mkdir swap
# cd swap
# dd if=/dev/zero of=swapfile bs=1024 count=10000
10000+0 records in
10000+0 records out
# ls -al
total 10024
drwxr-xr-x 2 root root 4096 7月 28 14:58 .
drwxr-xr-x 19 root root 4096 7月 28 14:57 ..
-rw-r--r-- 1 root root 10240000 7月 28 14:58 swapfile


# mkswap swapfile
Setting up swapspace version 1, size = 9996 KiB

3.啟用swap檔案
# swapon swapfile
# ls -l
total 10016
-rw-r--r-- 1 root root 10240000 7月 28 14:58 swapfile
# free
total used free shared buffers cached
Mem: 513980 505052 8928 0 143900 282288
-/+ buffers/cache: 78864 435116
Swap: 1062240 21256 1040984

生成1200M的檔案

# dd if=/dev/zero of=swapfile bs=1024 count=1317000

建立為swap檔案

#mkswap swapfile

讓swap生效

#swapon swapfile
檢視一下swap
#swapon -s
Filename Type Size Used Priority

/dev/sda3 partition 8024 2504 -3

/var/swapfile file 1316992 0 -4

加到fstab檔案中讓系統引導時自動啟動
#vi /etc/fstab
/var/swapfile swap swap defaults 0 0


在Linux下增加Swap區
1.檢視系統Swap空間使用

# free
total used free shared buffers cached
Mem: 513980 493640 20340 0 143808 271780
-/+ buffers/cache: 78052 435928
Swap: 1052248 21256 1030992

2.在空間合適處建立swap檔案

# mkdir swap
# cd swap
# dd if=/dev/zero of=swapfile bs=1024 count=10000
10000+0 records in
10000+0 records out
# ls -al
total 10024
drwxr-xr-x 2 root root 4096 7月 28 14:58 .
drwxr-xr-x 19 root root 4096 7月 28 14:57 ..
-rw-r--r-- 1 root root 10240000 7月 28 14:58 swapfile
z

# mkswap swapfile
Setting up swapspace version 1, size = 9996 KiB


3.啟用swap檔案
# swapon swapfile
# ls -l
total 10016
-rw-r--r-- 1 root root 10240000 7月 28 14:58 swapfile
# free
total used free shared buffers cached
Mem: 513980 505052 8928 0 143900 282288
-/+ buffers/cache: 78864 435116
Swap: 1062240 21256 1040984
#[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70612/viewspace-1021765/,如需轉載,請註明出處,否則將追究法律責任。

相關文章