Nutilius technical notices (IAOE - I am only engineer)

FreeBSD resize zfs root partition

Published on: 2025-05-07 22:13:33 • 1 min read

Notices for FreeBSD resize zfs root partition

State before - virtual disk was expanded by provider - addtional 200 GB was added.

After resizing virtual disk the GPT partition was corrupted:

root@beastie:~ # gpart show
=>       40  838860720  da0  GPT  (600G) [CORRUPT]
         40       1024    1  freebsd-boot  (512K)
       1064        984       - free -  (492K)
       2048    4194304    2  freebsd-swap  (2.0G)
    4196352  834662400    3  freebsd-zfs  (398G)
  838858752       2008       - free -  (1.0M)

Disk after resizing shown in geom:

root@beastie:~ # geom disk list
Geom name: da0
Providers:
1. Name: da0
   Mediasize: 644245094400 (600G)
   Sectorsize: 512
   Stripesize: 4096
   Stripeoffset: 0
   Mode: r2w2e3
   descr: QEMU QEMU HARDDISK
   ident: (null)
   rotationrate: 0
   fwsectors: 63
   fwheads: 255

Correction of GPT:

GPT was CORRUPT because second copy in the end of disk was "destroyed" - new end of disk doesn't have second copy. TO correct GPT use recover option:

gpart recover da0

Status of disk after recover:

root@beastie:~ # gpart show da0
=>        40  1258291120  da0  GPT  (600G)
          40        1024    1  freebsd-boot  (512K)
        1064         984       - free -  (492K)
        2048     4194304    2  freebsd-swap  (2.0G)
     4196352   834662400    3  freebsd-zfs  (398G)
   838858752   419432408       - free -  (200G)

Status of zpool zroot

root@beastie:~ # zpool list
NAME    SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
zroot   396G  10.3G   386G        -         -     0%     2%  1.00x    ONLINE  -

Enable autoexpand

root@beastie:~ # zpool set autoexpand=on zroot

Status of zpool after autoexpand.

root@beastie:~ # zpool list
NAME    SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
zroot   596G  10.3G   586G        -         -     0%     1%  1.00x    ONLINE  -