添加swap交換分區
SWAP即交換分區是一種類似于Windows系統虛擬內存的功能,將一部分硬盤空間虛擬成內存來使用,從而解決內存容量不足的情況,因為SWAP畢竟是用硬盤資源虛擬的,所以速度上比真實物理內存要慢很多,一般只有當真實物理內存耗盡時才會調用SWAP。
1、創建一個分區,看上篇文章,別著急w保存退出
修改分區的類型輸入t
:
Command (m for help): t
Selected partition 1
2、查看可用的分區類型,輸入L
:
Hex code (type L to list all codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
3、輸入82
代表swap分區:
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap / Solaris)
4、再次查看分區表信息(已有分區信息):
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 / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 82 Linux swap / Solaris
5、保存分區表的設置:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
6、讓內核同步分區信息(此步驟僅在沒有找到分區設備的情況下才需要執行,非必要動作。):
[root@localhost ~]# partprobe
7、將sdb1分區設備格式化為swap類型:
[root@localhost ~]# mkswap /dev/sdb1
mkswap: /dev/sdb1: warning: don't erase bootbits sectors
(dos partition table detected). Use -f to force.
Setting up swapspace version 1, size = 2104476 KiB
no label, UUID=a77266ac-b078-45f7-a329-b95219d90e2b
8、查看當前的內存使用量情況,SWAP大小為2047:
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 980 651 329 0 62 438
-/+ buffers/cache: 150 829
Swap: 2047 0 2047
9、將sdb1的SWAP分區啟用:
[root@localhost ~]# swapon /dev/sdb1
10、再次查看當前系統的內存使用量情況(此時SWAP為4103m):
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 980 652 328 0 62 438
-/+ buffers/cache: 151 828
Swap: 4103 0 4103
11、設置為開機后自動掛載該SWAP分區設備:
[root@localhost ~]# vim /etc/fstab
/dev/sdb1 swap swap defaults 0 0
原創文章,作者:M20_he,如若轉載,請注明出處:http://www.www58058.com/44320