扩展Linux swap分区 两种方法

简介:

先来查询一下系统的swap

[root@localhost ~]# free -m

total used free shared buffers cached

Mem: 375 369 6 0 7 83

-/+ buffers/cache: 278 97

Swap: 1027 128 899

[root@localhost ~]#

现在系统中swap1024M

扩展是swap分区有两种方法,

(1) 利用磁盘的剩余空间来扩展swap

首先分区并改变分区的类型

[root@localhost ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 1958.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n

First cylinder (1316-1958, default 1316):

Using default value 1316

Last cylinder or +size or +sizeM or +sizeK (1316-1958, default 1958): +500M

Command (m for help): t

Partition number (1-8): 8

Hex code (type L to list codes): 82

Changed system type of partition 8 to 82 (Linux swap / Solaris)

Command (m for help): wq

格式化swap

[root@localhost ~]# mkswap /dev/sda8

Setting up swapspace version 1, size = 509927 kB

[root@localhost ~]#

启动swap

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

[root@localhost ~]#

现在我在查询一下swap的大小

[root@localhost ~]# free -m

total used free shared buffers cached

Mem: 375 369 6 0 7 82

-/+ buffers/cache: 278 96

Swap: 1513 128 1385

[root@localhost ~]#

可以看到的swap分区已经增大了500M

最后,要想下次系统重启生效,必须写在/etc/fstab文件中

/dev/sda8 swap swap defaults 0 0

~

(2) 利用分区的剩余空间来扩展swap

首先我一样要查询一下系统中swap分区的大小

[root@localhost ~]# free -m

total used free shared buffers cached

Mem: 375 368 7 0 7 81

-/+ buffers/cache: 278 96

Swap: 1513 128 1385

[root@localhost ~]#

然后利用dd工具来创建一个swap文件

[root@localhost ~]# dd if=/dev/zero of=swapfile bs=1M count=100

100+0 records in

100+0 records out

104857600 bytes (105 MB) copied, 0.632534 seconds, 166 MB/s

[root@localhost ~]#

格式化swap

[root@localhost ~]# mkswap swapfile

Setting up swapspace version 1, size = 104853 kB

[root@localhost ~]#

把这个文件当做一个分区来对待

启动swap

[root@localhost ~]# swapon swapfile

[root@localhost ~]#

现在来查询一下swap分区的大小

[root@localhost ~]# free -m

total used free shared buffers cached

Mem: 375 368 6 0 1 90

-/+ buffers/cache: 276 98

Swap: 1613 128 1485

[root@localhost ~]#

可以看到系统的swap分区已经扩大100M

最后,要想下次系统重启生效,必须写在/etc/fstab文件中

/swapfile swap swap defaults 0 0

~

以上的两种方法就是用来扩展swap分区的

还可以使用swapon -a 激活交换分区,(该命令可以读取/etc/fstab文件,并开启它列出所有的交换条目

还可以利用swapon -s 来查询交换分区的状态

[root@localhost ~]# swapon -s

Filename Type Size Used Priority

/dev/sda5 partition 1052216 131640 -1

/dev/sda8 partition 497972 0 -2

/root/swapfile file 102392 0 -3

[root@localhost ~]#

在这里,可以看到swap是有哪些文件组成的,还有优先级,数字越大,优先级越高。可以在/etc/fstab文件中default后面加上pri=XX为优先级)

 

参考至:blog.sina.com.cn/s/blog_779eecd8010124ta.html

如有错误,欢迎指正

邮箱:czmcj@163.com

作者:czmmiao  文章出处:http://czmmiao.iteye.com/blog/2117105
相关文章
|
3月前
|
安全 Linux 虚拟化
|
3月前
|
Linux Shell 数据库
文件查找是Linux用户日常工作的重要技能介绍了几种不常见的文件查找方法
文件查找是Linux用户日常工作的重要技能。本文介绍了几种不常见的文件查找方法,包括使用`find`和`column`组合、`locate`和`mlocate`快速查找、编写Shell脚本、使用现代工具`fd`、结合`grep`搜索文件内容,以及图形界面工具如`Gnome Search Tool`和`Albert`。这些方法能显著提升文件查找的效率和准确性。
92 2
|
4月前
|
运维 Linux
Linux查找占用的端口,并杀死进程的简单方法
通过上述步骤和命令,您能够迅速识别并根据实际情况管理Linux系统中占用特定端口的进程。为了获得更全面的服务器管理技巧和解决方案,提供了丰富的资源和专业服务,是您提升运维技能的理想选择。
168 1
|
4月前
|
运维 安全 Linux
Linux文件清空的五种方法总结分享
每种方法各有优势,选择最合适的一种或几种,可以极大提高您的工作效率。更多有关Linux系统管理的技巧与资源,欢迎访问,持续提升您的运维技能。
129 1
|
4月前
|
Linux 数据安全/隐私保护 索引
linux inode索引节点使用率100% 解决+hustoj忘记密码+最新MDK注册方法
linux inode索引节点使用率100% 解决+hustoj忘记密码+最新MDK注册方法
68 1
|
4月前
|
Ubuntu Linux 网络安全
在Linux上安装软件有多种方法
在Linux上安装软件有多种方法
166 64
|
Linux KVM 虚拟化
【Linux系统KVM虚拟机实战】LVM逻辑卷之扩展Swap交换分区
【Linux系统KVM虚拟机实战】LVM逻辑卷之扩展Swap交换分区
353 1
|
Linux
Linux系统之armbain配置swap交换分区
Linux系统之armbain配置swap交换分区
288 0
|
8天前
|
Linux
Linux系统之whereis命令的基本使用
Linux系统之whereis命令的基本使用
50 23
Linux系统之whereis命令的基本使用