Red Hat Enterprise Linux release 8.0 (Ootpa)-添加交换分区swap
添加交换分区 :向您的系统添加一个额外的交换分区567MiB.交换分区应在系统启动时自动加载。不要删除或以任何方式改动系统上的任何现有分换分区。
1、fdisk -l查看磁盘
[root@servera ~]# fdisk -l
Disk /dev/vda: 10 GiB, 10737418240 bytes, 20971520 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
Disklabel type: dos
Disk identifier: 0x16a1e057
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 20971486 20969439 10G 83 Linux
Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 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
[root@servera ~]# ls /dev/vd*
/dev/vda /dev/vda1 /dev/vdb
2、fdisk /dev/vdb 进行磁盘分区
[root@servera ~]# fdisk /dev/vdb
按m查看帮助指导
注意:修改类型为82
3、ls /dev/vd* 查看新增的磁盘分区
[root@servera ~]# ls /dev/vd*
/dev/vda /dev/vda1 /dev/vdb /dev/vdb1
4、partprobe 重读分区表
[root@servera ~]# partprobe
注意:partprobe命令用于重读分区表,将磁盘分区表变化信息通知内核,请求操作系统重新加载分区表。如果删除文件后,仍然提示占用空间,可以用partprobe在不重启的情况下重读分区
5、fdisk -l 查看分区
[root@servera ~]# fdisk -l
6、mkswap /dev/vdb1格式化分区
[root@servera ~]# mkswap /dev/vdb1
Setting up swapspace version 1, size = 567 MiB (594538496 bytes)
no label, UUID=16200cfa-66b5-4966-aba9-33f67d31e2da //注意,下面会使用到该UUID挂载fstab
7、vi /etc/fstab 修改启动项,永久挂载
# /etc/fstab
# Created by anaconda on Thu Apr 4 08:39:20 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.::
#
UUID=884f47c9-a69d-4c5b-915d-6b7c9c74c923 / xfs defaults 0 0
UUID=16200cfa-66b5-4966-aba9-33f67d31e2da swap swap default 0 0
8、swapon -a 加载一下永久挂载的新添加部分
[root@servera ~]# free -m
total used free shared buff/cache available
Mem: 821 190 285 15 345 477
Swap: 0 0 0
[root@servera ~]# swapon -a
swapon命令用于激活Linux系统中交换空间;-a 自动启动所有SWAP装置
[root@servera ~]# free -m
total used free shared buff/cache available
Mem: 821 190 285 15 345 477
Swap: 566 0 566
注意:mount -a 不适用于swap
参考URL:
https://www.runoob.com/linux/linux-comm-swapon.html
https://linux265.com/course/linux-command-partprobe.html