summaryrefslogtreecommitdiff
path: root/sysutils/firstboot-growfs/files/firstboot_growfs.in
blob: d767e6876b254c7a9d11a775fdf9fcfd1e803506 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh

# 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"