#!/bin/sh # $FreeBSD: head/sysutils/firstboot-growfs/files/firstboot_growfs.in 372970 2014-11-20 23:57:07Z cperciva $ # KEYWORD: firstboot # PROVIDE: firstboot_growfs # REQUIRE: NETWORKING # BEFORE: LOGIN # Add the following lines to /etc/rc.conf.local or /etc/rc.conf (in the disk # image, since this only runs on the first boot) to enable this: # # firstboot_growfs_enable="YES" . /etc/rc.subr : ${firstboot_growfs_enable:="NO"} : ${firstboot_growfs_fs:="/"} name="firstboot_growfs" rcvar=firstboot_growfs_enable start_cmd="firstboot_growfs_run" stop_cmd=":" firstboot_growfs_run() { local FSTYPE DISK GPTLABEL GPART GDISK GPARTNO FSTYPE=`mount -p | awk "{ if (\\$2 == \"${firstboot_growfs_fs}\") print \\$3 }"` case ${FSTYPE} in ufs) ;; *) echo "${firstboot_growfs_fs} is not a UFS volume, cannot resize" ;; esac DISK=`mount -p | awk "{ if (\\$2 == \"${firstboot_growfs_fs}\") print \\$1 }"` case ${DISK} in /dev/gpt/*) GPTLABEL=${DISK##/dev/gpt/} ;; *) echo "${firstboot_growfs_fs} is not on a GPT disk, cannot resize" return 0 ;; esac GPART=`glabel status -s | awk "{ if (\\$1 == \"gpt/${GPTLABEL}\") print \\$3 }"` GDISK=${GPART%p*} GPARTNO=${GPART##*p} gpart recover ${GDISK} gpart resize -i ${GPARTNO} ${GDISK} growfs -y ${firstboot_growfs_fs} } load_rc_config $name run_rc_command "$1"