Resize partition in FreeBSD with growfs
It’s hard to say, which partition will grow more during system work at installation time. So in one good day nagios will start alerting you about space shortage! Nowadays it’s not topical problem, but it could happen, as it was with me.Some administrator before me prepared solution for this case. He added one empty partition /mnt/b for cutting space from it in future. So my task was to grow one working partition without data loss.
What we have in the beginning:
df -h /dev/da1s1a 989M 488M 442M 52% /mnt/a /dev/da1s1b 6.8G 4.0K 6.4G 0% /mnt/b
We want to resize /dev/da1s1a up to 2GB. For this task we need some utils: bsdlabel, newfs, growfs.
First is to unmount partitions.
umount /mnt/a umount /mnt/b
After this we must change label data on slice /dev/da1s1
bsdlabel -e /dev/da1s1 # /dev/da1s1: 8 partitions: # size offset fstype [fsize bsize bps/cpg] a: 2097152 16 4.2BSD 2048 16384 28528 b: 14674629 2097168 4.2BSD 2048 16384 28448 c: 16771797 0 unused 0 0 # "raw" part, don't edit
After changing it would look like
# /dev/da1s1: 8 partitions: # size offset fstype [fsize bsize bps/cpg] a: 2048M 16 4.2BSD 2048 16384 28528 b: * * 4.2BSD 2048 16384 28448 c: 16771797 0 unused 0 0 # "raw" part, don't edit
Now it’s time to run growfs. It has key -s for setting new size of partition. One note, growfs works with size in blocks, so for 2GB it would be 4190208 ( 2 * 1024 * 1024 * 1024 / 512 ) because default block size is 512B.
growfs -s 4190208 /dev/da1s1a newfs -U /dev/da1s1b mount /dev/da1s1a /mnt/a mount /dev/da1s1b /mnt/b df -h /dev/da1s1a 1.9G 488M 452378 52% /mnt/a /dev/da1s1b 5.8G 4K 6674404 0% /mnt/b
I don’t know any way to resize /dev/da1s1b down, so we just run newfs against it.
|
|