21磁盘管理—Linux添加swap交换分区

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了21磁盘管理—Linux添加swap交换分区相关的知识,希望对你有一定的参考价值。

添加swap交换分区

SWAP即交换分区是一种类似于Windows系统虚拟内存的功能,将一部分硬盘空间虚拟成内存来使用,从而解决内存容量不足的情况,因为SWAP毕竟是用硬盘资源虚拟的,所以速度上比真实物理内存要慢很多,一般只有当真实物理内存耗尽时才会调用SWAP。

1、创建一个分区,看上篇文章,别着急w保存退出 
修改分区的类型输入t

Command (m for help): t
Selected partition 1

2、查看可用的分区类型,输入L

Hex code (type L to list all codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-

3、输入82代表swap分区:

Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap / Solaris)

4、再次查看分区表信息(已有分区信息):

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  82  Linux swap / Solaris

5、保存分区表的设置:

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

6、让内核同步分区信息(此步骤仅在没有找到分区设备的情况下才需要执行,非必要动作。):

[root@localhost ~]# partprobe

7、将sdb1分区设备格式化为swap类型:

[[email protected] ~]# mkswap /dev/sdb1 
mkswap: /dev/sdb1: warning: don‘t erase bootbits sectors
       (dos partition table detected). Use -f to force.
Setting up swapspace version 1, size = 2104476 KiB
no label, UUID=a77266ac-b078-45f7-a329-b95219d90e2b

8、查看当前的内存使用量情况,SWAP大小为2047:

[[email protected] ~]# free -m
            total       used       free     shared    buffers     cached
Mem:           980        651        329          0         62        438
-/+ buffers/cache:        150        829
Swap:         2047          0       2047

9、将sdb1的SWAP分区启用:

[root@localhost ~]# swapon /dev/sdb1 

10、再次查看当前系统的内存使用量情况(此时SWAP为4103m):

[[email protected] ~]# free -m
            total       used       free     shared    buffers     cached
Mem:           980        652        328          0         62        438
-/+ buffers/cache:        151        828
Swap:         4103          0       4103

11、设置为开机后自动挂载该SWAP分区设备:

[[email protected] ~]# vim /etc/fstab
/dev/sdb1 swap swap defaults 0 0


本文出自 “家住海边喜欢浪” 博客,请务必保留此出处http://zhang789.blog.51cto.com/11045979/1847244

以上是关于21磁盘管理—Linux添加swap交换分区的主要内容,如果未能解决你的问题,请参考以下文章

linux[基础]-22-[磁盘分区管理]-[交换分区]-[02]

linux磁盘管理一标准分区步骤和swap交换区的设置

Linux 操作系统原理 — 内存管理 — Swap 交换内存

Linux 操作系统原理 — 内存管理 — Swap 交换内存

磁盘管理之交换分区

linux磁盘和文件系统管理