Linux常用命令-swapon

命令

swapon

描述

enable devices and files for paging and swapping
开启swap分区

用法

1
swapon [options] [<spec>]

选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Options:
-a, --all 开启/etc/fstab中所有的swap分区配置
-e, --ifexists 跳过不存在的设备
-f, --fixpgsz 重新初始化swap分区
-p, --priority <prio> 指定swap设备的优先级
-s, --summary 显示当前在用的swap汇总信息
--show[=<columns>] 显示指定swap信息
--noheadings 不显示标题,配合--show使用
--raw 显示原始格式,配合--show
--bytes 显示单位为字节,默认显示为M,G,配合--show
-v, --verbose 显示详情

The <spec> parameter:
可以指定UUID,设备路径,文件路径
-L <label> synonym for LABEL=<label>
-U <uuid> synonym for UUID=<uuid>
LABEL=<label> specifies device by swap area label
UUID=<uuid> specifies device by swap area UUID
PARTLABEL=<label> specifies device by partition label
PARTUUID=<uuid> specifies device by partition UUID
<device> name of device to be used
<file> name of file to be used

注意

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 默认为查看swap分区
$ swapon
NAME TYPE SIZE USED PRIO
/dev/dm-1 partition 2G 0B -2
$ swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 2097148 0 -2
# -a开启/etc/fstab中所有的swap分区配置
$ swapon -a
$ swapon
NAME TYPE SIZE USED PRIO
/dev/dm-1 partition 2G 0B -2
/swapfile file 1000M 0B -3
$ more /proc/swaps
Filename Type Size Used Priority
/dev/dm-1 partition 2097148 0 -2
/swapfile file 1023996 0 -3