1

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
  • 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
0

If you want to decrease the size of a ZFS partition see:

Resizing is very easy, but not directly clear from reading the manpage:


root@proxmox:~# zfs get volsize zpool/test NAME        PROPERTY  VALUE
SOURCE zpool/test  volsize   2,05G    local

root@proxmox:~# zfs set volsize=2048M zpool/test

root@proxmox:~# zfs get volsize zpool/test NAME        PROPERTY  VALUE
SOURCE zpool/test  volsize   2G       local

root@proxmox:~# fdisk -l /dev/zvol/zpool/test Disk
/dev/zvol/zpool/test: 2 GiB, 2147483648 bytes, 4194304 sectors Units:
sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512
bytes / 8192 bytes I/O size (minimum/optimal): 8192 bytes / 8192 bytes

root@proxmox:~# zfs set volsize=1024M zpool/test

root@proxmox:~# fdisk -l /dev/zvol/zpool/test Disk
/dev/zvol/zpool/test: 1 GiB, 1073741824 bytes, 2097152 sectors Units:
sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512
bytes / 8192 bytes I/O size (minimum/optimal): 8192 bytes / 8192 bytes

It's actually easier than using gparted the old fashioned way.

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.