Linux手动添加swap分区
用法:dd [操作数] ...
或:dd 选项
Copy a file, converting and formatting according to the operands.
bs=BYTES read and write up to BYTES bytes at a time
cbs=BYTES convert BYTES bytes at a time
conv=CONVS convert the file as per the comma separated symbol list
count=N copy only N input blocks
ibs=BYTES read up to BYTES bytes at a time (default: 512)
if=FILE read from FILE instead of stdin
iflag=FLAGS read as per the comma separated symbol list
obs=BYTES write BYTES bytes at a time (default: 512)
of=FILE write to FILE instead of stdout
oflag=FLAGS write as per the comma separated symbol list
seek=N skip N obs-sized blocks at start of output
skip=N skip N ibs-sized blocks at start of input
status=LEVEL The LEVEL of information to print to stderr;
‘none‘ suppresses everything but error messages,
‘noxfer‘ suppresses the final transfer statistics,
‘progress‘ shows periodic transfer statistics
N and BYTES may be followed by the following multiplicative suffixes:
c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024, xM =M
GB =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y.
Each CONV symbol may be:
ascii from EBCDIC to ASCII
ebcdic from ASCII to EBCDIC
ibm from ASCII to alternate EBCDIC
block pad newline-terminated records with spaces to cbs-size
unblock replace trailing spaces in cbs-size records with newline
lcase change upper case to lower case
ucase change lower case to upper case
sparse try to seek rather than write the output for NUL input blocks
swab swap every pair of input bytes
sync pad every input block with NULs to ibs-size; when used
with block or unblock, pad with spaces rather than NULs
excl fail if the output file already exists
nocreat do not create the output file
notrunc 不截断输出文件
noerror 读取数据发生错误后仍然继续
fdatasync 结束前将输出文件数据写入磁盘
fsync 类似上面,但是元数据也一同写入
FLAG 符号可以是:
append 追加模式(仅对输出有意义;隐含了conv=notrunc)
direct 使用直接I/O 存取模式
directory 除非是目录,否则 directory 失败
dsync 使用同步I/O 存取模式
sync 与上者类似,但同时也对元数据生效
fullblock 为输入积累完整块(仅iflag)
nonblock 使用无阻塞I/O 存取模式
noatime 不更新存取时间
nocache Request to drop cache. See also oflag=sync
noctty 不根据文件指派控制终端
nofollow 不跟随链接文件
count_bytes treat ‘count=N‘ as a byte count (iflag only)
skip_bytes treat ‘skip=N‘ as a byte count (iflag only)
seek_bytes treat ‘seek=N‘ as a byte count (oflag only)
Sending a USR1 signal to a running ‘dd‘ process makes it
print I/O statistics to standard error and then resume copying.
Options are:
--help 显示此帮助信息并退出
--version 显示版本信息并退出
GNU coreutils online help:
<
http:
//www.gnu.org/software/coreutils
/>
请向
<
http:
//translationproject.org/team/zh_CN.html
>
报告dd 的翻译错误
Full documentation at:
<
http:
//www.gnu.org/software/coreutils/dd
>
or available locally via: info ‘(coreutils) dd invocation‘
1. 检查当前的swap分区情况
# free –m
total used free shared buffers cached
Mem: 1006 84 922 0 11 38
-/+ buffers/cache: 35 971
Swap: 0 0 0
2. 增加交换分区文件及大小
如上,当前swap分区的大小为0,假如需要增加1024M的大小。
判定新交换文件的大小,将大小乘以1024来判定块的大小。例如,大小为64MB的交换文件的块大小为65536,在 shell 提示下以根用户身份键入以下命令,其中的 count 等于想要的块大小。
# dd if=/dev/zero of=/home/swap bs=1M count=1024
1024000+0 records in
1024000+0 records out
格式化交换文件,将swap文件格式化成s文件系统,系统才能使用
# mkswap /home/swap
Setting up swapspace version 1, size = 1023996 KiB
3. 启动交换分区文件
假如想立即启用交换分区文件,请执行:
# swapon /home/swap
要停止使用新创建的swap文件,只要执行 swapoff/home/swap命令即可.
检验增加后的swap分区大小
# free -m
total used free shared buffers cached
Mem: 1006 994 12 0 4 929
-/+ buffers/cache: 60 946
Swap: 999 0 999
4. 如希望在系统再次启动时,自动启用刚增加的swap,可编辑/etc/fstab文件:
# vi /etc/fstab,增加如下行
/home/swap swap swap defaults 0 0
5.修改linux swap空间的swappiness,降低对硬盘的缓存
linux 会使用硬盘的一部分做为SWAP分区,用来进行进程调度--进程是正在运行的程序--把当前不用的进程调成‘等待(standby)‘,甚至‘睡眠(sleep)’,一旦要用,再调成‘活动(active)’,睡眠的进程就躺到SWAP分区睡大觉,把内存空出来让给‘活动’的进程。
如果内存够大,应当告诉 linux 不必太多的使用 SWAP 分区, 可以通过修改 swappiness 的数值。swappiness=0的时候表示最大限度使用物理内存,然后才是 swap空间,swappiness=100的时候表示积极的使用swap分区,并且把内存上的数据及时的搬运到swap空间里面。在ubuntu 里面,默认设置swappiness这个值等于60。
!!!! 如果内存较小,而进程调度频繁,硬盘的响动就会大了 !!!!
现在一般1个G的内存可修改为10, 2个G的可改为5, 甚至是0。具体这样做:
1.查看你的系统里面的swappiness
$ cat /proc/sys/vm/swappiness
不出意外的话,你应该看到是 60
2.修改swappiness值为10
$ sudo sysctl vm.swappiness=10
但是这只是临时性的修改,在你重启系统后会恢复默认的60,为长治久安,还要更进一步:
$ sudo vi /etc/sysctl.conf
在这个文档的最后加上这样一行:
vm.swappiness=10
然后保存,重启。ok,你的设置就生效了。
原文:http://www.cnblogs.com/cdyboke/p/7413923.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!