首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Ubuntu18.04中增加swapfile?

如何在Ubuntu18.04中增加swapfile?
EN

Ask Ubuntu用户
提问于 2018-09-15 11:42:11
回答 1查看 79K关注 0票数 67

我有8 GB内存和1TB硬盘的笔记本电脑。我有一个2GB的swapfile (Ubuntu18.04默认使用一个swapfile而不是单独的交换分区),我想增加它来使用hibernation。

我想把它从2GB提高到16 GB。下面是GParted的截图:

我试图用fallocate -l 16G来增加它,但是它没有起作用。

还有来自free -m的图像:

EN

回答 1

Ask Ubuntu用户

发布于 2018-11-04 21:14:08

man mkswap中,建议使用dd命令,如@钒柱所示。

代码语言:javascript
复制
If  you  don't  know  the  page  size  that  your  machine uses, 
you may be able to look it up with 
"cat /proc/cpuinfo" 
(or you may not – the contents of this file depend on architecture and kernel version).

   To set up a swap file, it is necessary to create that file before   
   initializing  it  with  mkswap,  e.g. using a command like

          # fallocate --length 8GiB swapfile

   Note  that  a  swap  file must not contain any holes.  Using cp(1) to  
   create the file is not acceptable.
   Neither is use of fallocate(1) on file systems that support preallocated 
   files, such as XFS or ext4,  or on  copy-on-write  filesystems like btrfs.  

   It is recommended to use dd(1) and /dev/zero in these cases.
   Please read notes from swapon(8) before adding a swap file to copy-on- 
   write filesystems.

这里是man swapon的笔记

代码语言:javascript
复制
NOTES
       You should not use swapon on a file with holes.  This can be seen in
       the system log as

              swapon: swapfile has holes.

       The swap file implementation in the kernel expects to be able to write  
       to the file directly, without the assistance  of the filesystem.  This 
       is a problem on preallocated files (e.g.  fallocate(1)) on filesys‐
       tems like XFS or ext4, and on copy-on-write filesystems like btrfs.

       It is recommended to use dd(1) and /dev/zero to avoid holes on XFS
       and ext4.

       swapon may not work correctly when using a swap file with some  
       versions of btrfs.  This is due to  btrfs being  a copy-on-write 
       filesystem: the file location may not be static and corruption can 
       result.  
       Btrfs actively disallows the use of swap files on its filesystems
       by refusing to map the file.

       One possible workaround is to map the swap file to a loopback device.  
       This will allow the filesystem to determine the mapping properly but  
       may come with a performance impact.

       Swap over NFS may not work.
票数 4
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1075505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档