3

How can I increase swap partition size?

I would like to shrink the size of partition #5(/dev/nvme0n1p5 which is a ZFS partition) by 6Gb and add it to partition #3(/dev/nvme0n1p3).

I'm running Xubuntu 19.10 with ZFS as root.

Notes:

  • Since none of the GUI Partition managers(GParted/Gnome Disks/KDE Partition Manager) currently support changing/moving ZFS partitions, I can't use them.
  • I don't want to create another new swap partition on ZFS, I just want to use the current one and increase its size.
  • I don't want to create a new swapfile on ZFS!

System Info

sudo parted -l

Model: WDC PC SN520 SDAPNUW-512G-1002 (nvme)
Disk /dev/nvme0n1: 512GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name                  Flags
 1      1049kB  538MB   537MB   fat32           EFI System Partition  boot, esp
 2      538MB   590MB   52.4MB  ext4
 3      590MB   2738MB  2147MB  linux-swap(v1)
 4      2738MB  4885MB  2147MB  zfs
 5      4885MB  512GB   507GB   zfs
sudo fdisk -l /dev/nvme0n1

Disk /dev/nvme0n1: 476.96 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: WDC PC SN520 SDAPNUW-512G-1002          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 9E99ED37-A328-4F95-B9F9-946E5ED049B8

Device           Start        End   Sectors   Size Type
/dev/nvme0n1p1    2048    1050623   1048576   512M EFI System
/dev/nvme0n1p2 1050624    1153023    102400    50M Linux filesystem
/dev/nvme0n1p3 1153024    5347327   4194304     2G Linux swap
/dev/nvme0n1p4 5347328    9541631   4194304     2G Solaris boot
/dev/nvme0n1p5 9541632 1000215182 990673551 472.4G Solaris root
sudo zpool list -v

NAME          SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
bpool        1.88G   131M  1.75G        -         -     0%     6%  1.00x    ONLINE  -
  nvme0n1p4  1.88G   131M  1.75G        -         -     0%  6.82%      -  ONLINE  
rpool         472G   112G   360G        -         -     9%    23%  1.00x    ONLINE  -
  nvme0n1p5   472G   112G   360G        -         -     9%  23.8%      -  ONLINE
sudo swapon --show --output all

NAME           TYPE      SIZE USED PRIO UUID                                 LABEL
/dev/nvme0n1p3 partition   2G 7.8M   -2 52702bf2-1e50-4ece-8d3e-db01cff707fe
lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 19.10
Release:    19.10
Codename:   eoan
8
  • Your question is not simply on increasing a SWAP, because you clearly know the traditional tools. Please edit your question title to reflect the actual problem, resizing ZFS. – vanadium Dec 24 '19 at 9:35
  • @vanadium sure, done. – slashsbin Dec 24 '19 at 10:10
  • Why not create a new swapfile on ZFS? – sudodus Dec 25 '19 at 18:33
  • @sudodus It seems it's not possible to create a swapfile on a ZFS which the swapon command would accept! The swapon command fails with error Files with holes. I've tried to create a swapfile with fallocate/dd/truncate commands and they all produce files that are not accepted! Maybe you have more luck. Please see the notes section of swapon manual for more information about the "Files with holes" error. – slashsbin Dec 25 '19 at 20:25
  • I have not tried, but understand now why a swapfile is not a solution. A workaround might be two or more smaller swapfiles, that can be created without any hole. – sudodus Dec 25 '19 at 20:34
1

According to Aaron Toponce's guide:

You cannot shrink a zpool, only grow it.

Source:
https://pthree.org/2012/12/04/zfs-administration-part-i-vdevs/

Here is another guide:
http://www.resilvered.com/2011/07/how-to-shrink-zfs-root-pool.html

It looks like this second guide "shrinks" a pool by creating a new (smaller) pool on a different disk, and then sending a snapshot from the old pool to the new pool.

0

A zfs partition cannot be shrunk, but a new swap partition can be created in the root zpool just fine like this:

zfs create -V 20G -b "$(getconf PAGESIZE)" \
      -o compression=zle -o logbias=throughput \
      -o sync=always -o primarycache=metadata \
      -o secondarycache=none \
      -o com.sun:auto-snapshot=false \
      rpool/swap
mkswap -f /dev/zvol/rpool/swap
3
  • 1
    This is not a good solution, as there is currently a long-standing bug where using a ZVOL for swap makes your system lock-up under load. Do not recommend using ZVOLs until this issue is resolved, because this WILL cause people's systems to lock up. Discussed here github.com/openzfs/zfs/issues/7734 and even wiki github.com/zfsonlinux/pkg-zfs/wiki/… – Cray Feb 28 at 8:42
  • Interesting find. On another note - would a swapfile on a zfs be similarly unreliable as a zvol for swap? – Alexander Shcheblikin Mar 4 at 13:02
  • At least on Linux it is not possible (meaning: very hard, since everything is open source and you could in theory rewrite some driver with enough time, yadda yadda) to add a regular file in zfs as a swap space. The swapon command will complain that the file has holes, regardless of how you try to allocate/prefill/zerofill/dd the file. So the question of whether it would be reliable to do this, while interesting, in practice is overshadowed by question "could you even configure it that way", answer to which is no. – Cray Mar 5 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.