内存交换空间(swap)的构建
2016-03-29 17:47
399 查看
一、使用物理分区构建swap
1、先进行分区的行为。
强制内核更新分区表:
2、开始构建swap格式。
3、查实查看与加载。
二、使用文件系统构建swap
1、使用dd这个命令来新增一个128MB的文件在/data下面:
2、使用mkswap将/data/swap这个文件格式化为swap的文件格式:
3、使用swapon来将/data/swap启动
使用swapoff关掉swapfile
为了能够让swap自动挂载,要修改/etc/fstab文件
在文件末尾加上
/data/swap swap swap default 0 0
这样就算重启系统,swap分区就不用手动挂载了。
1、先进行分区的行为。
[root@iZ255cppmtxZ ~]# fdisk /dev/xvdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (1,3,4, default 1): 4 First sector (20973568-62914559, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-62914559, default 62914559): +512M Partition 4 of type Linux and of size 10 GiB is set Command (m for help): p Disk /dev/xvdb: 32.2 GB, 32212254720 bytes, 62914560 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x25a2caf5 Device Boot Start End Blocks Id System /dev/xvdb2 2048 20973567 10485760 83 Linux /dev/xvdb4 20973568 41945087 10485760 83 Linux Command (m for help): t <==修改系统ID Partition number (2,4, default 4): 4 Hex code (type L to list all codes): 82 <==改成swap的ID Changed type of partition 'Linux' to 'Linux swap / Solaris' Command (m for help): p Disk /dev/xvdb: 32.2 GB, 32212254720 bytes, 62914560 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x25a2caf5 Device Boot Start End Blocks Id System /dev/xvdb2 2048 20973567 10485760 83 Linux /dev/xvdb4 20973568 41945087 10485760 82 Linux swap / Solaris Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
强制内核更新分区表:
[root@iZ255cppmtxZ ~]# partprobe
2、开始构建swap格式。
[root@iZ255cppmtxZ ~]# mkswap /dev/xvdb4 Setting up swapspace version 1, size = 5485756 KiB no label, UUID=033a1d75-88fd-4347-8726-08d856cb9ad1
3、查实查看与加载。
[root@iZ255cppmtxZ ~]# swapon /dev/xvdb4 [root@iZ255cppmtxZ ~]# free total used free shared buffers cached Mem: 1016656 152956 863700 6624 11036 75828 -/+ buffers/cache: 66092 950564 Swap: 10485756 0 10485756
[root@iZ255cppmtxZ ~]# swapon -s Filename Type Size Used Priority /dev/xvdb4 partition 10485756 0 -1
二、使用文件系统构建swap
1、使用dd这个命令来新增一个128MB的文件在/data下面:
[root@iZ255cppmtxZ ~]# dd if=/dev/zero of=/data/swap bs=1M count=512 512+0 records in 512+0 records out 536870912 bytes (537 MB) copied, 7.82149 s, 68.6 MB/s
2、使用mkswap将/data/swap这个文件格式化为swap的文件格式:
[root@iZ255cppmtxZ ~]# mkswap /data/swap Setting up swapspace version 1, size = 524284 KiB no label, UUID=ede63d44-cf78-4d08-92ca-15fb38a625f4
3、使用swapon来将/data/swap启动
[root@iZ255cppmtxZ ~]# swapon /data/swap swapon: /data/swap: insecure permissions 0644, 0600 suggested. [root@iZ255cppmtxZ ~]# free -m total used free shared buffers cached Mem: 992 670 322 6 11 586 -/+ buffers/cache: 72 919 Swap: 511 0 511 [root@iZ255cppmtxZ ~]# swapon -s Filename Type Size Used Priority /data/swap file 524284 0 -1
使用swapoff关掉swapfile
[root@iZ255cppmtxZ ~]# swapoff /dev/xvdb4 [root@iZ255cppmtxZ ~]# swapoff /data/swap
为了能够让swap自动挂载,要修改/etc/fstab文件
在文件末尾加上
/data/swap swap swap default 0 0
这样就算重启系统,swap分区就不用手动挂载了。
相关文章推荐
- 关于此次团队项目中技术选型问题
- Xcode7 使用NSURLSession发送HTTP请求的问题
- java的序列化与反序列化及transient关键字
- 1-100的Catalan数
- javaer to go之基础
- git diff查看差异
- word embedding
- 328-m-Odd Even Linked List
- VM模板学习
- java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
- mysql存储过程笔记
- Mybatis入门例子
- activity间传送bitmap的办法
- <c:forEach>循环list,<c:if>判断奇偶
- Android常见文件路径介绍
- MAC下Eclipse的启动
- eclipse 入门级使用
- 欺壹世充电系列之[Svn集中式版本管理系统] 推荐
- MySQL测试SQL执行的速度测试
- Codeforces 544E Remembering Strings 状压dp