增加 ZFS 交换分区大小

增加 ZFS 交换分区大小

我正在以 root 身份运行 Xubuntu 19.10 和 ZFS。

如何增加交换分区(ZFS)的大小?

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 磁盘实用程序交换分区的屏幕截图: Gnome 磁盘实用程序的交换分区屏幕截图

请注意,它在rpool屏幕截图中被标记为。

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

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

答案1

从提供的输出来看,交换不是 zpool/zvol 的一部分。例如,这是一台在 ZFS 上有交换的机器的输出:

我的 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  -

“rpool”可能只是分区上的标签,并不指代 ZFS 卷。

如果您想将 SWAP 添加到 ZFS,您可以执行以下操作:

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

在您的 FSTAB 中:

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

确保设置合适的尺寸

相关内容