Linux 之 swap分区创建与管理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 之 swap分区创建与管理相关的知识,希望对你有一定的参考价值。
swap分区创建与管理
1.查看swap分区
[[email protected] ~]# 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分区大小
[[email protected] ~]# 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
[[email protected] ~]# swapoff /dev/sda2
[[email protected] ~]# 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
[[email protected] ~]# swapon /dev/sda2
[[email protected] ~]# 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分区扩容
[[email protected] ~]# 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
[[email protected] ~]# 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
[[email protected] ~]# swapon /opt/swapfile #启用该swap分区,并会自动合并到原来的swap分区上
[[email protected] ~]# 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
以上是关于Linux 之 swap分区创建与管理的主要内容,如果未能解决你的问题,请参考以下文章