手动增长swap空间
一、可能遇到的需求:某一个程序须要大一点的swap分区,须要咱们手动增长swap分区
首先在文件系统中建立一个模拟的磁盘出来:
dd if=/dev/zero of=/tmp/newdisk bs=1M count=100
dd命令:是用来操做磁盘的,能够读、写;if指定从哪里去读;of指定将0写到哪里去;bs指定每个块的大小为1M;newdisk大小=count乘以100(即newdisk大小为100M)
[root@linux-01 ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 4.65032 s, 22.5 MB/s
[root@linux-01 ~]# du -sh /tmp/newdisk
100M /tmp/newdisklinux
二、建立完虚拟磁盘后须要格式化:
[root@linux-01 ~]# mkswap -f /tmp/newdisk
Setting up swapspace version 1, size = 102396 KiB
no label, UUID=a211ca68-dba6-4e06-8e64-999c31ba4555安全
三、把新加的100Mswap加载到如今的swap上,使用swapon命令:
[root@linux-01 ~]# free -m
total used free shared buff/cache available
Mem: 976 131 584 6 259 660
Swap: 2047 0 2047 //未加载前swap分区大小2047
[root@linux-01 ~]# swapon /tmp/newdisk
swapon: /tmp/newdisk: insecure permissions 0644, 0600 suggested. //提示权限不安全
[root@linux-01 ~]# free -m
total used free shared buff/cache available
Mem: 976 131 585 6 259 660
Swap: 2147 0 2147 //加载完100M以后能够查看到swap大小为2147M
[root@linux-01 ~]# chmod 0600 /tmp/newdisk //更改newdisk权限为0600markdown
四、卸载新增长的swap:使用swapoff命令:
[root@linux-01 ~]# swapoff /tmp/newdisk
[root@linux-01 ~]# free -m
total used free shared buff/cache available
Mem: 976 129 587 6 259 663
Swap: 2047 0 2047 //卸载完成以后swap大小恢复为2047M
不想要能够删除掉newdisk:
[root@linux-01 ~]# rm -f /tmp/newdiskide