swap 分区创建与管理
1. 查看 swap 分区
- [root@localhost ~]# free -h
- total used free shared buffers cached
- Mem: 2.0G 1.0G 944M 1.5M 265M 341M
- -/+ buffers/cache: 454M 1.5G
- Swap: 4.0G 0B 4.0G #swap 分区大小
- [root@localhost ~]# fdisk -l
- Disk /dev/sda: 53.7 GB, 53687091200 bytes
- 255 heads, 63 sectors/track, 6527 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: 0x0004c723
- Device Boot Start End Blocks Id System
- /dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 548 4194304 82 Linux swap / Solaris #swap 挂载地方
Partition 2 does not end on cylinder boundary.
/dev/sda3 548 6528 48028672 83 Linux
2. 关闭开启 swap
- [root@localhost ~]# swapoff /dev/sda2
- [root@localhost ~]# free -h
- total used free shared buffers cached
- Mem: 2.0G 1.1G 923M 1.5M 265M 341M
- -/+ buffers/cache: 475M 1.5G
- Swap: 0B 0B 0B
- [root@localhost ~]# swapon /dev/sda2
- [root@localhost ~]# free -h
- total used free shared buffers cached
- Mem: 2.0G 1.0G 944M 1.5M 265M 341M
- -/+ buffers/cache: 455M 1.5G
- Swap: 4.0G 0B 4.0G
3.swap 分区扩容
- [root@localhost ~]# dd if=/dev/zero of=/opt/swapfile bs=1M count=1024 #创建一个 swap 分区
- 1024+0 records in
- 1024+0 records out
- 1073741824 bytes (1.1 GB) copied, 19.2751 s, 55.7 MB/s
- [root@localhost ~]# mkswap /opt/swapfile #格式化成 swap 格式
- mkswap: /opt/swapfile: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
- Setting up swapspace version 1, size = 1048572 KiB
- no label, UUID=565ba456-ae47-4749-a7f7-1cd26f37bdbd
- [root@localhost ~]# swapon /opt/swapfile #启用该 swap 分区, 并会自动合并到原来的 swap 分区上
- [root@localhost ~]# free -h
- total used free shared buffers cached
- Mem: 2.0G 1.9G 101M 1.5M 264M 1.1G
- -/+ buffers/cache: 466M 1.5G
- Swap: 5.0G 0B 5.0G
来源: http://www.bubuko.com/infodetail-2604372.html