修改linux swap虚拟内存大小

本文介绍如何在Linux系统中查看内存和swap分区的大小,并详细展示了创建新的swap文件、激活该文件以及设置为开机自启的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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              2047
 
2)创建swap文件:
[root@rhel6 usr]# mkdir swap
[root@rhel6 usr]# cd swap/
[root@rhel6 swap]# dd if=/dev/zero of=swapfile bs=402400count=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月   410: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              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!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值