Resize partitions and zpool on the fly
Posted: June 20th, 2013 | Author: hiren | Filed under: FreeBSD, storage | Tags: zfs gpart freebsd-current | No Comments »This is how my disk layout looked before the change:
# gpart show -l
=> 63 250069617 ada0 MBR (119G)
63 250069617 1 (null) [active] (119G)
=> 0 250069617 ada0s1 BSD (119G)
0 115343360 1 (null) (55G)
115343360 117440512 2 (null) (56G)
232783872 17285745 4 (null) (8.2G)
# bsdlabel ada0s1
# /dev/ada0s1:
8 partitions:
# size offset fstype [fsize bsize bps/cpg]
a: 115343360 0 ZFS
b: 117440512 115343360 ZFS
c: 250069617 0 unused 0 0 # "raw" part, don't edit
d: 17285745 232783872 swap
# zpool status
pool: zroot
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
zroot ONLINE 0 0 0
ada0s1a ONLINE 0 0 0
errors: No known data errors
# zpool list
NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT
zroot 54.5G 39.1G 15.4G 71% 1.00x ONLINE -
Above you can see only ada0s1a (55G) was being used by my zpool: zroot.
I wanted to extend it to use the ada0s1b (56G) too.
1) Set autoexpand to “on” on zroot
# zpool get autoexpand zroot
NAME PROPERTY VALUE SOURCE
zroot autoexpand off default
# zpool set autoexpand=on zroot
# zpool get autoexpand zroot
NAME PROPERTY VALUE SOURCE
zroot autoexpand on local
2) Tell geom: “I know what I am doing”
# sysctl kern.geom.debugflags=16
kern.geom.debugflags: 0 -> 16
3) Delete the unused partition
# gpart delete -i 2 ada0s1
ada0s1b deleted
# gpart show
=> 63 250069617 ada0 MBR (119G)
63 250069617 1 freebsd [active] (119G)
=> 0 250069617 ada0s1 BSD (119G)
0 115343360 1 freebsd-zfs (55G)
115343360 117440512 - free - (56G)
232783872 17285745 4 freebsd-swap (8.2G)
4) Resize the partition in use to include the unused space
# gpart resize -s 232783872 -i 1 ada0s1
ada0s1a resized
# gpart show
=> 63 250069617 ada0 MBR (119G)
63 250069617 1 freebsd [active] (119G)
=> 0 250069617 ada0s1 BSD (119G)
0 232783872 1 freebsd-zfs (111G)
232783872 17285745 4 freebsd-swap (8.2G)
# zpool status
pool: zroot
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
zroot ONLINE 0 0 0
ada0s1a ONLINE 0 0 0
errors: No known data errors
5) Make zfs realize the fact that partition has been changed and make zpool
use the new partition which is actually the same one (ada0s1a).
# zpool online -e zroot ada0s1a ada0s1a
# zpool status
pool: zroot
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
zroot ONLINE 0 0 0
ada0s1a ONLINE 0 0 0
errors: No known data errors
6) Look at the success (SIZE is now 110G)
# zpool list
NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT
zroot 110G 39.1G 71.4G 35% 1.00x ONLINE -