1

I'm running Xubuntu 19.10 with ZFS as root.

How can I increase swap partition(ZFS) size?

sudo swapon --show --output all
NAME           TYPE      SIZE USED PRIO UUID                                 LABEL
/dev/nvme0n1p3 partition   2G 7.8M   -2 52702bf2-1e50-4ece-8d3e-db01cff707fe
cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=027C-FFBA  /boot/efi       vfat    umask=0077      0       1
UUID=fdbb5efc-744f-4718-b09b-c3e5bb54a219   /boot/grub  ext4    errors=remount-ro   0   1
UUID=52702bf2-1e50-4ece-8d3e-db01cff707fe   none    swap    discard 0   0
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
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 19.10
Release:    19.10
Codename:   eoan

Gnome Disk Utility Screenshot for Swap Partition: Gnome Disk Utility Screenshot for Swap Partition

Note that it's marked as in the rpool in the screenshot.

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 zpool status -v
  pool: bpool
 state: ONLINE
  scan: scrub repaired 0B in 0 days 00:00:00 with 0 errors on Sat Nov  9 23:54:01 2019
config:

    NAME         STATE     READ WRITE CKSUM
    bpool        ONLINE       0     0     0
      nvme0n1p4  ONLINE       0     0     0

errors: No known data errors

  pool: rpool
 state: ONLINE
  scan: scrub repaired 0B in 0 days 00:01:25 with 0 errors on Sat Nov  9 23:55:26 2019
config:

    NAME         STATE     READ WRITE CKSUM
    rpool        ONLINE       0     0     0
      nvme0n1p5  ONLINE       0     0     0

errors: No known data errors
sudo zfs list

See https://pastebin.ubuntu.com/p/6jDVwbhfCT/

  • 1
    What makes you thing that /dev/nvme0n1p3 is a ZFS thing ? – Soren A Dec 19 '19 at 10:40
  • @SorenA Gnome Disk Utility marks it as part of the rpool, I've added the screenshot to the question. – slashsbin Dec 19 '19 at 12:32
  • Can you edit the main post and show the output of sudo zpool list then sudo zpool status and sudo zfs list. Growing the swap partition should be as straight forward as just increasing the zvol size – stratus Dec 19 '19 at 14:17
  • Updated :thumbsup: – slashsbin Dec 19 '19 at 14:35
  • @K7AAY No I don't need to hibernate and I agree with you, but it seems it's not possible to create a swap file on a ZFS which swapon command would accept! The swapon command fails with error "Files with holes". I've tried to create a swap file with fallocate/dd/truncate and they all produce files that are not accepted! Maybe you have more luck. – slashsbin Dec 19 '19 at 20:04
0

From the output provided the swap is not part of the zpool/zvol. For example here is output from a machine which has Swap on ZFS:

My FSTAB:

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/nuc--root-root /               xfs     noatime         0       0
# /boot was on /dev/sdb1 during installation
UUID=afd2054d-1ed3-498f-90de-b7d282bdab80 /boot           ext2    noatime,nodiratime 0       2
/dev/zvol/VMs/swap none swap discard 0 0
stratus@nuc:/$ sudo zpool list
NAME   SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
VMs    232G  79.0G   153G         -    61%    34%  1.00x  ONLINE  -

stratus@nuc:/$ sudo zpool status
  pool: VMs
 state: ONLINE
  scan: scrub repaired 0 in 0h21m with 0 errors on Sun Dec  8 00:45:29 2019
config:

    NAME                                  STATE     READ WRITE CKSUM
    VMs                                   ONLINE       0     0     0
      ata-faspeed_F710-250G_180116710082  ONLINE       0     0     0

errors: No known data errors

stratus@nuc:/$ sudo zfs list
NAME         USED  AVAIL  REFER  MOUNTPOINT
VMs         86.4G   138G    96K  none
VMs/images  77.7G   138G  77.7G  /var/lib/libvirt/images/
VMs/swap    8.50G   146G  1.09G  -

It is likely that 'rpool' is just a label on the partition and not refering to the ZFS volume.

If you would like to add SWAP to ZFS you can do this:

zfs create -V 8G -b $(getconf PAGESIZE) -o logbias=throughput -o sync=always -o primarycache=metadata -o com.sun:auto-snapshot=false rpool/swap
mkswap -f /dev/zvol/rpool/swap
swapon /dev/zvol/rpool/swap

In your FSTAB:

# IN FSTAB
/dev/zvol/rpool/swap none swap discard 0 0

Make sure to set the size as you feel appropriate

  • Thank you for your help, could you please provide a solution for increasing the size of the current swap partition too? How to get free space from zfs pool and add it to the swap partition? – slashsbin Dec 19 '19 at 15:28
  • Thats not possible without significant effort. The reason for this is because of the way the partitions are laid out. They don't appear to be part of an LVM group. There is no reason why you cannot have two swap partitions – stratus Dec 19 '19 at 16:19
  • It seems that currently, you can't have a swap pool on ZFS without lockups/system freezes! please see: open issue, arch wiki and official zfs on linux wiki. – slashsbin Dec 20 '19 at 6:35
  • Your statements are misleading. You can (and I do) have several systems with swap on ZFS. In your links it very specifically says systems with high memory pressure. I have 5 systems with ubuntu/swap/zfs and none of them crash (uptime being measured in months), they are KVM hosts – stratus Dec 20 '19 at 12: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.