Skip to content

Instantly share code, notes, and snippets.

@wcxaaa
Created June 5, 2022 13:57
Show Gist options
  • Save wcxaaa/7f396dc610e8c20b8958a02cc9e98b70 to your computer and use it in GitHub Desktop.
Save wcxaaa/7f396dc610e8c20b8958a02cc9e98b70 to your computer and use it in GitHub Desktop.
btrfs 创建 swapfile
  • 在Btrfs分区根目录创建一个新子卷:
btrfs subvol create @swap
  • 继续执行以下命令:
chattr +C @swap # 禁用Copy On Write
btrfs property set @swap compression none # 禁用压缩
fallocate -l 16GiB @swap/swapfile
chmod 600 @swap/swapfile
mkswap @swap/swapfile
  • (可选)尝试一下挂载swap:
swapon @swap/swapfile
swapon --show
# 会显示:
# NAME                        TYPE  SIZE USED PRIO
# [...]/@swap/swapfile  file 16G   0B   -2
  • 开机自动挂载:

    • 根目录下创建个文件夹
    mkdir -p /swap
    • /etc/fstab最后面加入如下内容
    UUID=[btrfs分区的UUID] /swap btrfs defaults,subvol=@swap 0 0 
    /swap/swapfile               none    swap defaults                           0 0 
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment