Red Hat Linux添加一个swap分区

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_42147250/article/details/89099218

添加一个swap分区

要求:

swap 分区容量为 512 MiB

当您的系统启动时,swap 分区应该可以自动挂载

不要移除或者修改其他已经存在于您的系统中的 swap 分区

================================================ 
1、先查看一下目前系统中使用的swap分区,我的是只有一个,现在我要再添加个,容量是512M的

[root@desktop ~]# swapon -s
Filename                Type        Size    Used    Priority
/dev/sda2             partition   2047996   0             -1

2、用分区工具重新划分一个容量为512M的分区,逻辑分区主分区都可以,推荐使用逻辑分区

[root@desktop ~]# fdisk /dev/sda 
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): p   看一下目前的分区状态

扫描二维码关注公众号,回复: 7659670 查看本文章

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000bffad

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    20482047    10240000   83  Linux
/dev/sda2        20482048    24578047     2048000   82  Linux swap / Solaris
/dev/sda3        24578048    25602047      512000   83  Linux

Command (m for help): n    使用n新建分区
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e   选择拓展分区
Selected partition 4
First sector (25602048-41943039, default 25602048): 
Using default value 25602048
Last sector, +sectors or +size{K,M,G} (25602048-41943039, default 41943039):  --->我这里就把剩余的空间全给这个扩展分区了
Using default value 41943039
Partition 4 of type Extended and of size 7.8 GiB is set

Command (m for help): n   按n继续分区,开始分逻辑分区
All primary partitions are in use
Adding logical partition 5
First sector (25604096-41943039, default 25604096): 
Using default value 25604096
Last sector, +sectors or +size{K,M,G} (25604096-41943039, default 41943039): +512M  输入我要分区的大小
Partition 5 of type Linux and of size 512 MiB is set

Command (m for help): t     按t修改分区类型
Partition number (1-5, default 5): 
Hex code (type L to list all codes): 82   修改为swap类型
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): w    按w保存退出

[root@desktop ~]#partprobe    刷新磁盘信息

3、格式化分区为swap格式,并且启用

[root@desktop ~]# mkswap /dev/sda5   格式化
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=8a529678-5180-4c8c-bd2c-18677c573ba3
[root@desktop ~]# swapon /dev/sda5  启用
[root@desktop ~]# swapon -s   查看正在使用的swap分区,已存在
Filename                Type        Size    Used    Priority
/dev/sda2                               partition   2047996 0   -1
/dev/sda5                               partition   524284  0   -2

4、配置开机自动挂载

[root@desktop ~]# blkid     看要挂载的swap分区的UUID,然后复制
/dev/sda1: UUID="3c6e20fa-3e12-42ca-8dba-b12eee74e43e" TYPE="xfs" 
/dev/sda2: UUID="ff7d2e6d-c2d7-46a0-af09-70c85898ab46" TYPE="swap" 
/dev/sda3: UUID="4Ntfep-th0e-bCXr-Qo3b-EPJ1-SRsu-nfeOru" TYPE="LVM2_member" 
/dev/sda5: UUID="8a529678-5180-4c8c-bd2c-18677c573ba3" TYPE="swap" 
/dev/mapper/vg0-lv0: UUID="b2285e5e-de78-4392-945a-817843fd7f10" TYPE="ext3" 
[root@desktop ~]# vim /etc/fstab   编辑挂载文件,内容如下图
[root@desktop ~]# mount -a   重新加载挂载表

[root@desktop ~]# 


 

猜你喜欢

转载自blog.csdn.net/qq_42147250/article/details/89099218
今日推荐