Linux-添加虚拟内存,不添加硬盘方式操作

在linux中,当物理内存mem不足时,就会使用虚拟内存(swap分区)

例如增加2G虚拟内存,操作如下:

1.查看内存大小

root@localhost \~# free -m

2.创建要作为swap分区的文件:增加1GB大小的交换分区,则命令写法如下,其中的count等于想要的块的数量(bs*count=文件大小)

root@localhost \~# dd if=/dev/zero of=h bs=1M count=1024

3.目录空间大小

root@localhost \~# du -sh h

4.格式化为交换分区文件

root@localhost \~# mkswap h #建立swap的文件系统

5.启用交换分区文件:

root@localhost \~# swapon h #启用swap文件

6.查看下扩充后的内存

root@localhost \~# free -m #查看swap添加了1G内存

7.使系统开机时自启用,在文件/etc/fstab中添加一行:

/root/swapfile swap swap defaults 0 0

8.关闭某个分区

root@localhost \~# swapoff h

相关推荐
未济1 天前
linux 配置环境变量
linux
傲世仙尊1 天前
目录即文件-Ext文件系统收尾篇
linux·c语言
_艾伦 耶格尔.1 天前
进程间通信
linux
Liuqy-051 天前
Linux IO编程——静态库、动态库
linux
彧azz1 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
-梅1 天前
linux(8) 软硬链接
linux·运维·服务器
AIgorithmGEEK1 天前
[Linux]线程三部曲(上):一个执行流的诞生——从操作系统一路拆到 pthread_create
linux·线程·pid
琥珀色糖2 天前
SimlpeHttp
linux·服务器
qeen872 天前
【Linux】操作系统之进程介绍(二)
linux·笔记·学习·进程
Zenova EdgeOS2 天前
Linux ss 工业边缘网络分析实战
linux·python·边缘计算·工业网关