swapon -a
swapon -s
swapon -p /dev_name
swapoff /dev_name
swapon
-a 重新加载/etc/fstab文件中的所有swap分区
-s 显示swapon的summary信息
-p 显示设备的优先级
通过文件创建swap
[root@foundation0 srv]# dd if=/dev/zero of=/srv/swapfile bs=1M count=512
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 0.497669 s, 1.1 GB/s
[root@foundation0 srv]# mkswap /srv/swapfile
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=0a4acab5-ff8a-4c19-a4c5-350b3db8b429
[root@foundation0 srv]# chmod 0600 /srv/swapfile
[root@foundation0 srv]# swapon -p 100 /srv/swapfile #设置swap的优先级
[root@foundation0 srv]# swapon -s
Filename Type Size Used Priority
/dev/sda2 partition 5185532 1122268 -1
/srv/swapfile file 524284 0 -2
删除文件类型的swap分区:
[root@foundation0 srv]# swapoff /srv/swapfile
[root@foundation0 srv]# swapon -s
Filename Type Size Used Priority
/dev/sda2 partition 5185532 1122268 -1
配置开机自动挂载:
vim /etc/fatab
/dev/sdc2 swap swap defaults 0 0
/dev/sdc3 swap swap pri=1 0 0 #设置swap的优先级
通过磁盘分区来创建SWAP分区
创建swap分区类型:
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'
Command (m for help): p
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbee7cf6f
Device Boot Start End Blocks Id System
/dev/sdc1 2048 2099199 1048576 82 Linux swap / Solaris
格式化分区:
[root@foundation0 srv]# mkswap /dev/sdb2
mkswap: /dev/sdb2: warning: wiping old ext4 signature.
Setting up swapspace version 1, size = 511996 KiB
no label, UUID=8317d390-feb0-431f-8df8-aefe52a14796
[root@foundation0 srv]# partprobe
创建自动挂载文件系统
vim /etc/fstab
UUID=8317d390-feb0-431f-8df8-aefe52a14796 swap swap defaults 0 0
查看是否配置正确:加载所有的交换分区
[root@foundation0 srv]# swapon -a
查看swap分区是否加载使用:
[root@foundation0 srv]# swapon -s
Filename Type Size Used Priority
/dev/sda2 partition 3031036 0 -1
/srv/swapfile file 524284 0 100
/dev/sdb2 partition 511996 0 -2
++++++++++++++++++++++++
关闭swap分区:
[root@foundation0 srv]# swapoff /dev/sdb2
[root@foundation0 srv]# swapon -s
Filename Type Size Used Priority
/dev/sda2 partition 3031036 0 -1
/srv/swapfile file 524284 0 100
删除swap在/etc/fstab中的配置
[root@foundation0 srv]# swapon -a
[root@foundation0 srv]# swapon -s
Filename Type Size Used Priority
/dev/sda2 partition 3031036 0 -1
/srv/swapfile file 524284 0 100
2017-12-05
RHCE:swap系统交换分区创建,查看,删除
评论
发表评论
姓 名: