Solve Linux Swapon/swap: failure: Invalid parameter problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.