Linux禁止swap分区,Linux 之 swap分区创建与管理

swap分区创建与管理

1.查看swap分区

[root@localhost ~]# free -h

total used free shared buffers cached

Mem: 2.0G 1.0G 944M 1.5M 265M 341M

-/+ buffers/cache: 454M 1.5G

Swap: 4.0G 0B 4.0G #swap分区大小

[root@localhost ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 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: 0x0004c723

Device Boot Start End Blocks Id System

/dev/sda1 * 1 26 204800 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 26 548 4194304 82 Linux swap / Solaris #swap挂载地方

Partition 2 does not end on cylinder boundary.

/dev/sda3 548 6528 48028672 83 Linux

2.关闭开启swap

[root@localhost ~]# swapoff /dev/sda2

[root@localhost ~]# free -h

total used free shared buffers cached

Mem: 2.0G 1.1G 923M 1.5M 265M 341M

-/+ buffers/cache: 475M 1.5G

Swap: 0B 0B 0B

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

[root@localhost ~]# free -h

total used free shared buffers cached

Mem: 2.0G 1.0G 944M 1.5M 265M 341M

-/+ buffers/cache: 455M 1.5G

Swap: 4.0G 0B 4.0G

3.swap分区扩容

[root@localhost ~]# dd if=/dev/zero of=/opt/swapfile bs=1M count=1024 #创建一个swap分区

1024+0 records in

1024+0 records out

1073741824 bytes (1.1 GB) copied, 19.2751 s, 55.7 MB/s

[root@localhost ~]# mkswap /opt/swapfile #格式化成swap格式

mkswap: /opt/swapfile: warning: don't erase bootbits sectors

on whole disk. Use -f to force.

Setting up swapspace version 1, size = 1048572 KiB

no label, UUID=565ba456-ae47-4749-a7f7-1cd26f37bdbd

[root@localhost ~]# swapon /opt/swapfile #启用该swap分区,并会自动合并到原来的swap分区上

[root@localhost ~]# free -h

total used free shared buffers cached

Mem: 2.0G 1.9G 101M 1.5M 264M 1.1G

-/+ buffers/cache: 466M 1.5G

Swap: 5.0G 0B 5.0G

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值