添加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.178linux.com/44320