Test environment: VMware 11
Test system: Red Hat Enterprise Linux 7
When there is not much space in our system to create a swap partition, one solution:
1[Email protected] ~]#DD if=/dev/zero of=/var/swapspace bs=1g count=1#创建交换分区文件, specify size 1G and save to/the Var directory2Recorded a 1 +0the read- in3Recorded a 1 +0the Writing41073741824 bytes (1.1GB) has been replicated,40.9398Seconds26.2MB/seconds #显示文件创建成功5[Email protected] ~]#ls-lh/var/swapspace #查看创建的swap文件6-rw-r--r--.1Root root1.0G February1 One: in/var/Swapspace7[Email protected] ~]# Mkswap/var/swapspace-L myswap #创建交换分区并设置卷标 myswap8Setting Swap space version1, size =1048572KiB9Label=myswap, uuid=6d756da7-e942-4fc6-b3b8-86f56be7f286 #显示设置成功并打印出相关信息Ten[Email protected] ~]# Free-h #查看修改前swap状态 OneTotal used Freeshared buffers Cached A mem:990m 148M 842M 644K 0B 26M --/+ buffers/cache:121m 869M -Swap:2.0G 74M1. 9G the[Email protected] ~]# swapon/var/swapspace #开户swap -[Email protected] ~]# Free-h #再次查看swap分区 -Total used Freeshared buffers Cached - mem:990m 150M 839M 712K 0B 27M +-/+ buffers/cache:123m 867M -Swap:3.0G 74M2. 9G +[Email protected] ~]#
When Linux does not have multiple partitions, swap adds a scenario