[转载]How To Add Swap on Ubuntu 12.04
How To Add Swap on Ubuntu 12.04
Aug 17, 2012 Linux Basics Ubuntu
About Linux Swapping
Linux RAM is composed of chunks of memory called pages. To free up pages of RAM, a “linux swap” can occur and a page of memory is copied from the RAM to preconfigured space on the hard disk. Linux swaps allow a system to harness more memory than was originally physically available.
However, swapping does have disadvantages. Because hard disks have a much slower memory than RAM, virtual private server performance may slow down considerably. Additionally, swap thrashing can begin to take place if the system gets swamped from too many files being swapped in and out.
Check for Swap Space
Before we proceed to set up a swap file, we need to check if any swap files have been enabled on the VPS by looking at the summary of swap usage.
sudo swapon -s
An empty list will confirm that you have no swap files enabled:
Filename Type Size Used Priority
Check the File System
After we know that we do not have a swap file enabled on the virtual server, we can check how much space we have on the server with the df command. The swap file will take 256MB— since we are only using up about 8% of the /dev/sda, we can proceed.
df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda 20907056 1437188 18421292 8% /
udev 121588 4 121584 1% /dev
tmpfs 49752 208 49544 1% /run
none 5120 0 5120 0% /run/lock
none 124372 0 124372 0% /run/shm
Create and Enable the Swap File
Now it’s time to create the swap file itself using the dd command :
sudo dd if=/dev/zero of=/swapfile bs=1024 count=256k
“of=/swapfile” designates the file’s name. In this case the name is swapfile.
Subsequently we are going to prepare the swap file by creating a linux swap area:
sudo mkswap /swapfile
The results display:
Setting up swapspace version 1, size = 262140 KiB
no label, UUID=103c4545-5fc5-47f3-a8b3-dfbdb64fd7eb
Finish up by activating the swap file:
sudo swapon /swapfile
You will then be able to see the new swap file when you view the swap summary.
swapon -s
Filename Type Size Used Priority
/swapfile file 262140 0 -1
This file will last on the virtual private server until the machine reboots. You can ensure that the swap is permanent by adding it to the fstab file.
Open up the file:
sudo nano /etc/fstab
Paste in the following line:
/swapfile none swap sw 0 0
Swappiness in the file should be set to 10. Skipping this step may cause both poor performance, whereas setting it to 10 will cause swap to act as an emergency buffer, preventing out-of-memory crashes.
You can do this with the following commands:
echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
To prevent the file from being world-readable, you should set up the correct permissions on the swap file:
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
[转载]How To Add Swap on Ubuntu 12.04的更多相关文章
- How To Add Swap on Ubuntu 14.04
https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04 How To Add Swap on ...
- [转]Ubuntu 12.04 安装屏保
From:http://www.howtogeek.com/114027/how-to-add-screensavers-to-ubuntu-12.04/ How to Add Screensaver ...
- Get back Typing Break in Ubuntu 12.04 & 11.10(转载)
转自:http://ubuntuguide.net/get-back-typing-break-in-ubuntu-12-04-11-10 Since Ubuntu 11.10 Oneiric, th ...
- Ubuntu 12.04的gnome classic panel添加程序快捷键(转载)
How to add applets to the Gnome classic panel in Ubuntu 12.04 转自:http://www.borfast.com/blog/how-add ...
- 【NS2】Ubuntu 12.04 LTS 中文输入法的安装(转载)
本文是笔者使用 Ubuntu 操作系统写的第一篇文章!参考了红黑联盟的这篇文章:Ubuntu 12.04中文输入法的安装 安装 Ubuntu 12.04 着实费力一番功夫,老是在用 Ubuntu 来引 ...
- [转载] Ubuntu 12.04下安装git,SSH及出现的Permission denied解决办法
如何安装ssh http://os.51cto.com/art/201109/291634.htm 仅需要阅读至成功开启ssh服务即可 http://www.linuxidc.com/Linux/20 ...
- ubuntu 12.04 alt+tab无法切换窗口的问题(转载)
转自:http://www.2cto.com/os/201209/153282.html ubuntu 12.04 alt+tab无法切换窗口的问题 安装cpmpiz配置管理程序. sudo ...
- Ubuntu 12.04 设置终端字体为文泉驿(转载)
转自:http://my.oschina.net/uniquejava/blog/98480 0.说明 在gnome-terminal终端中看习惯了文泉驿微米黑字体,没想到从11.10升级到 ...
- Ubuntu 12.04 root默认密码? 如何使用root登录? (转载)
转自:http://www.lupaworld.com/article-219280-1.html 在安装Ubuntu 12.04时并没有设置root的密码,登录的时候也没有使用root账户.当我们使 ...
随机推荐
- url地址中 "&" "/"等符号的转义处理(转)
URL出现了有+,空格,/,?,%,#,&,=等特殊符号的时候,可能在服务器端无法获得正确的参数值,如何是好? 解决办法:将这些字符转化成服务器可以识别的字符,对应关系如下: URL中的特殊字 ...
- ios调用系统导航
#import "ViewController.h" #import <MapKit/MapKit.h> @interface ViewController () @p ...
- 浅谈JSON.parse()、JSON.stringify()和eval()的作用
(1)JSON.parse 函数 var json = '{"name":"GDT","age":23,"University&q ...
- 【SQL 数据库】将一张数据表信息复制到另一张数据表
一.MySQL数据库 1.如果目标表存在 INSERT INTO 目标表 SELECT * FROM 源表; 2.如果目标表不存在 CREATE TABLE 目标表 SELECT * FROM ...
- kylin学习笔记
阅读官网,学到哪就写到哪 1.需要先建立Model 2.kylin需要配置事实表,纬度表:可以自定义join. 我的用法和官方建议的不同,我是直接在hive中将所有的取join成一个单表,再根据单表 ...
- 从客户端(CourseIssueContent="<P>财务审计师岗位认证招生简章<BR>...")中检测到有潜在危险的 Request.Form 值。
说明: 请求验证过程检测到有潜在危险的客户端输入值,对请求的处理已经中止.该值可能指示危及应用程序安全的尝试,如跨站点的脚本攻击.通过在 Page 指令或 配置节中设置 validateRequest ...
- 服装PDA软件|服装销售开单PDA管理软件|服装PDA管理系统|服装PDA点货系统|服装移动POS系统
浩瀚软件为了更好服务于广大批发客户群体进行销售.盘点.调拨配送等.深圳浩瀚软件推出基于无线网络版移动PDA销售开单系统.该系统支持无线3G.WIFI.GPRS系统,用户可以手持PDA在无线网络连接状态 ...
- 浩瀚科技PDA移动开单|盘点机 数据采集器 条码扫描开单微POS软件 现场打印开单
PDA移动开单,是我公司的一款便携式开单配套产品,PDA能通过蓝牙.无线局域网.互联网直接与主机连接,让公司业务人员能随时随地了解公司产品信息并且进行开单.入库.库存.盘点等一系列进销存操作.是现今企 ...
- js-js实现,在HTML中使用JavaScript,基本概念
Js实现: 1.JavaScript实现的组成: 核心(ECMAScript):由ECMA-262定义,提供核心语言功能 文档对象模型(DOM)提供访问和操作网页内容的方法以及接口 浏览器对象模型(B ...
- wpf,CollectionViewSource,使用数据过滤 筛选 功能。
class TextListBoxVMpublic : ViewModelBase { public TextListBoxVMpublic() { var list = this.GetEmploy ...