内存交换空间(swap)的构建
2024-09-04 11:10:43
一、使用物理分区构建swap
1、先进行分区的行为。
[root@iZ255cppmtxZ ~]# fdisk /dev/xvdb
Welcome to fdisk (util-linux 2.23.). 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 ( primary, extended, free)
e extended
Select (default p): p
Partition number (,,, default ):
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ): +512M Partition of type Linux and of size GiB is set Command (m for help): p Disk /dev/xvdb: 32.2 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x25a2caf5 Device Boot Start End Blocks Id System
/dev/xvdb2 Linux
/dev/xvdb4 Linux Command (m for help): t <==修改系统ID
Partition number (,, default ): 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, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x25a2caf5 Device Boot Start End Blocks Id System
/dev/xvdb2 Linux
/dev/xvdb4 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 , size = KiB
no label, UUID=033a1d75-88fd---08d856cb9ad1
3、查实查看与加载。
[root@iZ255cppmtxZ ~]# swapon /dev/xvdb4
[root@iZ255cppmtxZ ~]# free
total used free shared buffers cached
Mem:
-/+ buffers/cache:
Swap:
[root@iZ255cppmtxZ ~]# swapon -s
Filename Type Size Used Priority
/dev/xvdb4 partition -
二、使用文件系统构建swap
1、使用dd这个命令来新增一个128MB的文件在/data下面:
[root@iZ255cppmtxZ ~]# dd if=/dev/zero of=/data/swap bs=1M count=
+ records in
+ records out
bytes ( MB) copied, 7.82149 s, 68.6 MB/s
2、使用mkswap将/data/swap这个文件格式化为swap的文件格式:
[root@iZ255cppmtxZ ~]# mkswap /data/swap
Setting up swapspace version , size = KiB
no label, UUID=ede63d44-cf78-4d08-92ca-15fb38a625f4
3、使用swapon来将/data/swap启动
[root@iZ255cppmtxZ ~]# swapon /data/swap
swapon: /data/swap: insecure permissions , suggested.
[root@iZ255cppmtxZ ~]# free -m
total used free shared buffers cached
Mem:
-/+ buffers/cache:
Swap:
[root@iZ255cppmtxZ ~]# swapon -s
Filename Type Size Used Priority
/data/swap file -
使用swapoff关掉swapfile
[root@iZ255cppmtxZ ~]# swapoff /dev/xvdb4
[root@iZ255cppmtxZ ~]# swapoff /data/swap
为了能够让swap自动挂载,要修改/etc/fstab文件
在文件末尾加上
/data/swap swap swap default 0 0
这样就算重启系统,swap分区就不用手动挂载了。
最新文章
- 基于python的七种经典排序算法
- MYSQL常用内置函数详解说明
- Android 蓝牙 BLE 开发笔记
- AC之路开始了~
- 数据库中MyISAM与InnoDB区别
- 在windows下创建一个Mongo服务
- In Action(SPFA+01背包)
- COJ 0342 逆序对(一)
- UIPickerView(选择控制器) 自学之初体验
- Google的Java经常使用类库 Guava
- 基于支持向量机的车牌识别-- opencv2.4.7+vs2012环境搭建
- HDU - 1584 IDA*
- ";元素隐式具有 “any” 类型,因为类型“Shared”没有索引签名";问题解决思路
- 微信公众号Java接入demo
- shell启动执行cypher语句
- Python 带有参数的装饰器
- 最受欢迎编程语言又是谁?C语言居首,大数据赢了
- 保姆级教程——Ubuntu16.04 Server下深度学习环境搭建:安装CUDA8.0,cuDNN6.0,Bazel0.5.4,源码编译安装TensorFlow1.4.0(GPU版)
- Day4 JavaScript(二)dom操作
- Inside GDALAllRegister之一: 五大部分