Opened 2 years ago

Last modified 2 years ago

#342 new enhancement

Add ability to grow/resize a volume (ZFS)

Reported by: fraenki Owned by:
Priority: minor Milestone:
Component: Backend Version: 8.0-RELEASE
Keywords: grow, resize, filesystem, zfs Cc: fw@…

Description

I've got a (virtual) FreeNAS 8.0 appliance with 200 GB disk space. Lately I've grown the (virtual) disk to 500 GB, but FreeNAS does not provide a way to grow the logical volume.

It should be possible to resize or at least grow a ZFS volume with FreeNAS. (I know it's not possible for UFS, but ZFS should work.)

Is there a way to grow the volume on the CLI? Just asking for a workaround until resize is offcially supported :)

Change History (4)

comment:1 Changed 2 years ago by jpaetzel

Running zpool export then zpool import at the CLI should work to get it seeing the new size.

comment:2 Changed 2 years ago by fraenki

I did a quick test with a new disk:

  1. created a 33 GB disk
  2. added the disk in FreeNAS: ZFS pool "test1"
  3. shutdown; increase disk size to 77 GB; power-up FreeNAS
  4. on the CLI: zpool export test1
  5. on the CLI: zpool import test1
  6. no luck :(

# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
test1 30.8G 97.5K 30.7G 0% ONLINE -

# zpool get "all" test1
NAME PROPERTY VALUE SOURCE
test1 size 30.8G -
test1 used 97.5K -
test1 available 30.7G -
test1 capacity 0% -
test1 altroot - default
test1 health ONLINE -
test1 guid 16911801513613885688 default
test1 version 15 default
test1 bootfs - default
test1 delegation on default
test1 autoreplace off default
test1 cachefile - default
test1 failmode wait default
test1 listsnapshots off default

Still 33 GB instead of 77 GB. Is there anything else I could try?

comment:3 Changed 2 years ago by jpaetzel

Lightbulb. I know what the issue is now.

The underlying ZFS device is a GPT partition on the drive. When you increase the size of the disk the GPT partition does not change size.

You can see the GPT partitions by doing zpool status in the CLI.

So for example:

I created a pool on a 8 gig drive.

freenas# zpool status grow

  pool: grow
 state: ONLINE
 scrub: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        grow        ONLINE       0     0     0
          gpt/da8   ONLINE       0     0     0

errors: No known data errors

freenas# gpart show da8

=>      34  16777149  da8  GPT  (8.0G)
        34        94       - free -  (47K)
       128   4194304    1  freebsd-swap  (2.0G)
   4194432  12582751    2  freebsd-zfs  (6.0G)

I then shut down the VM and expanded the disk to 16 GB

You have to reboot the system for FreeBSD to see the new device size.

After reboot:

freenas# gpart show da8
=>      34  16777149  da8  GPT  (16G) [CORRUPT]
        34        94       - free -  (47K)
       128   4194304    1  freebsd-swap  (2.0G)
   4194432  12582751    2  freebsd-zfs  (6.0G)

So the gpart table is corrupt, but that can be fixed:
freenas# gpart recover da8

da8 recovered

And now it shows:
freenas# gpart show da8

=>      34  33554365  da8  GPT  (16G)
        34        94       - free -  (47K)
       128   4194304    1  freebsd-swap  (2.0G)
   4194432  12582751    2  freebsd-zfs  (6.0G)
  16777183  16777216       - free -  (8.0G)

Now you need to export the pool:

freenas# zpool export grow

And then the scary part. There's no way to grow a gpart partition, so you have to delete it and recreate it.

freenas# gpart delete -i 2 da8

da8p2 deleted

freenas# gpart add -t freebsd-zfs -b 4194432 -l da8 da8

da8p2 added

freenas# gpart show da8

=>      34  33554365  da8  GPT  (16G)
        34        94       - free -  (47K)
       128   4194304    1  freebsd-swap  (2.0G)
   4194432  29359967    2  freebsd-zfs  (14G)

freenas# zpool import grow
freenas# zpool status grow

  pool: grow
 state: ONLINE
 scrub: none requested
config:

        NAME                                          STATE     READ WRITE CKSUM
        grow                                          ONLINE       0     0     0
          gptid/16b619e1-7d65-11e0-8100-000c292f41c2  ONLINE       0     0     0

errors: No known data errors

freenas# zpool list grow

NAME   SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
grow  14.0G  94.5K  14.0G     0%  ONLINE  -

The magic here is that if you use the same start block as the original partition (the -b flag to gpart add) then nothing will be changed.

comment:4 Changed 2 years ago by delphij

Hi,

In order to "grow" a disk, the following operation have to be done from command line at this time. We are working on a better solution.

# zpool export pool_to_be_grown
# swapoff -a
(make the disk grow)
# gpart backup ada0 > ada0.gpart
(repeat for EVERY disk in the pool; this is to backup the partition table in a text file so you could recover from mistake.)
# gpart resize -i 2 ada0
(2 is the typical index number, repeat for every disk in the pool)
# gpart show
(review if the partiton table is good)
# swapon -a
# zpool import pool_to_be_grown

ZFS will automatically pick up with the changes of underlying disk.

Hope this helps.

Note: See TracTickets for help on using tickets.