使用DD 创建SWAP
Posted imp-w
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用DD 创建SWAP相关的知识,希望对你有一定的参考价值。
1创建所需swap空间的文件
if=获取数据 of=输出位置 块大小(每次复制大小) 块个数(复制次数)
[[email protected] ~]# dd if=/dev/zero of=/tmp/100m bs=1M count=100 100+0 records in 100+0 records out 104857600 bytes (105 MB) copied, 2.01386 s, 52.1 MB/s
[[email protected] ~]# ll -h /tmp/100m
-rw-r--r--. 1 root root 100M Apr 21 13:44 /tmp/100m
2 格式化文件成为SWAP
[[email protected] ~]# mkswap /tmp/100m mkswap: /tmp/100m: warning: don‘t erase bootbits sectors on whole disk. Use -f to force. Setting up swapspace version 1, size = 102396 KiB no label, UUID=f90d8d0c-4972-42fc-83f8-4b98c651554e [[email protected] ~]# file /tmp/100m 查看文件类型是否更改为swap /tmp/100m: Linux/i386 swap file (new style) 1 (4K pages) size 25599 pages
3 让文件生效成SWAP
[[email protected] ~]# free -h total used free shared buffers cached Mem: 3.7G 2.2G 1.6G 232K 1.0G 164M -/+ buffers/cache: 972M 2.8G Swap: 1.5G 0B 1.5G
[[email protected] ~]# swapon /tmp/100m
[[email protected] ~]# free -h
total used free shared buffers cached
Mem: 3.7G 2.2G 1.6G 232K 1.0G 164M
-/+ buffers/cache: 972M 2.8G
Swap: 1.6G 0B 1.6G
4 检查swap 是由及部分组成
[[email protected] ~]# swapon -s Filename Type Size Used Priority /dev/sda2 partition 1048572 0 -1 /tmp/500m file 511996 0 -2 /tmp/100m file 102396 0 -3
5 永久挂载/开机挂载
方法1:写入 /etc/rc.local
[[email protected] ~]# cat /etc/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don‘t # want to do the full Sys V style init stuff. touch /var/lock/subsys/local #bin/mount /dev/sdc1 /date swapon /tmp/100m
方法2
[[email protected] ~]# cat /etc/fstab
/tmp/100m swap swap defaults 0 0
以上是关于使用DD 创建SWAP的主要内容,如果未能解决你的问题,请参考以下文章