b0rken.org / freebsd / Resizing zpool comprising GPT partitions

Resizing zpool and underlying GPT partitions

Here are the results of my experiment in resizing the GPT partitions that a raidz zpool is built on. The test machine is a virtual host running 8.1-RELEASE amd64, with twelve 1GB virtual disks attached. They are detected by FreeBSD as ada1 through ada12.

  1. Create GPT tables on three disks:
  2. vFreeBSD# gpart create -s GPT ada1
    ada1 created
    vFreeBSD# gpart create -s GPT ada2
    ada2 created
    vFreeBSD# gpart create -s GPT ada3
    ada3 created
    
  3. Create one freebsd-zfs partition on each disk, each using half the available space (512MB):
  4. vFreeBSD# gpart add -s 1048576 -t freebsd-zfs ada1
    ada1p1 added
    vFreeBSD# gpart add -s 1048576 -t freebsd-zfs ada2
    ada2p1 added
    vFreeBSD# gpart add -s 1048576 -t freebsd-zfs ada3
    ada3p1 added
    
  5. Display partitions so far:
  6. vFreeBSD# gpart show
    (snipped)
    =>     34  2097085  ada1  GPT  (1.0G)
           34  1048576     1  freebsd-zfs  (512M)
      1048610  1048509        - free -  (512M)
    
    =>     34  2097085  ada2  GPT  (1.0G)
           34  1048576     1  freebsd-zfs  (512M)
      1048610  1048509        - free -  (512M)
    
    =>     34  2097085  ada3  GPT  (1.0G)
           34  1048576     1  freebsd-zfs  (512M)
      1048610  1048509        - free -  (512M)
    
  7. Create raidz pool and show the status:
  8. vFreeBSD# zpool create test1 raidz ada1p1 ada2p1 ada3p1
    vFreeBSD# zpool status
      pool: test1
     state: ONLINE
     scrub: none requested
    config:
    
            NAME        STATE     READ WRITE CKSUM
            test1       ONLINE       0     0     0
              raidz1    ONLINE       0     0     0
                ada1p1  ONLINE       0     0     0
                ada2p1  ONLINE       0     0     0
                ada3p1  ONLINE       0     0     0
    
    errors: No known data errors
    vFreeBSD# zfs list
    NAME    USED  AVAIL  REFER  MOUNTPOINT
    test1  87.9K   980M  24.0K  /test1
    

    The pool is about 1GB in size, which is expected for a raidz pool based on three 512MB devices

  9. Export the pool, delete one of the underlying partitions and recreate it spanning the whole disk:
  10. vFreeBSD# zpool export test1
    vFreeBSD# gpart delete -i 1 ada1
    ada1p1 deleted
    vFreeBSD# gpart add -t freebsd-zfs ada1
    ada1p1 added
    
    vFreeBSD# gpart show
    (snipped)
    =>     34  2097085  ada1  GPT  (1.0G)
           34  2097085     1  freebsd-zfs  (1.0G)
    
    =>     34  2097085  ada2  GPT  (1.0G)
           34  1048576     1  freebsd-zfs  (512M)
      1048610  1048509        - free -  (512M)
    
    =>     34  2097085  ada3  GPT  (1.0G)
           34  1048576     1  freebsd-zfs  (512M)
      1048610  1048509        - free -  (512M)
    
  11. Reimport the pool and check its status:
  12. vFreeBSD# zpool import test1
    vFreeBSD# zpool status
      pool: test1
     state: ONLINE
     scrub: none requested
    config:
    
            NAME        STATE     READ WRITE CKSUM
            test1       ONLINE       0     0     0
              raidz1    ONLINE       0     0     0
                ada1p1  ONLINE       0     0     0
                ada2p1  ONLINE       0     0     0
                ada3p1  ONLINE       0     0     0
    
    errors: No known data errors
    vFreeBSD# zfs list
    NAME    USED  AVAIL  REFER  MOUNTPOINT
    test1  87.9K   980M  24.0K  /test1
    

    The pool is still intact and has no errors and is the same size as before.

  13. Export pool and resize the other two partitions:
  14. vFreeBSD# zpool export test1
    vFreeBSD# gpart delete -i 1 ada2
    ada2p1 deleted
    vFreeBSD# gpart add -t freebsd-zfs ada2
    ada2p1 added
    vFreeBSD# gpart delete -i 1 ada3
    ada3p1 deleted
    vFreeBSD# gpart add -t freebsd-zfs ada3
    ada3p1 added
    vFreeBSD# gpart show
    (snipped)
    =>     34  2097085  ada1  GPT  (1.0G)
           34  2097085     1  freebsd-zfs  (1.0G)
    
    =>     34  2097085  ada2  GPT  (1.0G)
           34  2097085     1  freebsd-zfs  (1.0G)
    
    =>     34  2097085  ada3  GPT  (1.0G)
           34  2097085     1  freebsd-zfs  (1.0G)
    

    Now all three partitions underlying the zpool have been expanded from 512MB to 1GB

  15. Reimport the pool again and check its status:
  16. vFreeBSD# zpool import test1
    vFreeBSD# zpool status
      pool: test1
     state: ONLINE
     scrub: none requested
    config:
    
            NAME        STATE     READ WRITE CKSUM
            test1       ONLINE       0     0     0
              raidz1    ONLINE       0     0     0
                ada1p1  ONLINE       0     0     0
                ada2p1  ONLINE       0     0     0
                ada3p1  ONLINE       0     0     0
    
    errors: No known data errors
    vFreeBSD# zfs list
    NAME    USED  AVAIL  REFER  MOUNTPOINT
    test1  91.9K  1.96G  24.0K  /test1
    

    Now that all three underlying freebsd-zfs partitions have been grown, the zpool has automatically expanded to fill the available space and is now about 2GB in size. At no point was the zpool in an error state.

The act of deleting a partition does not in itself destroy the filesystem that was contained in it. As long as a new partition is created with the the same starting sector number and the ending sector number equal or greater then before, the filesystem should remain intact.


Last modified: 2011-01-30 10:54