Properly handle the replacement of a partially allocated root directory.
(cherry picked from commit f4fc3895243b9a8ae0577e731a3e450377071196)
(cherry picked from commit 2aa6ed881d22e4ed095d04ecb8a11f178274a644)
(cherry picked from commit 2567b60f62534bf5b243972f85b4921bba837439)
Sponsored by: The FreeBSD Foundation