分享

修改linux swap虚拟内存大小

 海盗船长加菲 2017-11-30
1)在linux下,首先,查看内存和swap大小:
[root@rhel6 usr]# free -m
             total       used       free     shared    buffers     cached
Mem:          1386       1272        114          0         90        952
-/+ buffers/cache:        228       1158
Swap:         2047          0       2047
 
2)创建swap文件:
[root@rhel6 usr]# mkdir swap
[root@rhel6 usr]# cd swap/
[root@rhel6 swap]# dd if=/dev/zero of=swapfile bs=402400 count=10000

记录了10000+0 的读入
记录了10000+0 的写出
4024000000字节(4.0 GB)已复制,224.925 秒,17.9 MB/秒
 
[root@rhel6 swap]# ls -al
总用量 3929700
drwxr-xr-x.  2 root root       4096 2月   4 10:16 .
drwxr-xr-x. 15 root root       4096 2月   4 10:15 ..
-rw-r--r--.  1 root root 4024000000 2月   4 10:20 swapfile
 
[root@rhel6 swap]# mkswap swapfile
mkswap: swapfile: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 3929680 KiB
no label, UUID=4e2ce2fe-3963-46ce-90cd-466495cd8ca8
 
3)激活swap文件:
[root@rhel6 swap]# swapon swapfile
[root@rhel6 swap]# free -m
             total       used       free     shared    buffers     cached
Mem:          1386       1296         90          0         82        975
-/+ buffers/cache:        239       1147
Swap:         5885          0       5885
 
4)若想要开机时自启动,需要修改文件/etc/fstab中的swap行:
[root@rhel6 swap]# vi /etc/fstab 
UUID=8c6bea6a-3bba-4594-b5a8-fd4afd311476 swap                    swap    defaul
ts        0 0
/usr/swap/swapfile                                                swap    defaul
ts        0 0

jesus love you!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多