En este artículo voy a explicar cómo redimensionar (expandir) una partición que contiene un sistema de archivos ZFS en Linux, típicamente luego de haber aumentado el tamaño del disco de una máquina virtual.
Un sistema GNU/Linux (Debian), corriendo en una máquina virtual, posee un disco /dev/sdb
dedicado completamente a un pool ZFS ("z01"):
root@debian:~# zpool history | grep /dev 2019-07-01.11:25:38 zpool create z01 /dev/sdb
Este pool tiene un tamaño de 16 BG:
root@debian:~# df -h /z01 Filesystem Size Used Avail Use% Mounted on z01 16G 0 16G 0% /z01
El disco ha sido expandido hasta los 50 GB, tal como se observa en la salida de fdisk
:
root@debian:~# fdisk -l /dev/sdb Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors Disk model: Virtual disk 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: 88D5429F-FF6F-9242-AAD0-F651682DAAEB Device Start End Sectors Size Type /dev/sdb1 2048 33554398 33552351 16G Solaris /usr & Apple ZFS
Veamos entonces cómo expandir el pool "z01" para que haga uso de los 50 GB disponibles desde este momento.
La tarea es relativamente sencilla y consiste en redimensionar la única partición presente en el disco, creada por ZFS. A tal fin es posible utilizar cualquier herramienta como fdisk
, parted
u otra.
No hace falta mencionar que es necesario contar con un backup completo y fresco antes de comenzar, y no hacerlo sobre un sistema en producción, ya que estamos manipulando estructuras de ZFS de forma manual. Hay un riesgo inevitable de pérdida o corrupción de datos e integridad de la información almacenada en el sistema de archivos.
A continuación se demuestra el procedimiento utilizando la herramienta fdisk
, tal como explica el artículo: Cómo redimensionar una partición con fdisk.
Ejecutar fdisk
pasando como parámetro el dispositivo que corresponde con el disco completo:
root@debian:~# fdisk /dev/sdb Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. GPT PMBR size mismatch (33554431 != 104857599) will be corrected by write. The backup GPT table is not on the end of the device. This problem will be corrected by write. Command (m for help): p Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors Disk model: Virtual disk 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: 88D5429F-FF6F-9242-AAD0-F651682DAAEB Device Start End Sectors Size Type /dev/sdb1 2048 33554398 33552351 16G Solaris /usr & Apple ZFS
Para redimensionar una partición con fdisk
, simplemente se debe borrar y volver a crear, cuidando que comience en exactamente el mismo sector:
Command (m for help): d Selected partition 1 Partition 1 has been deleted. Command (m for help): n Partition number (1-128, default 1): First sector (34-104857566, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-104857566, default 104857566): Created a new partition 1 of type 'Linux filesystem' and of size 50 GiB. Partition #1 contains a zfs_member signature. Do you want to remove the signature? [Y]es/[N]o: n
En este punto es importante no borrar la firma de la tabla de particiones para no corromper el pool ZFS (responder "No").
Command (m for help): p Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors Disk model: Virtual disk 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: 88D5429F-FF6F-9242-AAD0-F651682DAAEB Device Start End Sectors Size Type /dev/sdb1 2048 104857566 104855519 50G Linux filesystem
Luego es necesario restablecer el tipo de partición a 48 ("Solaris /usr & Apple ZFS"):
Command (m for help): t Selected partition 1 Partition type (type L to list all types): 48 Changed type of partition 'Linux filesystem' to 'Solaris /usr & Apple ZFS'. Command (m for help): p Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors Disk model: Virtual disk 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: 88D5429F-FF6F-9242-AAD0-F651682DAAEB Device Start End Sectors Size Type /dev/sdb1 2048 104857566 104855519 50G Solaris /usr & Apple ZFS
Finalmente, escribir los cambios en la tabla de partición:
Command (m for help): w The partition table has been altered. Syncing disks. root@debian:~#
Verificar el cambio de tamaño de la partición sdb1
:
root@debian:~# fdisk -l /dev/sdb Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors Disk model: Virtual disk 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: 88D5429F-FF6F-9242-AAD0-F651682DAAEB Device Start End Sectors Size Type /dev/sdb1 2048 104857566 104855519 50G Solaris /usr & Apple ZFS
Ahora resta expandir el pool ZFS. Para ello se debe habilitar la propiedad autoexpand del pool, para luego expandirlo utilizando el comando online -e
:
root@debian:~# zpool set autoexpand=on z01 root@debian:~# zpool online -e z01 sdb root@debian:~# zfs list NAME USED AVAIL REFER MOUNTPOINT z01 231K 48,3G 24K /z01 z01/backups 24K 48,3G 24K /backups
Por último, es recomendable correr un chequeo de integridad del pool mediante el comando scrub
:
root@debian:~# zpool scrub z01 root@debian:~# zpool status z01 pool: z01 state: ONLINE scan: scrub repaired 0B in 0h0m with 0 errors on Fri Aug 23 09:49:28 2019 config: NAME STATE READ WRITE CKSUM z01 ONLINE 0 0 0 sdb ONLINE 0 0 0 errors: No known data errors
¡Eso es todo amigues!
Referencias
man zfs
man zpool
man fdisk
- Linux ZFS & resizing single disk pool
- Introducción a ZFS en FreeBSD
- Checking ZFS File System Integrity
- wipefs(8) - Linux manual page