Shrink a Attached ZFS disk

Jan 22, 2018
34
2
28
42
NRW
Hello,

i have a VM with a few discs attached.

Now i want to shrink a disk that is attached from a ZFS Pool. Is there a easy way to do it? Because i already reduded filesystem and parition -100GiB, but now i am a bit confused how to redude the disk actually.

Thx
 
While i do not know what redude means, I would suggest you create a new smaller disk, attach it, copy over the data and remove th old bigger one.
 
Resizing is very easy, but not directly clear from reading the manpage:

Code:
root@proxmox:~# zfs create -s -V 2096M zpool/test

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
 
Yes, thats something i tought that would be doable via the GUI..

I don't think it'll ever be. Lots of people will click it and destroy their data because they don't know all the steps involved. You manually have to resize your guest fs, partition table and then the underlying storage, so you're better of doing everything manually.
 
Resizing is very easy, but not directly clear from reading the manpage:

Code:
root@proxmox:~# zfs create -s -V 2096M zpool/test

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

You make ZFS look so easy.

If you want to resize the zvol to enlarge it from its original size rather than to reduce it, assuming the pool has enough space for it, do you need to re-format the underlying fs of the zvol (ext4 on top of ZFS)?

In that case, would a simple backup copy of the existing data in the zvol (mainly .raw container files) to be later restored suffice?
 
You make ZFS look so easy.

It is :-D

If you want to resize the zvol to enlarge it from its original size rather than to reduce it, assuming the pool has enough space for it, do you need to re-format the underlying fs of the zvol (ext4 on top of ZFS)?

ext4 has an online growing feature. Just resize your Partition, potential LVM and then resize2fs and you're done. Growing is always very easy (also in windows). Shrinking is not.

In that case, would a simple backup copy of the existing data in the zvol (mainly .raw container files) to be later restored suffice?

You don't have .raw files, you have a zvol which is a block device, so no need for a file there. Do you mean a backup in the ZFS sense of send/receive or a real vzdump PVE backup? Both will work.

ZFS snapshots will also work:

Code:
root@proxmox ~ > zfs create -s -V 2096M zpool/test
root@proxmox ~ > zfs snapshot zpool/test@zfs-rules
root@proxmox ~ > zfs set volsize=2048M zpool/test
root@proxmox ~ > zfs snapshot zpool/test@zfs-rules-even-more
root@proxmox ~ > zfs set volsize=1024M zpool/test
root@proxmox ~ > zfs list -o name,used,volsize -r -t all zpool/test
NAME                             USED  VOLSIZE
zpool/test                       168K       1G
zpool/test@zfs-rules              56K    2,05G
zpool/test@zfs-rules-even-more    56K       2G
 
  • Like
Reactions: moxfan

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!