diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index a34fdc8c9fd2ec00cb4367981c27927ebf7f2466..72d8af16b0b7b45dfa1db7836ebc6188a3dd3343 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -1591,10 +1591,16 @@ function install_profile_modules(&$install_state) {
   arsort($non_required);
 
   $batch_builder = new BatchBuilder();
-  foreach ($required + $non_required as $module => $weight) {
+  $module_groups = array_chunk($required + $non_required, Settings::get('core.multi-module-install', 20), TRUE);
+
+  foreach ($module_groups as $module_group) {
+    $names = [];
+    foreach ($module_group as $module => $weight) {
+      $names[] = $files[$module]->info['name'];
+    }
     $batch_builder->addOperation(
       '_install_module_batch',
-      [$module, $files[$module]->info['name']],
+      [array_keys($module_group), $names],
     );
   }
   $batch_builder
@@ -1896,9 +1902,10 @@ function install_finished(&$install_state) {
  * Performs batch installation of modules.
  */
 function _install_module_batch($module, $module_name, &$context) {
-  \Drupal::service('module_installer')->install([$module], FALSE);
-  $context['results'][] = $module;
-  $context['message'] = t('Installed %module module.', ['%module' => $module_name]);
+  $module = (array) $module;
+  \Drupal::service('module_installer')->install($module, FALSE);
+  $context['results'] = array_merge($context['results'], $module);
+  $context['message'] = t('Installed %module module(s).', ['%module' => implode(', ', $module_name)]);
 }
 
 /**
diff --git a/core/lib/Drupal/Component/DependencyInjection/Container.php b/core/lib/Drupal/Component/DependencyInjection/Container.php
index 104da1276d951da99bfdaa614c7a49c93e21f29f..3654d5fa5caaf17785c957e8ee60bd65f0f26d48 100644
--- a/core/lib/Drupal/Component/DependencyInjection/Container.php
+++ b/core/lib/Drupal/Component/DependencyInjection/Container.php
@@ -202,6 +202,8 @@ public function get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_IN
    */
   public function reset() {
     $this->services = [];
+    // Register the service_container with itself.
+    $this->services['service_container'] = $this;
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php
index 8331c1bc7c0400b523286b1fe30b40e3edfb0ab2..d9f69536d2a74c50abc955d4d8fcebdc60fd36fd 100644
--- a/core/lib/Drupal/Core/Config/ConfigImporter.php
+++ b/core/lib/Drupal/Core/Config/ConfigImporter.php
@@ -12,6 +12,7 @@
 use Drupal\Core\DependencyInjection\DependencySerializationTrait;
 use Drupal\Core\Entity\EntityStorageException;
 use Drupal\Core\Lock\LockBackendInterface;
+use Drupal\Core\Site\Settings;
 use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\Core\StringTranslation\TranslationInterface;
 use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
@@ -625,7 +626,10 @@ protected function processExtensions(&$context) {
     $operation = $this->getNextExtensionOperation();
     if (!empty($operation)) {
       $this->processExtension($operation['type'], $operation['op'], $operation['name']);
-      $context['message'] = t('Synchronizing extensions: @op @name.', ['@op' => $operation['op'], '@name' => $operation['name']]);
+      // @todo Improve this fix for
+      //   Drupal\Tests\config\Functional\ConfigImportAllTest.
+      $names = implode(', ', (array) $operation['name']);
+      $context['message'] = t('Synchronizing extensions: @op @name.', ['@op' => $operation['op'], '@name' => $names]);
       $processed_count = count($this->processedExtensions['module']['install']) + count($this->processedExtensions['module']['uninstall']);
       $processed_count += count($this->processedExtensions['theme']['uninstall']) + count($this->processedExtensions['theme']['install']);
       $context['finished'] = $processed_count / $this->totalExtensionsToProcess;
@@ -748,10 +752,16 @@ protected function getNextExtensionOperation() {
       foreach ($types as $type) {
         $unprocessed = $this->getUnprocessedExtensions($type);
         if (!empty($unprocessed[$op])) {
+          if ($type === 'module' && $op === 'install') {
+            $name = array_slice($unprocessed[$op], 0, Settings::get('core.multi-module-install', 20));
+          }
+          else {
+            $name = array_shift($unprocessed[$op]);
+          }
           return [
             'op' => $op,
             'type' => $type,
-            'name' => array_shift($unprocessed[$op]),
+            'name' => $name,
           ];
         }
       }
@@ -863,16 +873,17 @@ protected function processConfiguration($collection, $op, $name) {
    *   The type of extension, either 'module' or 'theme'.
    * @param string $op
    *   The change operation.
-   * @param string $name
-   *   The name of the extension to process.
+   * @param string|array $names
+   *   The name or names of the extension to process.
    */
-  protected function processExtension($type, $op, $name) {
+  protected function processExtension($type, $op, $names) {
+    $names = (array) $names;
     // Set the config installer to use the sync directory instead of the
     // extensions own default config directories.
     \Drupal::service('config.installer')
       ->setSourceStorage($this->storageComparer->getSourceStorage());
     if ($type == 'module') {
-      $this->moduleInstaller->$op([$name], FALSE);
+      $this->moduleInstaller->$op($names, FALSE);
       // Installing a module can cause a kernel boot therefore inject all the
       // services again.
       $this->reInjectMe();
@@ -891,10 +902,11 @@ protected function processExtension($type, $op, $name) {
         $this->configManager->getConfigFactory()->reset('system.theme');
         $this->processedSystemTheme = TRUE;
       }
-      \Drupal::service('theme_installer')->$op([$name]);
+      \Drupal::service('theme_installer')->$op($names);
+    }
+    foreach ($names as $name) {
+      $this->setProcessedExtension($type, $op, $name);
     }
-
-    $this->setProcessedExtension($type, $op, $name);
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php
index a7f4ce4dd4d1c43d847632ff7385bac75b1ce7fe..702cfb387c9f816d8c3a8cc93e11550f08e30639 100644
--- a/core/lib/Drupal/Core/Config/ConfigInstaller.php
+++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php
@@ -105,7 +105,7 @@ public function __construct(ConfigFactoryInterface $config_factory, StorageInter
   /**
    * {@inheritdoc}
    */
-  public function installDefaultConfig($type, $name) {
+  public function installDefaultConfig($type, $name, DefaultConfigMode $mode = DefaultConfigMode::All) {
     $extension_path = $this->extensionPathResolver->getPath($type, $name);
     // Refresh the schema cache if the extension provides configuration schema
     // or is a theme.
@@ -113,61 +113,75 @@ public function installDefaultConfig($type, $name) {
       $this->typedConfig->clearCachedDefinitions();
     }
 
-    $default_install_path = $this->getDefaultConfigDirectory($type, $name);
-    if (is_dir($default_install_path)) {
-      if (!$this->isSyncing()) {
-        $storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION);
-        $prefix = '';
-      }
-      else {
-        // The configuration importer sets the source storage on the config
-        // installer. The configuration importer handles all of the
-        // configuration entity imports. We only need to ensure that simple
-        // configuration is created when the extension is installed.
-        $storage = $this->getSourceStorage();
-        $prefix = $name . '.';
-      }
-
-      // Gets profile storages to search for overrides if necessary.
-      $profile_storages = $this->getProfileStorages($name);
+    if ($mode->createInstallConfig()) {
+      $default_install_path = $this->getDefaultConfigDirectory($type, $name);
+      if (is_dir($default_install_path)) {
+        if (!$this->isSyncing()) {
+          $storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION);
+          $prefix = '';
+        }
+        else {
+          // The configuration importer sets the source storage on the config
+          // installer. The configuration importer handles all of the
+          // configuration entity imports. We only need to ensure that simple
+          // configuration is created when the extension is installed.
+          $storage = $this->getSourceStorage();
+          $prefix = $name . '.';
+        }
 
-      // Gather information about all the supported collections.
-      $collection_info = $this->configManager->getConfigCollectionInfo();
-      foreach ($collection_info->getCollectionNames() as $collection) {
-        $config_to_create = $this->getConfigToCreate($storage, $collection, $prefix, $profile_storages);
-        if ($name == $this->drupalGetProfile()) {
-          // If we're installing a profile ensure simple configuration that
-          // already exists is excluded as it will have already been written.
-          // This means that if the configuration is changed by something else
-          // during the install it will not be overwritten again.
-          $existing_configuration = array_filter($this->getActiveStorages($collection)->listAll(), function ($config_name) {
-            return !$this->configManager->getEntityTypeIdByName($config_name);
-          });
-          $config_to_create = array_diff_key($config_to_create, array_flip($existing_configuration));
+        // Gets profile storages to search for overrides if necessary.
+        $profile_storages = $this->getProfileStorages($name);
+
+        // Gather information about all the supported collections.
+        $collection_info = $this->configManager->getConfigCollectionInfo();
+        foreach ($collection_info->getCollectionNames() as $collection) {
+          $config_to_create = $this->getConfigToCreate($storage, $collection, $prefix, $profile_storages);
+          if ($name == $this->drupalGetProfile()) {
+            // If we're installing a profile ensure simple configuration that
+            // already exists is excluded as it will have already been written.
+            // This means that if the configuration is changed by something else
+            // during the install it will not be overwritten again.
+            $existing_configuration = array_filter($this->getActiveStorages($collection)->listAll(), function ($config_name) {
+              return !$this->configManager->getEntityTypeIdByName($config_name);
+            });
+            $config_to_create = array_diff_key($config_to_create, array_flip($existing_configuration));
+          }
+          if (!empty($config_to_create)) {
+            $this->createConfiguration($collection, $config_to_create);
+          }
         }
-        if (!empty($config_to_create)) {
-          $this->createConfiguration($collection, $config_to_create);
+      }
+    }
+
+    if ($mode->createOptionalConfig()) {
+      // During a drupal installation optional configuration is installed at the
+      // end of the installation process. Once the install profile is installed
+      // optional configuration should be installed as usual.
+      // @see install_install_profile()
+      $profile_installed = in_array($this->drupalGetProfile(), $this->getEnabledExtensions(), TRUE);
+      if (!$this->isSyncing() && (!InstallerKernel::installationAttempted() || $profile_installed)) {
+        $optional_install_path = $extension_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
+        if (is_dir($optional_install_path)) {
+          // Install any optional config the module provides.
+          $storage = new FileStorage($optional_install_path, StorageInterface::DEFAULT_COLLECTION);
+          $this->installOptionalConfig($storage, '');
         }
       }
     }
 
-    // During a drupal installation optional configuration is installed at the
-    // end of the installation process. Once the install profile is installed
-    // optional configuration should be installed as usual.
-    // @see install_install_profile()
-    $profile_installed = in_array($this->drupalGetProfile(), $this->getEnabledExtensions(), TRUE);
-    if (!$this->isSyncing() && (!InstallerKernel::installationAttempted() || $profile_installed)) {
-      $optional_install_path = $extension_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
-      if (is_dir($optional_install_path)) {
-        // Install any optional config the module provides.
-        $storage = new FileStorage($optional_install_path, StorageInterface::DEFAULT_COLLECTION);
-        $this->installOptionalConfig($storage, '');
+    if ($mode->createSiteOptionalConfig()) {
+      // During a drupal installation optional configuration is installed at the
+      // end of the installation process. Once the install profile is installed
+      // optional configuration should be installed as usual.
+      // @see install_install_profile()
+      $profile_installed = in_array($this->drupalGetProfile(), $this->getEnabledExtensions(), TRUE);
+      if (!$this->isSyncing() && (!InstallerKernel::installationAttempted() || $profile_installed)) {
+        // Install any optional configuration entities whose dependencies can now
+        // be met. This searches all the installed modules config/optional
+        // directories.
+        $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE, $this->installProfile);
+        $this->installOptionalConfig($storage, [$type => $name]);
       }
-      // Install any optional configuration entities whose dependencies can now
-      // be met. This searches all the installed modules config/optional
-      // directories.
-      $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE, $this->installProfile);
-      $this->installOptionalConfig($storage, [$type => $name]);
     }
 
     // Reset all the static caches and list caches.
@@ -482,7 +496,7 @@ public function isSyncing() {
    *   Array of configuration object names that already exist keyed by
    *   collection.
    */
-  protected function findPreExistingConfiguration(StorageInterface $storage) {
+  protected function findPreExistingConfiguration(StorageInterface $storage, array $previous_config_names = []) {
     $existing_configuration = [];
     // Gather information about all the supported collections.
     $collection_info = $this->configManager->getConfigCollectionInfo();
@@ -491,7 +505,7 @@ protected function findPreExistingConfiguration(StorageInterface $storage) {
       $config_to_create = array_keys($this->getConfigToCreate($storage, $collection));
       $active_storage = $this->getActiveStorages($collection);
       foreach ($config_to_create as $config_name) {
-        if ($active_storage->exists($config_name)) {
+        if ($active_storage->exists($config_name) || array_search($config_name, $previous_config_names[$collection] ?? [], TRUE) !== FALSE) {
           $existing_configuration[$collection][] = $config_name;
         }
       }
@@ -508,35 +522,60 @@ public function checkConfigurationToInstall($type, $name) {
       // validation events.
       return;
     }
-    $config_install_path = $this->getDefaultConfigDirectory($type, $name);
-    if (!is_dir($config_install_path)) {
-      return;
-    }
+    $names = (array) $name;
+    $enabled_extensions = $this->getEnabledExtensions();
+    $previous_config_names = [];
 
-    $storage = new FileStorage($config_install_path, StorageInterface::DEFAULT_COLLECTION);
+    foreach ($names as $name) {
+      // Add the extension that will be enabled to the list of enabled extensions.
+      $enabled_extensions[] = $name;
 
-    $enabled_extensions = $this->getEnabledExtensions();
-    // Add the extension that will be enabled to the list of enabled extensions.
-    $enabled_extensions[] = $name;
-    // Gets profile storages to search for overrides if necessary.
-    $profile_storages = $this->getProfileStorages($name);
-
-    // Check the dependencies of configuration provided by the module.
-    [$invalid_default_config, $missing_dependencies] = $this->findDefaultConfigWithUnmetDependencies($storage, $enabled_extensions, $profile_storages);
-    if (!empty($invalid_default_config)) {
-      throw UnmetDependenciesException::create($name, array_unique($missing_dependencies, SORT_REGULAR));
-    }
+      $config_install_path = $this->getDefaultConfigDirectory($type, $name);
+      if (!is_dir($config_install_path)) {
+        continue;
+      }
+
+      // Store the config names for the checked module in order to add them to
+      // the list of active configuration for the next module.
+      if (isset($previous_storage)) {
+        foreach ($this->configManager->getConfigCollectionInfo()->getCollectionNames() as $collection) {
+          $config_to_create = array_keys($this->getConfigToCreate($previous_storage, $collection));
+          if (!isset($previous_config_names[$collection])) {
+            $previous_config_names[$collection] = $config_to_create;
+          }
+          else {
+            $previous_config_names[$collection] = array_merge($previous_config_names[$collection], $config_to_create);
+          }
+        }
+      }
 
-    // Install profiles can not have config clashes. Configuration that
-    // has the same name as a module's configuration will be used instead.
-    if ($name != $this->drupalGetProfile()) {
-      // Throw an exception if the module being installed contains configuration
-      // that already exists. Additionally, can not continue installing more
-      // modules because those may depend on the current module being installed.
-      $existing_configuration = $this->findPreExistingConfiguration($storage);
-      if (!empty($existing_configuration)) {
-        throw PreExistingConfigException::create($name, $existing_configuration);
+      $storage = new FileStorage($config_install_path, StorageInterface::DEFAULT_COLLECTION);
+
+      // Gets profile storages to search for overrides if necessary.
+      $profile_storages = $this->getProfileStorages($name);
+
+      // Check the dependencies of configuration provided by the module.
+      [
+        $invalid_default_config,
+        $missing_dependencies,
+      ] = $this->findDefaultConfigWithUnmetDependencies($storage, $enabled_extensions, $profile_storages, $previous_config_names);
+      if (!empty($invalid_default_config)) {
+        throw UnmetDependenciesException::create($name, array_unique($missing_dependencies, SORT_REGULAR));
       }
+
+      // Install profiles can not have config clashes. Configuration that
+      // has the same name as a module's configuration will be used instead.
+      if ($name != $this->drupalGetProfile()) {
+        // Throw an exception if the module being installed contains configuration
+        // that already exists. Additionally, can not continue installing more
+        // modules because those may depend on the current module being installed.
+        $existing_configuration = $this->findPreExistingConfiguration($storage, $previous_config_names);
+        if (!empty($existing_configuration)) {
+          throw PreExistingConfigException::create($name, $existing_configuration);
+        }
+      }
+
+      $previous_storage = $storage;
     }
   }
 
@@ -550,6 +589,8 @@ public function checkConfigurationToInstall($type, $name) {
    * @param \Drupal\Core\Config\StorageInterface[] $profile_storages
    *   An array of storage interfaces containing profile configuration to check
    *   for overrides.
+   * @param string[][] $previously_checked_config
+   *   A list of previously checked configuration. Keyed by collection name.
    *
    * @return array
    *   An array containing:
@@ -557,10 +598,10 @@ public function checkConfigurationToInstall($type, $name) {
    *     - An array that will be filled with the missing dependency names, keyed
    *       by the dependents' names.
    */
-  protected function findDefaultConfigWithUnmetDependencies(StorageInterface $storage, array $enabled_extensions, array $profile_storages = []) {
+  protected function findDefaultConfigWithUnmetDependencies(StorageInterface $storage, array $enabled_extensions, array $profile_storages = [], array $previously_checked_config = []) {
     $missing_dependencies = [];
     $config_to_create = $this->getConfigToCreate($storage, StorageInterface::DEFAULT_COLLECTION, '', $profile_storages);
-    $all_config = array_merge($this->configFactory->listAll(), array_keys($config_to_create));
+    $all_config = array_merge($this->configFactory->listAll(), array_keys($config_to_create), $previously_checked_config[StorageInterface::DEFAULT_COLLECTION] ?? []);
     foreach ($config_to_create as $config_name => $config) {
       if ($missing = $this->getMissingDependencies($config_name, $config, $enabled_extensions, $all_config)) {
         $missing_dependencies[$config_name] = $missing;
diff --git a/core/lib/Drupal/Core/Config/ConfigInstallerInterface.php b/core/lib/Drupal/Core/Config/ConfigInstallerInterface.php
index 72ae7e7fc879bc476864b3b66e7a317832a3f534..f15c874372128934d33d8c811def5e0c03097336 100644
--- a/core/lib/Drupal/Core/Config/ConfigInstallerInterface.php
+++ b/core/lib/Drupal/Core/Config/ConfigInstallerInterface.php
@@ -27,10 +27,14 @@ interface ConfigInstallerInterface {
    *   The extension type; e.g., 'module' or 'theme'.
    * @param string $name
    *   The name of the module or theme to install default configuration for.
+   * @param \Drupal\Core\Config\DefaultConfigMode $mode
+   *   The default value DefaultConfigMode::All means create install, optional
+   *   and site optional configuration. The other modes create a single type
+   *   config.
    *
    * @see \Drupal\Core\Config\ExtensionInstallStorage
    */
-  public function installDefaultConfig($type, $name);
+  public function installDefaultConfig($type, $name, DefaultConfigMode $mode = DefaultConfigMode::All);
 
   /**
    * Installs optional configuration.
@@ -108,8 +112,8 @@ public function isSyncing();
    *
    * @param string $type
    *   Type of extension to install.
-   * @param string $name
-   *   Name of extension to install.
+   * @param string|array $name
+   *   Name or names of extensions to install.
    *
    * @throws \Drupal\Core\Config\UnmetDependenciesException
    * @throws \Drupal\Core\Config\PreExistingConfigException
diff --git a/core/lib/Drupal/Core/Config/DefaultConfigMode.php b/core/lib/Drupal/Core/Config/DefaultConfigMode.php
new file mode 100644
index 0000000000000000000000000000000000000000..8a09c34665e4fe76fdee90b3ffbc5fd3326f26ed
--- /dev/null
+++ b/core/lib/Drupal/Core/Config/DefaultConfigMode.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Drupal\Core\Config;
+
+/**
+ * Provides modes for ConfigInstallerInterface::installDefaultConfig().
+ *
+ * @see \Drupal\Core\Config\ConfigInstallerInterface::installDefaultConfig()
+ */
+enum DefaultConfigMode {
+  case All;
+  case Install;
+  case Optional;
+  case SiteOptional;
+
+  /**
+   * Determines if config in /install directory should be created.
+   *
+   * @return bool
+   *   TRUE to create config in /install directory, FALSE if not.
+   */
+  public function createInstallConfig(): bool {
+    return match($this) {
+      DefaultConfigMode::All, DefaultConfigMode::Install => TRUE,
+      DefaultConfigMode::Optional, DefaultConfigMode::SiteOptional => FALSE,
+    };
+  }
+
+  /**
+   * Determines if config in /optional directory should be created.
+   *
+   * @return bool
+   *   TRUE to create config in /optional directory, FALSE if not.
+   */
+  public function createOptionalConfig(): bool {
+    return match($this) {
+      DefaultConfigMode::All, DefaultConfigMode::Optional => TRUE,
+      DefaultConfigMode::Install, DefaultConfigMode::SiteOptional => FALSE,
+    };
+  }
+
+  /**
+   * Determines if optional config in other installed modules should be created.
+   *
+   * @return bool
+   *   TRUE to create optional config in other installed modules,
+   *   FALSE if not.
+   */
+  public function createSiteOptionalConfig(): bool {
+    return match($this) {
+      DefaultConfigMode::All, DefaultConfigMode::SiteOptional => TRUE,
+      DefaultConfigMode::Install, DefaultConfigMode::Optional => FALSE,
+    };
+  }
+
+}
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 6c1a8e1bbaa40478c24cbfcdcc6aa0c09e8eee73..ec4db26d196c1f4c310c2b30b1827bcfe7ce4cba 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -1205,6 +1205,71 @@ public function rebuildContainer() {
     return $this->initializeContainer();
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function resetContainer(): ContainerInterface {
+    $session_started = FALSE;
+    // Save the id of the currently logged in user.
+    if ($this->container->initialized('current_user')) {
+      $current_user_id = $this->container->get('current_user')->id();
+    }
+    // After rebuilding the container some objects will have stale services.
+    // Record a map of objects to service IDs prior to rebuilding the
+    // container in order to ensure
+    // \Drupal\Core\DependencyInjection\DependencySerializationTrait works as
+    // expected.
+    $this->container->get(ReverseContainer::class)->recordContainer();
+
+    // If there is a session, close and save it.
+    if ($this->container->initialized('session')) {
+      $session = $this->container->get('session');
+      if ($session->isStarted()) {
+        $session_started = TRUE;
+        $session->save();
+      }
+      unset($session);
+    }
+
+    $all_messages = $this->container->get('messenger')->all();
+
+    $persist = $this->getServicesToPersist($this->container);
+    $this->container->reset();
+    $this->persistServices($this->container, $persist);
+
+    $this->container->set('kernel', $this);
+
+    // Set the class loader which was registered as a synthetic service.
+    $this->container->set('class_loader', $this->classLoader);
+
+    if ($session_started) {
+      $this->container->get('session')->start();
+    }
+
+    // The request stack is preserved across container rebuilds. Re-inject the
+    // new session into the main request if one was present before.
+    if (($request_stack = $this->container->get('request_stack', ContainerInterface::NULL_ON_INVALID_REFERENCE))) {
+      if ($request = $request_stack->getMainRequest()) {
+        if ($request->hasSession()) {
+          $request->setSession($this->container->get('session'));
+        }
+      }
+    }
+
+    if (!empty($current_user_id)) {
+      $this->container->get('current_user')->setInitialAccountId($current_user_id);
+    }
+
+    // Re-add messages.
+    foreach ($all_messages as $type => $messages) {
+      foreach ($messages as $message) {
+        $this->container->get('messenger')->addMessage($message, $type);
+      }
+    }
+
+    return $this->container;
+  }
+
   /**
    * {@inheritdoc}
    */
diff --git a/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php
index f42e8eec6fb3fc88b11d9e7269737d0e56dd15b6..58f2191819e1462271acc227d81e98fa2505942c 100644
--- a/core/lib/Drupal/Core/DrupalKernelInterface.php
+++ b/core/lib/Drupal/Core/DrupalKernelInterface.php
@@ -3,6 +3,7 @@
 namespace Drupal\Core;
 
 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpKernel\HttpKernelInterface;
 use Symfony\Component\HttpFoundation\Request;
 
@@ -121,6 +122,13 @@ public function updateModules(array $module_list, array $module_filenames = []);
    */
   public function rebuildContainer();
 
+  /**
+   * Force a container reset.
+   *
+   * @return \Symfony\Component\DependencyInjection\ContainerInterface
+   */
+  public function resetContainer(): ContainerInterface;
+
   /**
    * Invalidate the service container for the next request.
    */
diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
index 289ecffe41fbaf3d3884851ee6050985775e1005..6c978aa5d71141b77c9fd97fae07a59218e7d8cc 100644
--- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php
+++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Config\DefaultConfigMode;
 use Drupal\Core\Database\Connection;
 use Drupal\Core\DrupalKernelInterface;
 use Drupal\Core\Entity\EntityStorageException;
@@ -173,6 +174,13 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
       $module_list = array_keys($module_list);
     }
 
+    // Remove any modules that are already installed.
+    $module_list = array_diff($module_list, array_keys($extension_config->get('module')));
+
+    if (empty($module_list)) {
+      return TRUE;
+    }
+
     // Required for module installation checks.
     include_once $this->root . '/core/includes/install.inc';
 
@@ -181,205 +189,262 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
     $sync_status = $config_installer->isSyncing();
     $modules_installed = [];
     foreach ($module_list as $module) {
-      $enabled = $extension_config->get("module.$module") !== NULL;
-      if (!$enabled) {
-        // Throw an exception if the module name is too long.
-        if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) {
-          throw new ExtensionNameLengthException("Module name '$module' is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters');
-        }
+      // Throw an exception if the module name is too long.
+      if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) {
+        throw new ExtensionNameLengthException("Module name '$module' is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters');
+      }
 
-        // Throw an exception if a theme with the same name is enabled.
-        $installed_themes = $extension_config->get('theme') ?: [];
-        if (isset($installed_themes[$module])) {
-          throw new ExtensionNameReservedException("Module name $module is already in use by an installed theme.");
-        }
+      // Throw an exception if a theme with the same name is enabled.
+      $installed_themes = $extension_config->get('theme') ?: [];
+      if (isset($installed_themes[$module])) {
+        throw new ExtensionNameReservedException("Module name $module is already in use by an installed theme.");
+      }
+    }
 
-        // Load a new config object for each iteration, otherwise changes made
-        // in hook_install() are not reflected in $extension_config.
-        $extension_config = \Drupal::configFactory()->getEditable('core.extension');
-
-        // Check the validity of the default configuration. This will throw
-        // exceptions if the configuration is not valid.
-        $config_installer->checkConfigurationToInstall('module', $module);
-
-        // Save this data without checking schema. This is a performance
-        // improvement for module installation.
-        $extension_config
-          ->set("module.$module", 0)
-          ->set('module', module_config_sort($extension_config->get('module')))
-          ->save(TRUE);
-
-        // Prepare the new module list, sorted by weight, including filenames.
-        // This list is used for both the ModuleHandler and DrupalKernel. It
-        // needs to be kept in sync between both. A DrupalKernel reboot or
-        // rebuild will automatically re-instantiate a new ModuleHandler that
-        // uses the new module list of the kernel. However, DrupalKernel does
-        // not cause any modules to be loaded.
-        // Furthermore, the currently active (fixed) module list can be
-        // different from the configured list of enabled modules. For all active
-        // modules not contained in the configured enabled modules, we assume a
-        // weight of 0.
-        $current_module_filenames = $this->moduleHandler->getModuleList();
-        $current_modules = array_fill_keys(array_keys($current_module_filenames), 0);
-        $current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module')));
-        $module_filenames = [];
-        foreach ($current_modules as $name => $weight) {
-          if (isset($current_module_filenames[$name])) {
-            $module_filenames[$name] = $current_module_filenames[$name];
-          }
-          else {
-            $module_path = \Drupal::service('extension.list.module')->getPath($name);
-            $pathname = "$module_path/$name.info.yml";
-            $filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL;
-            $module_filenames[$name] = new Extension($this->root, 'module', $pathname, $filename);
-          }
-        }
+    // Check the validity of the default configuration. This will throw
+    // exceptions if the configuration is not valid.
+    $config_installer->checkConfigurationToInstall('module', $module_list);
+
+    // Save this data without checking schema. This is a performance
+    // improvement for module installation.
+    $extension_config
+      ->set('module', module_config_sort(array_merge(
+        array_fill_keys($module_list, 0),
+        $extension_config->get('module')
+      )))
+      ->save(TRUE);
+
+    // Prepare the new module list, sorted by weight, including filenames.
+    // This list is used for both the ModuleHandler and DrupalKernel. It
+    // needs to be kept in sync between both. A DrupalKernel reboot or
+    // rebuild will automatically re-instantiate a new ModuleHandler that
+    // uses the new module list of the kernel. However, DrupalKernel does
+    // not cause any modules to be loaded.
+    // Furthermore, the currently active (fixed) module list can be
+    // different from the configured list of enabled modules. For all active
+    // modules not contained in the configured enabled modules, we assume a
+    // weight of 0.
+    $current_module_filenames = $this->moduleHandler->getModuleList();
+    $current_modules = array_fill_keys(array_keys($current_module_filenames), 0);
+    $current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module')));
+    $module_filenames = [];
+    foreach ($current_modules as $name => $weight) {
+      if (isset($current_module_filenames[$name])) {
+        $module_filenames[$name] = $current_module_filenames[$name];
+      }
+      else {
+        $module_path = \Drupal::service('extension.list.module')
+          ->getPath($name);
+        $pathname = "$module_path/$name.info.yml";
+        $filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL;
+        $module_filenames[$name] = new Extension($this->root, 'module', $pathname, $filename);
+      }
+    }
 
-        // Update the module handler in order to have the correct module list
-        // for the kernel update.
-        $this->moduleHandler->setModuleList($module_filenames);
-
-        // Clear the static cache of the "extension.list.module" service to pick
-        // up the new module, since it merges the installation status of modules
-        // into its statically cached list.
-        \Drupal::service('extension.list.module')->reset();
-
-        // Update the kernel to include it.
-        $this->updateKernel($module_filenames);
-
-        // Load the module's .module and .install files.
-        $this->moduleHandler->load($module);
-        $this->moduleHandler->loadInclude($module, 'install');
-
-        if (!InstallerKernel::installationAttempted()) {
-          // Replace the route provider service with a version that will rebuild
-          // if routes used during installation. This ensures that a module's
-          // routes are available during installation. This has to occur before
-          // any services that depend on it are instantiated otherwise those
-          // services will have the old route provider injected. Note that, since
-          // the container is rebuilt by updating the kernel, the route provider
-          // service is the regular one even though we are in a loop and might
-          // have replaced it before.
-          \Drupal::getContainer()->set('router.route_provider.old', \Drupal::service('router.route_provider'));
-          \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder'));
-        }
+    // Update the module handler in order to have the correct module list
+    // for the kernel update.
+    $this->moduleHandler->setModuleList($module_filenames);
+
+    // Clear the static cache of the "extension.list.module" service to pick
+    // up the new module, since it merges the installation status of modules
+    // into its statically cached list.
+    \Drupal::service('extension.list.module')->reset();
+
+    // Update the kernel to include it.
+    $this->updateKernel($module_filenames);
+
+    if (!InstallerKernel::installationAttempted()) {
+      // Replace the route provider service with a version that will rebuild
+      // if routes used during installation. This ensures that a module's
+      // routes are available during installation. This has to occur before
+      // any services that depend on it are instantiated otherwise those
+      // services will have the old route provider injected. Note that, since
+      // the container is rebuilt by updating the kernel, the route provider
+      // service is the regular one even though we are in a loop and might
+      // have replaced it before.
+      \Drupal::getContainer()->set('router.route_provider.old', \Drupal::service('router.route_provider'));
+      \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder'));
+    }
 
-        // Allow modules to react prior to the installation of a module.
-        $this->moduleHandler->invokeAll('module_preinstall', [$module, $sync_status]);
+    foreach ($module_list as $module) {
+      // Load the module's .module and .install files. Do this for all modules
+      // prior to calling hook_module_preinstall() in order to not pollute the
+      // cache.
+      $this->moduleHandler->load($module);
+      $this->moduleHandler->loadInclude($module, 'install');
+    }
 
-        // Now install the module's schema if necessary.
-        $this->installSchema($module);
+    foreach ($module_list as $module) {
+      // Allow modules to react prior to the installation of a module.
+      $this->moduleHandler->invokeAll('module_preinstall', [$module, $sync_status]);
 
-        // Clear plugin manager caches.
-        \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
+      // Now install the module's schema if necessary.
+      $this->installSchema($module);
+    }
 
-        // Set the schema version to the number of the last update provided by
-        // the module, or the minimum core schema version.
-        $version = \Drupal::CORE_MINIMUM_SCHEMA_VERSION;
-        $versions = $this->updateRegistry->getAvailableUpdates($module);
-        if ($versions) {
-          $version = max(max($versions), $version);
-        }
+    // Clear plugin manager caches.
+    // @todo should this be in the loop?
+    \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
 
-        // Notify interested components that this module's entity types and
-        // field storage definitions are new. For example, a SQL-based storage
-        // handler can use this as an opportunity to create the necessary
-        // database tables.
-        // @todo Clean this up in https://www.drupal.org/node/2350111.
-        $entity_type_manager = \Drupal::entityTypeManager();
-        $update_manager = \Drupal::entityDefinitionUpdateManager();
-        /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
-        $entity_field_manager = \Drupal::service('entity_field.manager');
-        foreach ($entity_type_manager->getDefinitions() as $entity_type) {
-          $is_fieldable_entity_type = $entity_type->entityClassImplements(FieldableEntityInterface::class);
-
-          if ($entity_type->getProvider() == $module) {
-            if ($is_fieldable_entity_type) {
-              $update_manager->installFieldableEntityType($entity_type, $entity_field_manager->getFieldStorageDefinitions($entity_type->id()));
-            }
-            else {
-              $update_manager->installEntityType($entity_type);
-            }
+    foreach ($module_list as $module) {
+      // Set the schema version to the number of the last update provided by
+      // the module, or the minimum core schema version.
+      $version = \Drupal::CORE_MINIMUM_SCHEMA_VERSION;
+      $versions = $this->updateRegistry->getAvailableUpdates($module);
+      if ($versions) {
+        $version = max(max($versions), $version);
+      }
+
+      // Notify interested components that this module's entity types and
+      // field storage definitions are new. For example, a SQL-based storage
+      // handler can use this as an opportunity to create the necessary
+      // database tables.
+      // @todo Clean this up in https://www.drupal.org/node/2350111.
+      $entity_type_manager = \Drupal::entityTypeManager();
+      $update_manager = \Drupal::entityDefinitionUpdateManager();
+      /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
+      $entity_field_manager = \Drupal::service('entity_field.manager');
+      foreach ($entity_type_manager->getDefinitions() as $entity_type) {
+        $is_fieldable_entity_type = $entity_type->entityClassImplements(FieldableEntityInterface::class);
+
+        if ($entity_type->getProvider() == $module) {
+          if ($is_fieldable_entity_type) {
+            $update_manager->installFieldableEntityType($entity_type, $entity_field_manager->getFieldStorageDefinitions($entity_type->id()));
+          }
+          else {
+            $update_manager->installEntityType($entity_type);
           }
-          elseif ($is_fieldable_entity_type) {
-            // The module being installed may be adding new fields to existing
-            // entity types. Field definitions for any entity type defined by
-            // the module are handled in the if branch.
-            foreach ($entity_field_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) {
-              if ($storage_definition->getProvider() == $module) {
-                // If the module being installed is also defining a storage key
-                // for the entity type, the entity schema may not exist yet. It
-                // will be created later in that case.
-                try {
-                  $update_manager->installFieldStorageDefinition($storage_definition->getName(), $entity_type->id(), $module, $storage_definition);
-                }
-                catch (EntityStorageException $e) {
-                  Error::logException($this->logger, $e, 'An error occurred while notifying the creation of the @name field storage definition: "@message" in %function (line %line of %file).', ['@name' => $storage_definition->getName()]);
-                }
+        }
+        elseif ($is_fieldable_entity_type) {
+          // The module being installed may be adding new fields to existing
+          // entity types. Field definitions for any entity type defined by
+          // the module are handled in the if branch.
+          foreach ($entity_field_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) {
+            if ($storage_definition->getProvider() == $module) {
+              // If the module being installed is also defining a storage key
+              // for the entity type, the entity schema may not exist yet. It
+              // will be created later in that case.
+              try {
+                $update_manager->installFieldStorageDefinition($storage_definition->getName(), $entity_type->id(), $module, $storage_definition);
+              }
+              catch (EntityStorageException $e) {
+                Error::logException($this->logger, $e, 'An error occurred while notifying the creation of the @name field storage definition: "@message" in %function (line %line of %file).', ['@name' => $storage_definition->getName()]);
               }
             }
           }
         }
+      }
 
-        // Install default configuration of the module.
-        $config_installer = \Drupal::service('config.installer');
-        $config_installer->installDefaultConfig('module', $module);
+      // Install default configuration of the module.
+      $config_installer = \Drupal::service('config.installer');
+      $config_installer->installDefaultConfig('module', $module, DefaultConfigMode::Install);
 
-        // If the module has no current updates, but has some that were
-        // previously removed, set the version to the value of
-        // hook_update_last_removed().
-        if ($last_removed = $this->moduleHandler->invoke($module, 'update_last_removed')) {
-          $version = max($version, $last_removed);
-        }
-        $this->updateRegistry->setInstalledVersion($module, $version);
+      // If the module has no current updates, but has some that were
+      // previously removed, set the version to the value of
+      // hook_update_last_removed().
+      if ($last_removed = $this->moduleHandler->invoke($module, 'update_last_removed')) {
+        $version = max($version, $last_removed);
+      }
+      $this->updateRegistry->setInstalledVersion($module, $version);
 
-        // Record the fact that it was installed.
-        $modules_installed[] = $module;
+      // Record the fact that it was installed.
+      $modules_installed[] = $module;
 
-        // Drupal's stream wrappers needs to be re-registered in case a
-        // module-provided stream wrapper is used later in the same request. In
-        // particular, this happens when installing Drupal via Drush, as the
-        // 'translations' stream wrapper is provided by Interface Translation
-        // module and is later used to import translations.
-        \Drupal::service('stream_wrapper_manager')->register();
+      // Drupal's stream wrappers needs to be re-registered in case a
+      // module-provided stream wrapper is used later in the same request. In
+      // particular, this happens when installing Drupal via Drush, as the
+      // 'translations' stream wrapper is provided by Interface Translation
+      // module and is later used to import translations.
+      \Drupal::service('stream_wrapper_manager')->register();
+
+      // Update the theme registry to include it.
+      \Drupal::service('theme.registry')->reset();
+
+      // Modules can alter theme info, so refresh theme data.
+      // @todo ThemeHandler cannot be injected into ModuleHandler, since that
+      //   causes a circular service dependency.
+      // @see https://www.drupal.org/node/2208429
+      \Drupal::service('theme_handler')->refreshInfo();
 
-        // Update the theme registry to include it.
-        \Drupal::service('theme.registry')->reset();
+      // Allow the module to perform install tasks.
+      $this->moduleHandler->invoke($module, 'install', [$sync_status]);
 
-        // Modules can alter theme info, so refresh theme data.
-        // @todo ThemeHandler cannot be injected into ModuleHandler, since that
-        //   causes a circular service dependency.
-        // @see https://www.drupal.org/node/2208429
-        \Drupal::service('theme_handler')->refreshInfo();
+      // Record the fact that it was installed.
+      \Drupal::logger('system')->info('%module module installed.', ['%module' => $module]);
+    }
 
-        // Allow the module to perform install tasks.
-        $this->moduleHandler->invoke($module, 'install', [$sync_status]);
+    // Install optional configuration from modules once all the modules have
+    // been properly installed. This is often where soft dependencies lie.
+    // @todo This code fixes \Drupal\Tests\help\Functional\HelpTest::testHelp().
+    $config_installer = \Drupal::service('config.installer');
+    foreach ($module_list as $module) {
+      $config_installer->installDefaultConfig('module', $module, DefaultConfigMode::Optional);
+    }
+    // Install optional configuration from other modules once all the modules
+    // have been properly installed. This is often where soft dependencies lie.
+    // @todo This code fixes
+    //   \Drupal\Tests\forum\Functional\Module\DependencyTest::testUninstallDependents().
+    foreach ($module_list as $module) {
+      $config_installer->installDefaultConfig('module', $module, DefaultConfigMode::SiteOptional);
+    }
 
-        // Record the fact that it was installed.
-        \Drupal::logger('system')->info('%module module installed.', ['%module' => $module]);
-      }
+    if (count($module_list) > 1) {
+      // Reset the container so static caches are rebuilt. This prevents static
+      // caches like those in \Drupal\views\ViewsData() from having stale data.
+      // @todo Adding this code fixed
+      //   \Drupal\KernelTests\Config\DefaultConfigTest::testModuleConfig().
+      //   \Drupal\Component\DependencyInjection\Container::reset() seems to
+      //   offer a way to do this but was broken for the following reasons:
+      //   1. Needs to set itself to 'service_container' like the constructor.
+      //   2. Needs to persist services, user and session like
+      //      DrupalKernel::initializeContainer()
+      //   3. Needs to work out how to work with things like
+      //      KernelTestBase::register() which set synthetic like services.
+      $this->updateKernel([]);
+
+      // Refresh anything cached with core.extension. This prevents caches in
+      // things like \Drupal\views\ViewsData() from having stale data.
+      // @todo This fixes \Drupal\Tests\views\Functional\ViewsFormAlterTest().
+      Cache::invalidateTags(['config:core.extension']);
+
+      // Rebuilding the container above means the loaded flag is not properly
+      // set.
+      // @todo consider replacing the loaded flag with something determined from
+      //   the keys in ModuleHandler. This fixes
+      //   \Drupal\Tests\search\Functional\SearchAdvancedSearchFormTest::testNodeType().
+      //   Note, previously this flag is set due to calling hook_install() and
+      //   rebuilding all the module handler statics above.
+      $this->moduleHandler->loadAll();
+
+      // Record the fact that it was multi-installed.
+      // @todo this feels for testing purposes only. Maybe remove later.
+      \Drupal::logger('system')->info('%modules installed with a single container rebuild.', ['%modules' => implode(', ', $module_list)]);
     }
 
-    // If any modules were newly installed, invoke hook_modules_installed().
-    if (!empty($modules_installed)) {
-      if (!InstallerKernel::installationAttempted()) {
-        // If the container was rebuilt during hook_install() it might not have
-        // the 'router.route_provider.old' service.
-        if (\Drupal::hasService('router.route_provider.old')) {
-          \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.old'));
-        }
-        if (!\Drupal::service('router.route_provider.lazy_builder')->hasRebuilt()) {
-          // Rebuild routes after installing module. This is done here on top of
-          // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on
-          // fastCGI which executes ::destruct() after the module installation
-          // page was sent already.
-          \Drupal::service('router.builder')->rebuild();
-        }
+    if (!InstallerKernel::installationAttempted()) {
+      // If the container was rebuilt during hook_install() it might not have
+      // the 'router.route_provider.old' service.
+      if (\Drupal::hasService('router.route_provider.old')) {
+        \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.old'));
+      }
+      if (!\Drupal::service('router.route_provider.lazy_builder')->hasRebuilt()) {
+        // Rebuild routes after installing module. This is done here on top of
+        // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on
+        // fastCGI which executes ::destruct() after the module installation
+        // page was sent already.
+        \Drupal::service('router.builder')->rebuild();
+      }
+      else {
+        // Rebuild the router immediately if it is marked as needing a rebuild.
+        // @todo Work this through a bit more. This fixes
+        //   \Drupal\Tests\standard\Functional\StandardTest::testStandard()
+        //   after separately out the optional configuration install.
+        \Drupal::service('router.builder')->rebuildIfNeeded();
       }
-
-      $this->moduleHandler->invokeAll('modules_installed', [$modules_installed, $sync_status]);
     }
 
+    $this->moduleHandler->invokeAll('modules_installed', [$modules_installed, $sync_status]);
+
     return TRUE;
   }
 
@@ -607,14 +672,20 @@ protected function updateKernel($module_filenames) {
     $sync_status = $config_installer->isSyncing();
     $source_storage = $config_installer->getSourceStorage();
 
-    // This reboots the kernel to register the module's bundle and its services
-    // in the service container. The $module_filenames argument is taken over as
-    // %container.modules% parameter, which is passed to a fresh ModuleHandler
-    // instance upon first retrieval.
-    $this->kernel->updateModules($module_filenames, $module_filenames);
+    if (!empty($module_filenames)) {
+      // This reboots the kernel to register the module's bundle and its services
+      // in the service container. The $module_filenames argument is taken over as
+      // %container.modules% parameter, which is passed to a fresh ModuleHandler
+      // instance upon first retrieval.
+      $this->kernel->updateModules($module_filenames, $module_filenames);
+      $container = $this->kernel->getContainer();
+    }
+    else {
+      $container = $this->kernel->resetContainer();
+    }
+
     // After rebuilding the container we need to update the injected
     // dependencies.
-    $container = $this->kernel->getContainer();
     $this->moduleHandler = $container->get('module_handler');
     $this->connection = $container->get('database');
     $this->updateRegistry = $container->get('update.update_hook_registry');
diff --git a/core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php b/core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php
index 76ce0ecb1278d01fec3f132d8ab2f6ca9008390e..0497e112866e31f2b24d83be450d73150dfb07e8 100644
--- a/core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php
+++ b/core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php
@@ -70,9 +70,9 @@ protected function lazyLoadItself()
         /**
          * {@inheritdoc}
          */
-        public function installDefaultConfig($type, $name)
+        public function installDefaultConfig($type, $name, \Drupal\Core\Config\DefaultConfigMode $mode = \Drupal\Core\Config\DefaultConfigMode::All)
         {
-            return $this->lazyLoadItself()->installDefaultConfig($type, $name);
+            return $this->lazyLoadItself()->installDefaultConfig($type, $name, $mode);
         }
 
         /**
diff --git a/core/modules/config/tests/config_import_test/config_import_test.module b/core/modules/config/tests/config_import_test/config_import_test.module
index e883045a429991d1440598fcd072835d0d5bee73..b9afd8caebb859dc6d301d4fe959ca197c6b2cff 100644
--- a/core/modules/config/tests/config_import_test/config_import_test.module
+++ b/core/modules/config/tests/config_import_test/config_import_test.module
@@ -30,3 +30,10 @@ function _config_import_test_config_import_steps_alter(&$context, ConfigImporter
   }
   $context['finished'] = 1;
 }
+
+/**
+ * Implements hook_modules_installed().
+ */
+function config_import_test_modules_installed($modules, $is_syncing) {
+  \Drupal::state()->set('config_import_test_modules_installed.list', $modules);
+}
diff --git a/core/modules/config/tests/config_import_test/src/EventSubscriber.php b/core/modules/config/tests/config_import_test/src/EventSubscriber.php
index 4da76d83df698c80f958ce1b5e69e738fc161039..71f86a58763ef06f7404b76306aeb2cc03329111 100644
--- a/core/modules/config/tests/config_import_test/src/EventSubscriber.php
+++ b/core/modules/config/tests/config_import_test/src/EventSubscriber.php
@@ -101,7 +101,7 @@ public function onConfigSave(ConfigCrudEvent $event) {
       $data = $config->get('module');
       $install = array_diff_key($data, $original);
       if (!empty($install)) {
-        $installed[] = key($install);
+        $installed = array_merge($installed, $install);
       }
       $uninstall = array_diff_key($original, $data);
       if (!empty($uninstall)) {
diff --git a/core/modules/config/tests/src/Functional/ConfigImportUITest.php b/core/modules/config/tests/src/Functional/ConfigImportUITest.php
index d12ae23816f5f1ccf53d588ae0f4aa4b94016b3d..2f95984c2f6a4c5117734f57b3317c7dbfc05633 100644
--- a/core/modules/config/tests/src/Functional/ConfigImportUITest.php
+++ b/core/modules/config/tests/src/Functional/ConfigImportUITest.php
@@ -163,9 +163,9 @@ public function testImport() {
     $this->assertTrue(\Drupal::service('theme_handler')->themeExists('olivero'), 'Olivero theme installed during import.');
 
     // Ensure installations and uninstallation occur as expected.
-    $installed = \Drupal::state()->get('ConfigImportUITest.core.extension.modules_installed', []);
     $uninstalled = \Drupal::state()->get('ConfigImportUITest.core.extension.modules_uninstalled', []);
     $expected = ['automated_cron', 'ban', 'text', 'options'];
+    $installed = \Drupal::state()->get('config_import_test_modules_installed.list');
     $this->assertSame($expected, $installed, 'Automated Cron, Ban, Text and Options modules installed in the correct order.');
     $this->assertEmpty($uninstalled, 'No modules uninstalled during import');
 
diff --git a/core/modules/config/tests/src/Functional/ConfigInstallWebTest.php b/core/modules/config/tests/src/Functional/ConfigInstallWebTest.php
index f38016541895a1be3ab5818dcdaeaecb7ab29afd..061775ba71507bd4e0b33e9d40ea584f37083df6 100644
--- a/core/modules/config/tests/src/Functional/ConfigInstallWebTest.php
+++ b/core/modules/config/tests/src/Functional/ConfigInstallWebTest.php
@@ -145,13 +145,11 @@ public function testPreExistingConfigInstall() {
       'modules[config_test][enable]' => TRUE,
       'modules[config_install_fail_test][enable]' => TRUE,
     ], 'Install');
+    // @todo improve error message as the config does not exist. But both modules
+    //   being install have the same configuration object and therefore we
+    //   cannot install both together.
     $this->assertSession()->responseContains('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default</em> already exists in active configuration.');
 
-    // Uninstall the config_test module to test the confirm form.
-    $this->drupalGet('admin/modules/uninstall');
-    $this->submitForm(['uninstall[config_test]' => TRUE], 'Uninstall');
-    $this->submitForm([], 'Uninstall');
-
     // Try to install config_install_fail_test without selecting config_test.
     // The user is shown a confirm form because the config_test module is a
     // dependency.
@@ -159,8 +157,19 @@ public function testPreExistingConfigInstall() {
     $this->drupalGet('admin/modules');
     $this->submitForm(['modules[config_install_fail_test][enable]' => TRUE], 'Install');
     $this->submitForm([], 'Continue');
+    // @todo improve error message as the config does not exist. But both modules
+    //   being install have the same configuration object and therefore we
+    //   cannot install both together.
     $this->assertSession()->responseContains('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default</em> already exists in active configuration.');
 
+    // Install the config test module so that the configuration does actually
+    // exist.
+    $this->drupalGet('admin/modules');
+    $this->submitForm([
+      'modules[config_test][enable]' => TRUE,
+    ], 'Install');
+    $this->assertSession()->responseContains('Module <em class="placeholder">Configuration test</em> has been installed.');
+
     // Test that collection configuration clashes during a module install are
     // reported correctly.
     \Drupal::service('module_installer')->install(['language']);
diff --git a/core/modules/content_translation/content_translation.info.yml b/core/modules/content_translation/content_translation.info.yml
index cc260aa9e3af3dc466e4e69fbc3c4f325b34a8d0..c0fbee06df07036b4ea0bd42d613fa48a8cd294a 100644
--- a/core/modules/content_translation/content_translation.info.yml
+++ b/core/modules/content_translation/content_translation.info.yml
@@ -3,6 +3,7 @@ type: module
 description: 'Allows users to translate content.'
 dependencies:
   - drupal:language
+  - drupal:path_alias
 package: Multilingual
 version: VERSION
 configure: language.content_settings_page
diff --git a/core/modules/system/tests/src/Functional/Pager/PagerTest.php b/core/modules/system/tests/src/Functional/Pager/PagerTest.php
index 9686d44dbb68e1bb54f1c218d1887b504365ecfd..ca3519893a70ebfa85d149b77034780c4612d1a0 100644
--- a/core/modules/system/tests/src/Functional/Pager/PagerTest.php
+++ b/core/modules/system/tests/src/Functional/Pager/PagerTest.php
@@ -42,6 +42,9 @@ class PagerTest extends BrowserTestBase {
   protected function setUp(): void {
     parent::setUp();
 
+    // Start from a clean log.
+    \Drupal::database()->delete('watchdog')->execute();
+
     // Insert 300 log messages.
     $logger = $this->container->get('logger.factory')->get('pager_test');
     for ($i = 0; $i < 300; $i++) {
diff --git a/core/modules/views/tests/src/Functional/Entity/FieldEntityTest.php b/core/modules/views/tests/src/Functional/Entity/FieldEntityTest.php
index 1489884840a32236a6e25d1ab0af2b0654c0f0eb..545a9d8d58f80bb156770d426c6a762bf654324f 100644
--- a/core/modules/views/tests/src/Functional/Entity/FieldEntityTest.php
+++ b/core/modules/views/tests/src/Functional/Entity/FieldEntityTest.php
@@ -155,6 +155,13 @@ public function testGetEntityNullEntityOptionalRelationship(): void {
     // Tests optional relationships with NULL entities don't log an error.
     $nodeReference->delete();
 
+    // @todo This test should be a kernel test and swapping the logger.factory
+    //   service out this way is not correct. Get the file_system service so it
+    //   is injected correctly. This is necessary due to the second container
+    //   rebuild in the ModuleInstaller. This might become unnecessary if we
+    //   swap that for a views hook.
+    \Drupal::service('file_system');
+
     // Use a mock logger so we can check that no errors were logged.
     $loggerFactory = $this->createMock(LoggerChannelFactoryInterface::class);
     $loggerFactory->expects($this->never())
@@ -168,6 +175,7 @@ public function testGetEntityNullEntityOptionalRelationship(): void {
     // First row will be $node since the other is now deleted.
     $row = $view->result[0];
     $this->assertNull($view->field['nid']->getEntity($row));
+
   }
 
 }
diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php
index ce3d4318c89cd2aff228cb5e2b54d1c18d9c4e46..3a7407f3b56adfc84812eadcd5e2b24050d592f4 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBase.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -576,6 +576,7 @@ public function register(ContainerBuilder $container) {
       $this->keyValue = new KeyValueMemoryFactory();
     }
     $container->set('keyvalue', $this->keyValue);
+    $container->getDefinition('keyvalue')->setSynthetic(TRUE);
 
     // Set the default language on the minimal container.
     $container->setParameter('language.default_values', Language::$defaultValues);