swapon:/swapfile:读取交换头失败:参数无效

gan*_*esh 13 linux

#sudo dd if=/dev/zero of=/swapspacefile bs=1M count=2048k

  0+0 records in
  0+0 records out
  0 bytes (0 B) copied, 0.000417928 s, 0.0 kB/s

#chmod 600 /swapspacefile

   mkswap: error: swap area needs to be at least 40 KiB

   Usage:
     mkswap [options] device [size]

   Options:
     -c, --check               check bad blocks before creating the swap area
     -f, --force               allow swap size area be larger than device
     -p, --pagesize SIZE       specify page size in bytes
     -L, --label LABEL         specify label
     -v, --swapversion NUM     specify swap-space version number
     -U, --uuid UUID           specify the uuid to use
     -V, --version             output version information and exit
     -h, --help                display this help and exit


#sudo mkswap /swapspacefile
Run Code Online (Sandbox Code Playgroud)

但是当我执行时它会在下面抛出,

  swapon: /swapfile: insecure permissions 0644, 0600 suggested.
  swapon: /swapfile: read swap header failed: Invalid argument
Run Code Online (Sandbox Code Playgroud)

小智 23

我从评论中读到了这个,但我认为我会作为答案可见。

# mkswap /swapfile
Run Code Online (Sandbox Code Playgroud)

您应该运行此命令来准备要用作交换空间的文件。

  • 仍然是一个很好的解决方案,为我工作的人会遇到这个问题,因为他们因不准备交换而得到相同的错误,(并且他们会得到与标题中相同的错误) (2认同)