freebsd-ports/sysutils/firstboot-growfs/files/firstboot_growfs.in
Steve Wills 2a218e9c2b sysutils/firstboot-growfs: revive
Revive this port as it will still be useful until the similar functionality in
base is more widely available, take ownership.
2014-12-24 04:50:16 +00:00

58 lines
1.2 KiB
Bash

#!/bin/sh
# $FreeBSD$
# 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"