|NO.Z.00047|——————————|^^ 操作 ^^|——|Linux&磁盘管理.V06|——|swap分区|

一、分配 swap 分区
### --- 分区,并修改为 swap 分区 ID

[root@localhost ~]# fdisk /dev/sdb
~~~     拿/dev/sdb 分区
Command (m for help): t                                     // 修改分区的系统 ID
Selected partition 1                                        // 只有一个分区,所以不用选择分区了
Hex code (type L to list codes): 82                         // 改为 swap 的 ID
Changed system type of partition 1 to 82 (Linux swap / Solaris)
二、格式化
### --- 格式化

[root@localhost ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 522076 KiB
no label, UUID=c3351dc3-f403-419a-9666-c24615e170fb
~~~     9.8.3       使用 swap 分区
~~~     在使用 swap 分区之前,我们先来说说 free 命令,命令如下:

[root@localhost ~]# free
total   used   free  shared buffers             cached
Mem:   1030796  130792  900004     0   15292    55420
-/+ buffers/cache:   60080  970716
Swap:   2047992     0 2047992
~~~     例:
[root@localhost ~]# swapon 分区设备文件名
 
~~~     让 swap 分区开机之后自动挂载
~~~     加入新 swap 分区的相关内容,我这里是直接使用的分区的设备文件名,大家当然也可以
~~~     使用 UUID 号了。
[root@localhost ~]# swapon /dev/sdb1
/dev/sdb1           swap            swap        defaults        0 0

一、手动添加swap分区:实验专题
### --- 手动添加swap分区
### --- 查看内存命令
~~~     buffers:缓冲:是用来加速硬盘的写入速度  
~~~     cached:缓存:是用来加速硬盘的读取速度

[root@server21 ~]# free -h
             total       used       free     shared    buffers     cached
Mem:          1.8G       154M       1.7G       248K       5.9M        42M
-/+ buffers/cache:       106M       1.7G
Swap:         4.0G         0B       4.0G
### --- 新建一个swap分区5GB
 
[root@server11 ~]# fdisk /dev/sdb 
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
First sector (2048-209715199, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +5G   
Command (m for help): p
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux
~~~     默认使用的是linux的标准的分区号:83
Command (m for help): l
 82  Linux swap /                                           // swap的ID号是82
### --- 手动swap分区的ID号
Command (m for help): t                                     // t修改分区号
Selected partition 1
Hex code (type L to list all codes): 82
Command (m for help): p
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   82  Linux swap / Solaris
~~~     分区号改为82了;swap的分区
Command (m for help): w                                     // 保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
### --- 格式化mkswap
[root@server11 ~]# mkswap /dev/sdb1 
Setting up swapspace version 1, size = 5242876 KiB
no label, UUID=f2bbbc8d-5e3b-4cd4-9376-ff8a82d5679e
 
~~~     查看新建的,还没有加载过来,swap还是之前的大小
[root@server11 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           1.8G        183M        1.1G         17M        527M        1.4G
Swap:          4.0G          0B        4.0G
### --- 临时加载到swap分区中,

[root@server11 ~]# swapon /dev/sdb1 
[root@server11 ~]# free -h                                  // swap分区为9GB,说明加载成功
              total        used        free      shared  buff/cache   available
Mem:           1.8G        186M        1.1G         17M        527M        1.4G
Swap:          9.0G          0B        9.0G
### --- 永久生效加载swap分区
~~~     或者以UUID的方式写入自动挂载文件

[root@server11 ~]# vim /etc/fstab 
/dev/sdb1               swap            swap            defaults                0 0

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(13)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示