ubuntu增加swap空间

来源:互联网 发布:淘宝服装店起名字大全 编辑:程序博客网 时间:2024/05/18 03:34
matthew@matthew:/$ sudo mkdir swap
mkdir: 无法创建目录"swap": 文件已存在
matthew@matthew:/$ cd swap/
matthew@matthew:/swap$ ls
matthew@matthew:/swap$ sudo dd if=/dev/zero of=swapfile bs=1024 count=8000000
记录了8000000+0 的读入
记录了8000000+0 的写出
8192000000字节(8.2 GB)已复制,63.6394 秒,129 MB/秒
matthew@matthew:/swap$ sudo swapon swap
swapon: swap:stat 失败: 没有那个文件或目录
matthew@matthew:/swap$ sudo mkswap -f swapfile
正在设置交换空间版本 1,大小 = 7999996 KiB
无标签, UUID=e84aa9ab-ac1a-45b5-8be5-abc06133e85a


matthew@matthew:/swap$ sudo swapon swapfile
matthew@matthew:/swap$ free -m
             total       used       free     shared    buffers     cached
Mem:          7886       7727        158          0          7       6951
-/+ buffers/cache:        768       7117

Swap:        11718        822      10895


补个脚本

#!/bin/bash

cd ../../../../..

cd swap/

sudo dd if=/dev/zero of=swapfile bs=1024 count=8000000 

sudo mkswap -f swapfile 

sudo swapon swapfile 

free -m


0 0