侧边栏壁纸
博主头像
一揽芳华 博主等级

行动起来,活在当下

  • 累计撰写 265 篇文章
  • 累计创建 24 个标签
  • 累计收到 4 条评论

目 录CONTENT

文章目录

6.5、添加交换分区

芳华是个男孩!
2024-10-14 / 0 评论 / 0 点赞 / 7 阅读 / 0 字
广告 广告

title: 05-添加交换分区
order: 5

icon: lightbulb

SWAP (交换)分区是一种通过在硬盘中预先划分一定的空间,然后将把内存中暂时不常用的数据 临时存放到硬盘中,以便腾出物理内存空间让更活跃的程序服务来使用的技术,其设计目的是为了解决 真实物理内存不足的问题。 但由于交换分区毕竟是通过硬盘设备读写数据的,速度肯定要比物理内存 慢,所以只有当真实的物理内存耗尽后才会调用交换分区的资源。交换分区的创建过程与前文讲到的挂 载并使用存储设备的过程非常相似。在对存储设备进行分区操作前,有必要先说一下交换分区的划分建 议:在生产环境中,交换分区的大小一般为真实物理内存的 1.5~2 倍,

实例:创建一个交换分区,分区大小为4G(本机linux系统内存为: 2G),我们添加一块硬盘做交换分 区(添加过程省略),添加完成之后我们使用命令lsblk查看一下:

[root@linux ~]# lsblk

对此磁盘(vdc)进行分区:

[root@linux ~]# fdisk /dev/vdc
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x36730f48.
Command (m for help): n //新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p //新建主分区
Partition number (1-4, default 1): 1 //敲击回车默认分区为编号为1,或者自定义
First sector (2048-8388607, default 2048): //默认敲回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607): //
敲击回车默认使用全部大小
Using default value 8388607
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): w //保存并推出
The partition table has been altered!
Calling ioctl() to re-read partition table.

同步分区信息到内核

 [root@linux ~]# partprobe

再次使用命令lsblk命令查看磁盘分区情况:

 [root@linux ~]# lsblk

使用交换分区专用格式化命令mkswap,对新建分的主分区进行格式化操作:

 [root@linux ~]# mkswap /dev/vdc1

使用swapon命令把准备好的swap分区正式挂载到文件系统中:

 [root@linux ~]# swapon /dev/vdc1

使用命令: free -m命令查看交换分区大小变化:

 [root@linux ~]# free -m

最后能够使交换分区设备在重启后依然生效,我们需要配置永久挂载点:

 [root@linux ~]# vi /etc/fstab //编辑fstab文件,尾行加入如下命令:

0
广告 广告

评论区