创建 create_swap.sh 文件并添加下面的内容来主动化交换空间的创建和挂载。
- $ nano create_swap.sh
- #!/bin/sh
- # size of swapfile in megabytes
- swapsize=1024
- # does the swap file already exist?
- grep -q "swapfile" /etc/fstab
- # if not then create it
- if [ $? -ne 0 ]; then
- echo 'swapfile not found. Adding swapfile.'
- fallocate -l ${swapsize}M /swapfile
- chmod 600 /swapfile
- mkswap /swapfile
- swapon /swapfile
- echo '/swapfile none swap defaults 0 0' >> /etc/fstab
- else
- echo 'swapfile found. No changes made.'
- fi
- echo '--------------------------------------------'
- echo 'Check whether the swap space created or not?'
- echo '--------------------------------------------'
- swapon --show
给文件添加履行权限。
- $ sudo +x create_swap.sh
运行文件来创建和挂载交换文件。
移除交换文件
- $ sudo ./create_swap.sh
- swapfile not found. Adding swapfile.
- Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
- no label, UUID=d9004261-396a-4321-a45f-9923e3e1328c
- --------------------------------------------
推荐阅读
Boot Repair Tool: 可以修复与启动相关的大部分问题
我们都碰着过启动相干的问题,并且大年夜部分时刻都是简单的 GRUB 汕9依υ?题。 有时刻很多人会认为、输入一段很长的敕令或在论坛中搜刮来找到解决办法太麻烦了。今天我要告诉你若何应>>>详细阅读
本文标题:在Linux中使用shell脚本自动创建/移除并挂载交换文件
地址:http://www.17bianji.com/lsqh/35997.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示