相比較而言,Windows 不會(huì)為 swap 單獨(dú)劃分一個(gè)分區(qū),而是使用分頁(yè)文件實(shí)現(xiàn)相同的功能,在概念上,Windows 稱(chēng)其為虛擬內(nèi)存,從某種意義上將,這個(gè)叫法更容易理解。因此,初學(xué)者將 swap 交換分區(qū)理解為虛擬內(nèi)存是沒(méi)有任何問(wèn)題的。
具體使用多大的 swap 分區(qū),取決于物理內(nèi)存大小和硬盤(pán)的容量。一般來(lái)講,swap 分區(qū)容量應(yīng)大于物理內(nèi)存大小,建議是內(nèi)存的兩倍,但不超過(guò) 2GB。但是,有時(shí)服務(wù)器的訪問(wèn)量確實(shí)很大,有可能出現(xiàn) swap 分區(qū)不夠用的情況,所以我們需要學(xué)習(xí) swap 分區(qū)的構(gòu)建方法。[root@localhost ~]# fdisk /dev/sdb
#以/dev/sdb分區(qū)為例
WARNING: DOS-compatible mode is deprecated.It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').
Command (m for help): n
#新建
Command action e extended p primary partition (1-4)
P
#主分區(qū)
Partition number (1-4): 1
#分區(qū)編號(hào)
First cylinder (1-2610, default 1):
#起始柱面
Using default value 1
Last cylinder, +cylinders or +size{K, M, G} (1-2610, default 2610): +500M
#大小
Command (m for help): p
#查看一下
Disk /dev/sdb: 21.5GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 *512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes 1512 bytes
Disk identifier: OxOOOOOebd
Device Boot Start End Blocks Id System
/dev/sdb1 1 65 522081 83 linux
#剛分配的分區(qū)ID是83,是Linux分區(qū),我們?cè)谶@里要分配swap分區(qū)
Command (m for help): t
#修改分區(qū)的系統(tǒng)ID
Selected partition 1
#只有一個(gè)分區(qū),所以不用選擇分區(qū)了
Hex code (type L to list codes): 82
#改為swap分區(qū)的ID
Changed system type of partition 1 to 82 (Linux swap / Solaris)
Command (m for help): p
#再查看一下
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 *512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes 1512 bytes Disk identifier: OxOOOOOebd
Device Boot Start End Blocks Id System
/dev/sdb1 1 65 522081 82 Linux swap / Solaris
#修改過(guò)來(lái)了
Command (m for help): w
#記得保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 522076 KiB
no label, UUID=c3351 dc3-f403-419a-9666-c24615e170fb
[root@localhost ~]#free
total used free shared buffers cached
Mem: 1030796 130792 900004 0 15292 55420
-/+ buffers/cache: 60080 970716
Swap: 2047992 0 2047992
[root@localhost ~]# swapon 分區(qū)設(shè)備文件名
例如:[root@localhost ~]# swapon /dev/sdb1
swap分區(qū)已加入,我們查看一下。
[root@localhost ~]#free
total used free shared buffers cached
Mem: 1030796 131264 899532 0 15520 55500
-/+ buffers/cache: 60244 970552
Swap: 2570064 0 2570064
[root@localhost ~]# swapoff /dev/sdb1
如果想讓 swap 分區(qū)開(kāi)機(jī)之后自動(dòng)掛載,就需要修改 /etc/fstab 文件,命令如下:[root@localhost ~]#vi /etc/fstab
UUID=c2ca6f57-b15c-43ea-bca0-f239083d8bd2 / ext4 defaults 1 1
UUID=0b23d315-33a7-48a4-bd37-9248e5c443451 boot ext4 defaults 1 2
UUID=4021be19-2751-4dd2-98cc-383368c39edb swap swap defaults 0 0
tmpfs /dev/shm
tmpfs defaults 0 0
devpts /dev/pts
devpts gid=5, mode=620 0 0
sysfs /sys
sysfs defaults 0 0
proc /proc
proc defaults 0 0
/dev/sdb1 swap swap
defaults 0 0
#加入新swap分區(qū)的相關(guān)內(nèi)容,這里直接使用分區(qū)的設(shè)備文件名,也可以使用UUID。
新聞熱點(diǎn)
疑難解答
圖片精選