IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    swapon /swap:失败:参数无效

    五月里徜徉的小猫咪发表于 2014-03-09 03:24:38
    love 0

    首先这个错误我发现并非是没有mkswap的缘故,而是btrfs根本不支持swapfile,解决的方法也很简单,就是把swapfile挂载到loopback就可以了,参见http://www.spinics.net/lists/linux-btrfs/msg28533.html

    github上面有个脚本,参见:https://github.com/sebastian-philipp/btrfs-swapon
    脚本内容如下

    #!/bin/sh
     #
     # Copyright (C) Sebastian Philipp
     #
    
    set -e
    
    swapsize="$1"
     swapname="$2"
    
    if [ -z "$swapsize" -o -z "$swapname" ]
     then
     cat <<EOF
     Usage: $0
    
    size: the size of the file, like "8G"
     file: path to the new swap file. This file should not exists.
     EOF
     exit 1
     fi
    
    if [ -e $swapname ]
     then
     echo "error: File already exists. $swapname"
     exit 1
     fi
    
    swapfile=$(losetup -f) #free loop device
    
    # set NOCOW
     touch $swapname
     chattr +C $swapname
     head -c $swapsize /dev/zero >> $swapname
    
    losetup $swapfile $swapname #mount file to loop
     mkswap $swapfile
     swapon $swapfile
    

    使用方法是./btrfs-swapon <size> <file path>,文件地址需要一个不存在的文件,把这个添加到rc.local就可以开机自启动挂载swapfile了



沪ICP备19023445号-2号
友情链接