博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
日常运维--Linux添加swap分区方法
阅读量:3721 次
发布时间:2019-05-22

本文共 2820 字,大约阅读时间需要 9 分钟。

Linux添加swap分区方法(以整块盘或分区作为虚拟内存)

建立一个普通的Linux分区(主分区、逻辑分区均可)

[root@devops-fleming /]# fdisk -lDisk /dev/vda: 44.0 GB, 44023414784 bytes, 85983232 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000b1b45   Device Boot      Start         End      Blocks   Id  System/dev/vda1   *        2048    85983198    42990575+  83  LinuxDisk /dev/vdb: 85.9 GB, 85899345920 bytes, 167772160 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x990f0d05   Device Boot      Start         End      Blocks   Id  System/dev/vdb1            2048    83888127    41943040   83  Linux/dev/vdb2        83888128   125831167    20971520   83  Linux/dev/vdb3       125831168   167772159    20970496   83  Linux

以/dev/vdb3设为虚拟内存为例,可以看到分区的十六进制编码是83,即普通的Linux分区,而swap分区的编码是82。修改分区类型的十六进制编码,使用t命令改写分区十六进制编码

[root@devops-fleming /]# fdisk /dev/vdbWelcome 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): tPartition number (1-3, default 3): 3Hex code (type L to list all codes): 82Changed type of partition 'Linux' to 'Linux swap / Solaris'Command (m for help): pDisk /dev/vdb: 85.9 GB, 85899345920 bytes, 167772160 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x990f0d05   Device Boot      Start         End      Blocks   Id  System/dev/vdb1            2048    83888127    41943040   83  Linux/dev/vdb2        83888128   125831167    20971520   83  Linux/dev/vdb3       125831168   167772159    20970496   82  Linux swap / SolarisCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.

可以看到/dev/vdb3的编码已经变成82 Linux swap / Solaris

格式化交换分区

[root@devops-fleming /]# mkswap /dev/vdb3Setting up swapspace version 1, size = 20970492 KiBno label, UUID=62976c8b-eeea-403c-914f-f6abfa735daf

启用交换分区

[root@devops-fleming /]# swapon /dev/vdb3

查看交换分区加载状态

[root@devops-fleming /]# free              total        used        free      shared  buff/cache   availableMem:        3880408      105288     2399132         500     1375988     3501300Swap:      20970492           0    20970492

停用交换分区

[root@izj6c1me2wu2lepyg9fhg5z ~]# swapoff /dev/vdb3

不能直接使用mount命令挂载swap分区,因为swap分区是没有挂载点的。

系统启动时自动挂载,修改/etc/fstab配置文件

/dev/vdb3 swap swap defaults 0 0

查看交换分区

[root@devops-fleming /]# swapon -sFilename				Type		Size	Used	Priority/dev/vdb3                              	partition	20970492	0	-2

 

转载地址:http://dodnn.baihongyu.com/

你可能感兴趣的文章
Leedcode40——组合总和II(回溯法)
查看>>
Spring系列教程——10AOP概述与原理
查看>>
Spring系列教程——11编程实现AOP
查看>>
原地Hash法
查看>>
Spring系列教程——12配置文件实现AOP
查看>>
Spring系列教程——13AspectJ讲解
查看>>
Spring系列教程——14Spring数据库操作讲解
查看>>
Spring系列教程——15Spring事务管理器
查看>>
Spring系列教程——16Aop事务配置与注解事务配置
查看>>
Spring系列教程——目录
查看>>
SpringMVC系列教程——02URL处理器映射
查看>>
SpringMVC系列教程——03处理器适配器讲解
查看>>
SpringMVC系列教程——04命令控制器讲解
查看>>
SpringMVC系列教程——05注解讲解
查看>>
SpringMVC系列教程——06控制器接收表单
查看>>
JavaWeb-ServletConfig对象的获取与使用
查看>>
SpringMVC系列教程——07控制器页面显示专题
查看>>
SpringMVC系列教程——08URL模板映射讲解
查看>>
SpringMVC系列教程——09转发与重定向及@RequestParam讲解
查看>>
SpringMVC系列教程——10接收与响应json数据格式
查看>>