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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值