手动添加swap分区

1.使用 dd 命令在/tmp下造一个分区

[root@localhost ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.200887 秒,522 MB/秒

/tmp目录为临时目录,重启后会清空文件

dd 命令:

介绍:在磁盘中写入数据

dd if=/dev/zero of=/tmp/newdisk bs=1M count=100 :往/tmp/newdisk 中写入100M的数据

  • if :输出,/dev/zero 是一个无限输入0的文件

  • of :输入

  • bs :每个块的大小

  • count:块的数量

2.格式化分区

[root@localhost ~]# swapon /tmp/newdisk
swapon: /tmp/newdisk:不安全的权限 0644,建议使用 0600。
[root@localhost ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            974         127         596           7         250         675
Swap:          2147           0        2147

swapon 命令删除分区

free 查看系统内存

3.删除分区

[root@localhost ~]# swapoff /tmp/newdisk 
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           974M        127M        596M        7.6M        250M        676M
Swap:          2.0G          0B        2.0G

swapoff 命令删除系统分区

最后更新于

这有帮助吗?