| 
      1
     | 
    
      diff --git a/src/etc/rc.be_functions.sh b/src/etc/rc.be_functions.sh
 
     | 
  
  
    | 
      2
     | 
    
      index 625ca123ec6844fbe3f44e5fcea5ed3c47e59f86..a0f0bc56d2e154d5f05d0b8905d8bb2e4a4b8776 100644
 
     | 
  
  
    | 
      3
     | 
    
      --- a/src/etc/rc.be_functions.sh
 
     | 
  
  
    | 
      4
     | 
    
      +++ b/src/etc/rc.be_functions.sh
 
     | 
  
  
    | 
      5
     | 
    
      @@ -37,14 +37,14 @@ existing_base_dir()
 
     | 
  
  
    | 
      6
     | 
    
       be_remount_subordinate()
 
     | 
  
  
    | 
      7
     | 
    
       {
     | 
  
  
    | 
      8
     | 
    
       	/sbin/zfs list -rH -o mountpoint,name,canmount,mounted -s mountpoint -t filesystem "${1}" | \
     | 
  
  
    | 
      9
     | 
    
      -	while read _mp _name _canmount _mounted ; do
 
     | 
  
  
    | 
      10
     | 
    
      -		# skip filesystems that must *not* be mounted
 
     | 
  
  
    | 
      11
     | 
    
      -		[ "${_canmount}" = "off" -o "${_mp}" = "/" ] && continue
     | 
  
  
    | 
      12
     | 
    
      -		# unmount the dataset if mounted...
 
     | 
  
  
    | 
      13
     | 
    
      -		[ "${_mounted}" = "yes" ] && /sbin/zfs umount -f "${_name}"
     | 
  
  
    | 
      14
     | 
    
      -		# finally, mount the dataset
 
     | 
  
  
    | 
      15
     | 
    
      -		/sbin/zfs mount "${_name}"
     | 
  
  
    | 
      16
     | 
    
      -	done
 
     | 
  
  
    | 
      17
     | 
    
      +		while read _mp _name _canmount _mounted ; do
 
     | 
  
  
    | 
      18
     | 
    
      +			# skip filesystems that must *not* be mounted
 
     | 
  
  
    | 
      19
     | 
    
      +			[ "${_canmount}" = "off" -o "${_mp}" = "/" ] && continue
     | 
  
  
    | 
      20
     | 
    
      +			# unmount the dataset if mounted...
 
     | 
  
  
    | 
      21
     | 
    
      +			[ "${_mounted}" = "yes" ] && /sbin/zfs umount -f "${_name}"
     | 
  
  
    | 
      22
     | 
    
      +			# finally, mount the dataset
 
     | 
  
  
    | 
      23
     | 
    
      +			/sbin/zfs mount "${_name}"
     | 
  
  
    | 
      24
     | 
    
      +		done
 
     | 
  
  
    | 
      25
     | 
    
       }
 
     | 
  
  
    | 
      26
     | 
    
       
 
     | 
  
  
    | 
      27
     | 
    
       #
 
     | 
  
  
    | 
      28
     | 
    
      @@ -62,27 +62,29 @@ be_mount_zfs() {
     | 
  
  
    | 
      29
     | 
    
       }
 
     | 
  
  
    | 
      30
     | 
    
       
 
     | 
  
  
    | 
      31
     | 
    
       #
 
     | 
  
  
    | 
      32
     | 
    
      -# Test if root on ZFS 
 
     | 
  
  
    | 
      33
     | 
    
      +# Get the active root dataset
 
     | 
  
  
    | 
      34
     | 
    
       #
 
     | 
  
  
    | 
      35
     | 
    
      -zfs_on_root()
 
     | 
  
  
    | 
      36
     | 
    
      +# Example: pfSense/ROOT/default
 
     | 
  
  
    | 
      37
     | 
    
      +#
 
     | 
  
  
    | 
      38
     | 
    
      +zfs_root_dataset()
 
     | 
  
  
    | 
      39
     | 
    
       {
     | 
  
  
    | 
      40
     | 
    
      -	local _mountfrom="$(/bin/kenv -q vfs.root.mountfrom)"
 
     | 
  
  
    | 
      41
     | 
    
      -	[ "${_mountfrom%%:*}" = "zfs" ]
     | 
  
  
    | 
      42
     | 
    
      +	local _mountfrom _rootds
 
     | 
  
  
    | 
      43
     | 
    
      +
 
     | 
  
  
    | 
      44
     | 
    
      +	_mountfrom="$(/bin/kenv -q vfs.root.mountfrom)"
 
     | 
  
  
    | 
      45
     | 
    
      +	[ "${_mountfrom%%:*}" = "zfs" ] || return 1
     | 
  
  
    | 
      46
     | 
    
      +
 
     | 
  
  
    | 
      47
     | 
    
      +	_rootds="${_mountfrom##*:}"
     | 
  
  
    | 
      48
     | 
    
      +	[ -n "${_rootds}" ] || return 1
     | 
  
  
    | 
      49
     | 
    
      +
 
     | 
  
  
    | 
      50
     | 
    
      +	echo "${_rootds}"
     | 
  
  
    | 
      51
     | 
    
       }
 
     | 
  
  
    | 
      52
     | 
    
       
 
     | 
  
  
    | 
      53
     | 
    
       #
 
     | 
  
  
    | 
      54
     | 
    
      -# Get the active root dataset
 
     | 
  
  
    | 
      55
     | 
    
      -#
 
     | 
  
  
    | 
      56
     | 
    
      -# Example: pfSense/ROOT/default
 
     | 
  
  
    | 
      57
     | 
    
      +# Test if root on ZFS
 
     | 
  
  
    | 
      58
     | 
    
       #
 
     | 
  
  
    | 
      59
     | 
    
      -zfs_root()
 
     | 
  
  
    | 
      60
     | 
    
      +zfs_on_root()
 
     | 
  
  
    | 
      61
     | 
    
       {
     | 
  
  
    | 
      62
     | 
    
      -	if zfs_on_root; then
 
     | 
  
  
    | 
      63
     | 
    
      -		/sbin/mount | while read _name _on _mp _more; do
 
     | 
  
  
    | 
      64
     | 
    
      -			[ ! "${_mp}" = "/" ] && continue
     | 
  
  
    | 
      65
     | 
    
      -			echo "${_name}"
     | 
  
  
    | 
      66
     | 
    
      -		done
 
     | 
  
  
    | 
      67
     | 
    
      -	fi
 
     | 
  
  
    | 
      68
     | 
    
      +	zfs_root_dataset >/dev/null 2>&1
 
     | 
  
  
    | 
      69
     | 
    
       }
 
     | 
  
  
    | 
      70
     | 
    
       
 
     | 
  
  
    | 
      71
     | 
    
       #
 
     | 
  
  
    | 
      72
     | 
    
      @@ -92,9 +94,24 @@ zfs_root()
 
     | 
  
  
    | 
      73
     | 
    
       #
 
     | 
  
  
    | 
      74
     | 
    
       zfs_root_pool()
 
     | 
  
  
    | 
      75
     | 
    
       {
     | 
  
  
    | 
      76
     | 
    
      -	local _rootds="$(zfs_root)"
 
     | 
  
  
    | 
      77
     | 
    
      -	[ $? -ne 0 ] && return 1
 
     | 
  
  
    | 
      78
     | 
    
      -	echo "${_rootds%%/*}"
     | 
  
  
    | 
      79
     | 
    
      +	local _rootds _pool
 
     | 
  
  
    | 
      80
     | 
    
      +
 
     | 
  
  
    | 
      81
     | 
    
      +	_rootds="$(zfs_root_dataset)"
 
     | 
  
  
    | 
      82
     | 
    
      +	_pool="${_rootds%%/*}"
     | 
  
  
    | 
      83
     | 
    
      +
 
     | 
  
  
    | 
      84
     | 
    
      +	[ -n "${_pool}" ] || return 1
     | 
  
  
    | 
      85
     | 
    
      +
 
     | 
  
  
    | 
      86
     | 
    
      +	echo "${_pool}"
     | 
  
  
    | 
      87
     | 
    
      +}
 
     | 
  
  
    | 
      88
     | 
    
      +
 
     | 
  
  
    | 
      89
     | 
    
      +#
 
     | 
  
  
    | 
      90
     | 
    
      +# DEPRECATED: Get the active root dataset
 
     | 
  
  
    | 
      91
     | 
    
      +#
 
     | 
  
  
    | 
      92
     | 
    
      +# Example: pfSense/ROOT/default
 
     | 
  
  
    | 
      93
     | 
    
      +#
 
     | 
  
  
    | 
      94
     | 
    
      +zfs_root()
 
     | 
  
  
    | 
      95
     | 
    
      +{
     | 
  
  
    | 
      96
     | 
    
      +	zfs_root_dataset
 
     | 
  
  
    | 
      97
     | 
    
       }
 
     | 
  
  
    | 
      98
     | 
    
       
 
     | 
  
  
    | 
      99
     | 
    
       #
 
     | 
  
  
    | 
      100
     | 
    
      @@ -114,8 +131,8 @@ zfs_be_root()
 
     | 
  
  
    | 
      101
     | 
    
       #
 
     | 
  
  
    | 
      102
     | 
    
       zfs_path_dataset()
 
     | 
  
  
    | 
      103
     | 
    
       {
     | 
  
  
    | 
      104
     | 
    
      -	zfs_on_root || return 1
 
     | 
  
  
    | 
      105
     | 
    
      -	/sbin/zfs list -H -d 0 -t filesystem -o name "$(existing_base_dir "${1}")" 2>/dev/null
     | 
  
  
    | 
      106
     | 
    
      +	zfs_on_root && \
 
     | 
  
  
    | 
      107
     | 
    
      +		/sbin/zfs list -H -d 0 -t filesystem -o name "$(existing_base_dir "${1}")" 2>/dev/null
     | 
  
  
    | 
      108
     | 
    
       }
 
     | 
  
  
    | 
      109
     | 
    
       
 
     | 
  
  
    | 
      110
     | 
    
       #
 
     | 
  
  
    | 
      111
     | 
    
      @@ -141,8 +158,8 @@ zfs_ds_exists()
 
     | 
  
  
    | 
      112
     | 
    
       # Set a ZFS user property
 
     | 
  
  
    | 
      113
     | 
    
       zfs_set_prop()
 
     | 
  
  
    | 
      114
     | 
    
       {
     | 
  
  
    | 
      115
     | 
    
      -	zfs_on_root || return 1
 
     | 
  
  
    | 
      116
     | 
    
      -	/sbin/zfs set "${2}=${3}" "${1}" 1>/dev/null 2>&1
     | 
  
  
    | 
      117
     | 
    
      +	zfs_on_root && \
 
     | 
  
  
    | 
      118
     | 
    
      +		/sbin/zfs set "${2}=${3}" "${1}" 1>/dev/null 2>&1
     | 
  
  
    | 
      119
     | 
    
       }
 
     | 
  
  
    | 
      120
     | 
    
       
 
     | 
  
  
    | 
      121
     | 
    
       #
 
     | 
  
  
    | 
      122
     | 
    
      @@ -150,16 +167,17 @@ zfs_set_prop()
 
     | 
  
  
    | 
      123
     | 
    
       #
 
     | 
  
  
    | 
      124
     | 
    
       zfs_unset_prop()
 
     | 
  
  
    | 
      125
     | 
    
       {
     | 
  
  
    | 
      126
     | 
    
      -	zfs_on_root || return 1
 
     | 
  
  
    | 
      127
     | 
    
      -	/sbin/zfs inherit -r "${2}" "${1}" 1>/dev/null 2>&1
     | 
  
  
    | 
      128
     | 
    
      +	zfs_on_root && \
 
     | 
  
  
    | 
      129
     | 
    
      +		/sbin/zfs inherit -r "${2}" "${1}" 1>/dev/null 2>&1
     | 
  
  
    | 
      130
     | 
    
       }
 
     | 
  
  
    | 
      131
     | 
    
      +
 
     | 
  
  
    | 
      132
     | 
    
       #
 
     | 
  
  
    | 
      133
     | 
    
       # Get a ZFS user property
 
     | 
  
  
    | 
      134
     | 
    
       #
 
     | 
  
  
    | 
      135
     | 
    
       zfs_get_prop()
 
     | 
  
  
    | 
      136
     | 
    
       {
     | 
  
  
    | 
      137
     | 
    
      -	zfs_on_root || return 1
 
     | 
  
  
    | 
      138
     | 
    
      -	/sbin/zfs get -H -o value "${2}" "${1}" 2>/dev/null
     | 
  
  
    | 
      139
     | 
    
      +	zfs_on_root && \
 
     | 
  
  
    | 
      140
     | 
    
      +		/sbin/zfs get -H -o value "${2}" "${1}" 2>/dev/null
     | 
  
  
    | 
      141
     | 
    
       }
 
     | 
  
  
    | 
      142
     | 
    
       
 
     | 
  
  
    | 
      143
     | 
    
       #
 
     | 
  
  
    | 
      144
     | 
    
      @@ -167,8 +185,8 @@ zfs_get_prop()
 
     | 
  
  
    | 
      145
     | 
    
       #
 
     | 
  
  
    | 
      146
     | 
    
       zfs_test_prop_eq()
 
     | 
  
  
    | 
      147
     | 
    
       {
     | 
  
  
    | 
      148
     | 
    
      -	zfs_on_root || return 1
 
     | 
  
  
    | 
      149
     | 
    
      -	[ "$(zfs_get_prop "${1}" "${2}")" = "${3}" ]
     | 
  
  
    | 
      150
     | 
    
      +	zfs_on_root && \
 
     | 
  
  
    | 
      151
     | 
    
      +		[ "$(zfs_get_prop "${1}" "${2}")" = "${3}" ]
     | 
  
  
    | 
      152
     | 
    
       }
 
     | 
  
  
    | 
      153
     | 
    
       
 
     | 
  
  
    | 
      154
     | 
    
       #
 
     | 
  
  
    | 
      155
     | 
    
      @@ -440,6 +458,9 @@ be_recent_name()
 
     | 
  
  
    | 
      156
     | 
    
       	echo "${_recent}"
     | 
  
  
    | 
      157
     | 
    
       }
 
     | 
  
  
    | 
      158
     | 
    
       
 
     | 
  
  
    | 
      159
     | 
    
      +#
 
     | 
  
  
    | 
      160
     | 
    
      +# Find a BE by ZFS property ($1) and optional value ($2)
 
     | 
  
  
    | 
      161
     | 
    
      +#
 
     | 
  
  
    | 
      162
     | 
    
       be_find_by_prop()
 
     | 
  
  
    | 
      163
     | 
    
       {
     | 
  
  
    | 
      164
     | 
    
       	local _p="${1}"
     | 
  
  
    | 
      165
     | 
    
      @@ -447,10 +468,10 @@ be_find_by_prop()
 
     | 
  
  
    | 
      166
     | 
    
       
 
     | 
  
  
    | 
      167
     | 
    
       	if zfs_on_root; then
 
     | 
  
  
    | 
      168
     | 
    
       		/sbin/zfs list -r -d 1 -H -o name,${_p} -S ${_p} "$(zfs_be_root)" | \
     | 
  
  
    | 
      169
     | 
    
      -		while read _name _previous; do
 
     | 
  
  
    | 
      170
     | 
    
      -			[ "${_previous}" = "${_v}" ] || continue;
     | 
  
  
    | 
      171
     | 
    
      -			echo ${_name##$(zfs_be_root)/}
     | 
  
  
    | 
      172
     | 
    
      -			return # we are done
 
     | 
  
  
    | 
      173
     | 
    
      -		done
 
     | 
  
  
    | 
      174
     | 
    
      +			while read _name _previous; do
 
     | 
  
  
    | 
      175
     | 
    
      +				[ "${_previous}" = "${_v}" ] || continue;
     | 
  
  
    | 
      176
     | 
    
      +				echo ${_name##$(zfs_be_root)/}
     | 
  
  
    | 
      177
     | 
    
      +				return # we are done
 
     | 
  
  
    | 
      178
     | 
    
      +			done
 
     | 
  
  
    | 
      179
     | 
    
       	fi
 
     | 
  
  
    | 
      180
     | 
    
       }
 
     | 
  
  
    | 
      181
     | 
    
      diff --git a/src/etc/pfSense-rc b/src/etc/pfSense-rc
 
     | 
  
  
    | 
      182
     | 
    
      index 6ab0bc59d7187fb40f9dd7ff7fbcb35197216925..7c670f0b5d6829c2264f9a44ce400a2203bd7e0f 100755
 
     | 
  
  
    | 
      183
     | 
    
      --- a/src/etc/pfSense-rc
 
     | 
  
  
    | 
      184
     | 
    
      +++ b/src/etc/pfSense-rc
 
     | 
  
  
    | 
      185
     | 
    
      @@ -440,9 +440,11 @@ if /sbin/kldstat -qm zfs; then
 
     | 
  
  
    | 
      186
     | 
    
       		errexit_on
 
     | 
  
  
    | 
      187
     | 
    
       	else
 
     | 
  
  
    | 
      188
     | 
    
       		USE_ZFS=1
 
     | 
  
  
    | 
      189
     | 
    
      -		! ZFSROOT="$(zfs_root)"
 
     | 
  
  
    | 
      190
     | 
    
      -		if [ -n "$ZFSROOT" ]; then
 
     | 
  
  
    | 
      191
     | 
    
      -			/sbin/zfs set readonly=off "$ZFSROOT"
 
     | 
  
  
    | 
      192
     | 
    
      +		errexit_off
 
     | 
  
  
    | 
      193
     | 
    
      +		ZFSROOT="$(zfs_root_dataset)"
 
     | 
  
  
    | 
      194
     | 
    
      +		errexit_on
 
     | 
  
  
    | 
      195
     | 
    
      +		if [ -n "${ZFSROOT}" ]; then
     | 
  
  
    | 
      196
     | 
    
      +			/sbin/zfs set readonly=off "${ZFSROOT}"
     | 
  
  
    | 
      197
     | 
    
       		fi
 
     | 
  
  
    | 
      198
     | 
    
       		/sbin/zfs mount -a
 
     | 
  
  
    | 
      199
     | 
    
       		# If /bootpool is present, then there is an additional zfs pool to import
 
     | 
  
  
    | 
      200
     | 
    
      @@ -813,11 +815,13 @@ if [ -f "$varrunpath/booting" ]; then
 
     | 
  
  
    | 
      201
     | 
    
       	/bin/rm "$varrunpath/booting"
 
     | 
  
  
    | 
      202
     | 
    
       fi
 
     | 
  
  
    | 
      203
     | 
    
       
 
     | 
  
  
    | 
      204
     | 
    
      +unset ZPOOL
 
     | 
  
  
    | 
      205
     | 
    
       if [ -n "${USE_ZFS}" ]; then
     | 
  
  
    | 
      206
     | 
    
      +	errexit_off
 
     | 
  
  
    | 
      207
     | 
    
      +	ZPOOL="$(zfs_root_pool)"
 
     | 
  
  
    | 
      208
     | 
    
      +	errexit_on
 
     | 
  
  
    | 
      209
     | 
    
       	# Create ZFS reservation
 
     | 
  
  
    | 
      210
     | 
    
       	if [ ! -f /.no_zfs_reservation ]; then
 
     | 
  
  
    | 
      211
     | 
    
      -		zpool list -o name pfSense > /dev/null 2>&1 && ZPOOL=pfSense
 
     | 
  
  
    | 
      212
     | 
    
      -		zpool list -o name zroot > /dev/null 2>&1 && ZPOOL=zroot
 
     | 
  
  
    | 
      213
     | 
    
       		if [ -n "${ZPOOL}" ]; then
     | 
  
  
    | 
      214
     | 
    
       			errexit_off # This will always fail if the reservation isn't already present
 
     | 
  
  
    | 
      215
     | 
    
       			if ! zfs list -Hp -o name -t filesystem | grep -q "${ZPOOL}/reservation"; then
     | 
  
  
    | 
      216
     | 
    
      @@ -836,8 +840,6 @@ if [ -n "${USE_ZFS}" ]; then
     | 
  
  
    | 
      217
     | 
    
       
 
     | 
  
  
    | 
      218
     | 
    
       	# Enable zpool trimming
 
     | 
  
  
    | 
      219
     | 
    
       	if [ ! -f /.no_zpool_autotrim ]; then
 
     | 
  
  
    | 
      220
     | 
    
      -		/sbin/zpool list -o name pfSense > /dev/null 2>&1 && ZPOOL=pfSense
 
     | 
  
  
    | 
      221
     | 
    
      -		/sbin/zpool list -o name zroot > /dev/null 2>&1 && ZPOOL=zroot
 
     | 
  
  
    | 
      222
     | 
    
       		if [ -n "${ZPOOL}" ]; then
     | 
  
  
    | 
      223
     | 
    
       			errexit_off # Not all platforms support TRIM
 
     | 
  
  
    | 
      224
     | 
    
       			AUTOTRIM=$( /sbin/zpool get -H -o value autotrim "${ZPOOL}" )
     | 
  
  
    | 
      225
     | 
    
      @@ -851,10 +853,8 @@ if [ -n "${USE_ZFS}" ]; then
     | 
  
  
    | 
      226
     | 
    
       		fi
 
     | 
  
  
    | 
      227
     | 
    
       	fi
 
     | 
  
  
    | 
      228
     | 
    
       
 
     | 
  
  
    | 
      229
     | 
    
      -	# Make sure the config dataset is always synced
 
     | 
  
  
    | 
      230
     | 
    
      -	if [ "$(/sbin/zfs get -H -o value sync pfSense/ROOT/default/cf)" != "always" ]; then
 
     | 
  
  
    | 
      231
     | 
    
      -		zfs set sync=always pfSense/ROOT/default/cf
 
     | 
  
  
    | 
      232
     | 
    
      -	fi
 
     | 
  
  
    | 
      233
     | 
    
      +	# Make sure the config dataset is "always" synced for safety
 
     | 
  
  
    | 
      234
     | 
    
      +	zfs_set_prop "${ZFSROOT}/cf" sync always
     | 
  
  
    | 
      235
     | 
    
       fi
 
     | 
  
  
    | 
      236
     | 
    
       
 
     | 
  
  
    | 
      237
     | 
    
       errexit_off # Could already be running
 
     |