首页 > 系统服务 > 详细

Linux 之 swap分区创建与管理

时间:2018-05-16 23:52:27      阅读:334      评论:0      收藏:0      [点我收藏+]
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

Linux 之 swap分区创建与管理

原文:http://blog.51cto.com/12965094/2117210

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!