diff --git a/bin/sh/profile b/bin/sh/profile
index b77c8787c79d..5b8a57d4b7b2 100644
--- a/bin/sh/profile
+++ b/bin/sh/profile
@@ -1,14 +1,34 @@
 # $FreeBSD$
 #
 # System-wide .profile file for sh(1).
 #
 # For the setting of languages and character sets please see
 # login.conf(5) and in particular the charset and lang options.
 # For full locales list check /usr/share/locale/*
 # You should also read the setlocale(3) man page for information
 # on how to achieve more precise control of locale settings.
 #
 # Check system messages
 # msgs -q
 # Allow terminal messages
 # mesg y
+
+# Load each .sh file in /etc/profile.d/, then /usr/local/etc/profile,
+# then each .sh file in /usr/local/etc/profile.d/.
+_loaded=${_loaded:-/etc/profile}
+export _loaded
+for _dir in /etc /usr/local/etc ; do
+	for _file in "${_dir}"/profile "${_dir}"/profile.d/*.sh ; do
+		if [ -f "${_file}" ] ; then
+			case :${_loaded}: in
+			*:"${_file}":*)
+				;;
+			*)
+				_loaded="${_loaded:+${_loaded}:}${_file}"
+				. "${_file}"
+				;;
+			esac
+		fi
+	done
+done
+unset _loaded _dir _file
diff --git a/etc/mtree/BSD.root.dist b/etc/mtree/BSD.root.dist
index cba3e9e73c79..0c70b11eed4e 100644
--- a/etc/mtree/BSD.root.dist
+++ b/etc/mtree/BSD.root.dist
@@ -1,124 +1,126 @@
 # $FreeBSD$
 #
 # Please see the file src/etc/mtree/README before making changes to this file.
 #
 
 /set type=dir uname=root gname=wheel mode=0755
 .
     bin
     ..
     boot
         defaults
         ..
         dtb
             allwinner             tags=package=runtime
             ..
             overlays              tags=package=runtime
             ..
             rockchip              tags=package=runtime
             ..
         ..
         firmware
         ..
         loader.conf.d             tags=package=bootloader
         ..
         lua
         ..
         kernel
         ..
         modules
         ..
         zfs
         ..
     ..
     dev             mode=0555
     ..
     etc
         X11
         ..
         autofs
         ..
         bluetooth
         ..
         cron.d
         ..
         defaults
         ..
         devd
         ..
         dma
         ..
         gss
         ..
         mail
         ..
         mtree
         ..
         newsyslog.conf.d
         ..
         ntp             mode=0700
         ..
         pam.d
         ..
         periodic
             daily
             ..
             monthly
             ..
             security
             ..
             weekly
             ..
         ..
         pkg
         ..
         ppp
         ..
+        profile.d
+        ..
         rc.conf.d
         ..
         rc.d
         ..
         security
         ..
         ssh
         ..
         ssl
         ..
         syslog.d
         ..
         zfs
         ..
     ..
     lib
         casper
         ..
         geom
         ..
         nvmecontrol
         ..
     ..
     libexec
         resolvconf
         ..
     ..
     media
     ..
     mnt
     ..
     net
     ..
     proc            mode=0555
     ..
     rescue
     ..
     root
     ..
     sbin
     ..
     tmp             mode=01777
     ..
     usr
     ..
     var
     ..
 ..