First of all, I found that the error is not mkswap, but btrfs do not support swapfile, the solution is very simple, that is, the Swapfile mount to loopback on the
The script code is as follows
| The code is as follows |
Copy Code |
| #!/bin/sh # # Copyright (C) Sebastian Philipp # set-e swapsize= "$" swapname= "$" If [-Z "$swapsize"-o-z "$swapname"] then ; Cat <<eof usage: $ size:the size of the file, like "8G" file:path to the N EW swap file. This file should is not exists. eof exit 1 fi If [e $swapname] then echo "www.11 1cn.net 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 |
The
usage is./btrfs-swapon <size> <file Path> The file address requires a nonexistent file, add this to the rc.local can boot from boot mount Swapfile