diff --git a/core/includes/common.inc b/core/includes/common.inc
index dfd20fa..6dcd540 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -272,7 +272,7 @@ function drupal_get_profile() {
     $profile = $install_state['parameters']['profile'];
   }
   else {
-    $profile = variable_get('install_profile', 'standard');
+    $profile = Drupal::state()->get('profile.install') ?: 'standard';
   }
 
   return $profile;
diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index eefe926..2c310a1 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -1985,7 +1985,7 @@ function install_update_configuration_translations(&$install_state) {
 function install_finished(&$install_state) {
   $profile = drupal_get_profile();
   // Remember the profile which was used.
-  variable_set('install_profile', $profile);
+  Drupal::state()->set('profile.install', $profile);
 
   // Installation profiles are always loaded last.
   module_set_weight($profile, 1000);
diff --git a/core/includes/update.inc b/core/includes/update.inc
index cf25b03..4a60149 100644
--- a/core/includes/update.inc
+++ b/core/includes/update.inc
@@ -331,6 +331,12 @@ function update_prepare_d8_bootstrap() {
         variable_set('language_default', (array) $language_default);
       }
 
+      // Moves install_profile from variable to state. You can't do that in
+      // system.install because _system_rebuild_module_data() needs the profile
+      // directly.
+      $old_variable = unserialize(Drupal::database()->query('SELECT value FROM {variable} WHERE name = :name', array(':name' => 'install_profile'))->fetchField());
+      Drupal::state()->set('profile.install', $old_variable);
+
       $module_config = config('system.module');
       $disabled_modules = config('system.module.disabled');
       $theme_config = config('system.theme');
diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php
index 67ec268..c17e186 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php
@@ -80,6 +80,10 @@ public function testVariableUpgrade() {
       'page.front' => 'node',
     );
 
+    // The upgrade path converts "install_profile" to the state key
+    // "profile.install".
+    $this->assertEqual('minimal', $this->container->get('state')->get('profile.install'));
+
     $expected_config['user.settings'] = array(
       'cancel_method' => 'user_cancel_reassign',
     );
diff --git a/core/modules/system/tests/upgrade/drupal-7.system.database.php b/core/modules/system/tests/upgrade/drupal-7.system.database.php
index beebe4e..f15d406 100644
--- a/core/modules/system/tests/upgrade/drupal-7.system.database.php
+++ b/core/modules/system/tests/upgrade/drupal-7.system.database.php
@@ -243,3 +243,8 @@
     'value' => serialize('public://color/seven-09696463/dummy-screenshot.png'),
   ))
   ->execute();
+
+db_update('variable')
+  ->fields(array('value' => 's:7:"minimal";'))
+  ->condition('name', 'install_profile')
+  ->execute();
