diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index c9cd714864cd619bbb9a3c9644d4bb816a7388db..a73a969b4ed5c540049bb9b3f2d59c3a53fdc0d6 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -457,7 +457,7 @@ function conf_init() {
   global $base_url, $base_path, $base_root;
 
   // Export the following settings.php variables to the global namespace
-  global $databases, $db_prefix, $cookie_domain, $conf, $installed_profile, $update_free_access;
+  global $databases, $db_prefix, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url;
   $conf = array();
 
   if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.php')) {
@@ -979,7 +979,7 @@ function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NO
  */
 function drupal_set_message($message = NULL, $type = 'status', $repeat = TRUE) {
   if ($message) {
-    if (!isset($_SESSION['messages'])) {
+    if (!isset($_SESSION['messages']) && function_exists('drupal_set_session')) {
       drupal_set_session('messages', array());
     }
 
diff --git a/includes/install.inc b/includes/install.inc
index 12598967962c15d7c57f71f7cc053754ba69bcb6..6eaf8db2c9d86295bc67b9fcf381d0f273402932 100644
--- a/includes/install.inc
+++ b/includes/install.inc
@@ -994,3 +994,61 @@ function drupal_check_module($module) {
   }
   return TRUE;
 }
+
+/**
+ * Check installation requirements and report any errors.
+ */
+function install_check_requirements($profile, $verify) {
+  // Check the profile requirements.
+  $requirements = $profile ? drupal_check_profile($profile) : array();
+
+  // If Drupal is not set up already, we need to create a settings file.
+  if (!$verify) {
+    $writable = FALSE;
+    $conf_path = './' . conf_path(FALSE, TRUE);
+    $settings_file = $conf_path . '/settings.php';
+    $file = $conf_path;
+    $exists = FALSE;
+    // Verify that the directory exists.
+    if (drupal_verify_install_file($conf_path, FILE_EXIST, 'dir')) {
+      // Check to make sure a settings.php already exists.
+      $file = $settings_file;
+      if (drupal_verify_install_file($settings_file, FILE_EXIST)) {
+        $exists = TRUE;
+        // If it does, make sure it is writable.
+        $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
+        $exists = TRUE;
+      }
+    }
+
+    if (!$exists) {
+      $requirements['settings file exists'] = array(
+        'title'       => st('Settings file'),
+        'value'       => st('The settings file does not exist.'),
+        'severity'    => REQUIREMENT_ERROR,
+        'description' => st('The @drupal installer requires that you create a settings file as part of the installation process. Copy the %default_file file to %file. More details about installing Drupal are available in <a href="@install_txt">INSTALL.txt</a>.', array('@drupal' => drupal_install_profile_name(), '%file' => $file, '%default_file' => $conf_path .'/default.settings.php', '@install_txt' => base_path() .'INSTALL.txt')),
+      );
+    }
+    else {
+      $requirements['settings file exists'] = array(
+        'title'       => st('Settings file'),
+        'value'       => st('The %file file exists.', array('%file' => $file)),
+      );
+      if (!$writable) {
+        $requirements['settings file writable'] = array(
+          'title'       => st('Settings file'),
+          'value'       => st('The settings file is not writable.'),
+          'severity'    => REQUIREMENT_ERROR,
+          'description' => st('The @drupal installer requires write permissions to %file during the installation process. If you are unsure how to grant file permissions, please consult the <a href="@handbook_url">online handbook</a>.', array('@drupal' => drupal_install_profile_name(), '%file' => $file, '@handbook_url' => 'http://drupal.org/server-permissions')),
+        );
+      }
+      else {
+        $requirements['settings file'] = array(
+          'title'       => st('Settings file'),
+          'value'       => st('Settings file is writable.'),
+        );
+      }
+    }
+  }
+  return $requirements;
+}
diff --git a/install.php b/install.php
index ec3bcf5071a4759f68110d02db5b2ad33820fbf9..17b02e119085cc561aac07db8659bba53d4d0977 100644
--- a/install.php
+++ b/install.php
@@ -890,64 +890,6 @@ function install_reserved_tasks() {
   return array('configure', 'profile-install', 'profile-install-batch', 'locale-initial-import', 'locale-initial-batch', 'profile-finished', 'locale-remaining-batch', 'finished', 'done');
 }
 
-/**
- * Check installation requirements and report any errors.
- */
-function install_check_requirements($profile, $verify) {
-  // Check the profile requirements.
-  $requirements = drupal_check_profile($profile);
-
-  // If Drupal is not set up already, we need to create a settings file.
-  if (!$verify) {
-    $writable = FALSE;
-    $conf_path = './' . conf_path(FALSE, TRUE);
-    $settings_file = $conf_path . '/settings.php';
-    $file = $conf_path;
-    $exists = FALSE;
-    // Verify that the directory exists.
-    if (drupal_verify_install_file($conf_path, FILE_EXIST, 'dir')) {
-      // Check to make sure a settings.php already exists.
-      $file = $settings_file;
-      if (drupal_verify_install_file($settings_file, FILE_EXIST)) {
-        $exists = TRUE;
-        // If it does, make sure it is writable.
-        $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
-        $exists = TRUE;
-      }
-    }
-
-    if (!$exists) {
-      $requirements['settings file exists'] = array(
-        'title'       => st('Settings file'),
-        'value'       => st('The settings file does not exist.'),
-        'severity'    => REQUIREMENT_ERROR,
-        'description' => st('The @drupal installer requires that you create a settings file as part of the installation process. Copy the %default_file file to %file. More details about installing Drupal are available in <a href="@install_txt">INSTALL.txt</a>.', array('@drupal' => drupal_install_profile_name(), '%file' => $file, '%default_file' => $conf_path .'/default.settings.php', '@install_txt' => base_path() .'INSTALL.txt')),
-      );
-    }
-    else {
-      $requirements['settings file exists'] = array(
-        'title'       => st('Settings file'),
-        'value'       => st('The %file file exists.', array('%file' => $file)),
-      );
-      if (!$writable) {
-        $requirements['settings file writable'] = array(
-          'title'       => st('Settings file'),
-          'value'       => st('The settings file is not writable.'),
-          'severity'    => REQUIREMENT_ERROR,
-          'description' => st('The @drupal installer requires write permissions to %file during the installation process. If you are unsure how to grant file permissions, please consult the <a href="@handbook_url">online handbook</a>.', array('@drupal' => drupal_install_profile_name(), '%file' => $file, '@handbook_url' => 'http://drupal.org/server-permissions')),
-        );
-      }
-      else {
-        $requirements['settings file'] = array(
-          'title'       => st('Settings file'),
-          'value'       => st('Settings file is writable.'),
-        );
-      }
-    }
-  }
-  return $requirements;
-}
-
 /**
  * Add the installation task list to the current page.
  */
diff --git a/modules/system/system.install b/modules/system/system.install
index 460836948395fd3729a5640db94b7015f731db2a..faef5d4adbcfb27e6132bec08753b204124b255f 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -3225,6 +3225,17 @@ function system_update_7019() {
   return $ret;
 }
 
+/**
+ * Enable field module.
+ */
+function system_update_7020() {
+  $ret = array();
+  $module_list = array('field_sql_storage', 'field');
+  drupal_install_modules($module_list);
+  module_enable($module_list);
+  return $ret;
+}
+
 /**
  * @} End of "defgroup updates-6.x-to-7.x"
  * The next series of updates should start at 8000.
diff --git a/update.php b/update.php
index 5181b5b46d54e6b5a4c7dbadb480435050c4ca0b..c8668fdfcb227b0c49b85536bdb74feea1b52a52 100644
--- a/update.php
+++ b/update.php
@@ -625,8 +625,18 @@ function update_task_list($active = NULL) {
  * Check update requirements and report any errors.
  */
 function update_check_requirements() {
+  global $db_url, $databases;
+  $requirements = array();
+
+  // If we will rewrite the settings.php then we need to make sure it is
+  // writeable.
+  if (empty($databases) && !empty($db_url) && is_string($db_url)) {
+    $requirements = install_check_requirements('', FALSE);
+  }
+  $warnings = FALSE;
+
   // Check the system module requirements only.
-  $requirements = module_invoke('system', 'requirements', 'update');
+  $requirements += module_invoke('system', 'requirements', 'update');
   $severity = drupal_requirements_severity($requirements);
 
   // If there are issues, report them.
@@ -637,10 +647,34 @@ function update_check_requirements() {
         if (isset($requirement['value']) && $requirement['value']) {
           $message .= ' (Currently using ' . $requirement['title'] . ' ' . $requirement['value'] . ')';
         }
+        $warnings = TRUE;
         drupal_set_message($message, 'warning');
       }
     }
   }
+  return $warnings;
+}
+
+/**
+ * Converts Drupal 6 $db_url to Drupal 7 $databases array.
+ */
+function update_check_d7_settings() {
+  global $db_url, $databases;
+
+  if (empty($databases) && !empty($db_url) && is_string($db_url)) {
+    $url = parse_url($db_url);
+    $driver = substr($db_url, 0, strpos($db_url, '://'));
+    if ($driver == 'mysqli') {
+      $driver = 'mysql';
+    }
+    $databases['default']['default']['driver'] = $driver;
+    $databases['default']['default']['database'] = substr($url['path'], 1);
+    foreach (array('user' => 'username', 'pass' => 'password', 'host' => 'host', 'port' => 'port') as $old_key => $new_key) {
+      $databases['default']['default'][$new_key] =  isset($url[$old_key]) ? urldecode($url[$old_key]) : '';
+    }
+    $conf_path = conf_path();
+    file_put_contents($conf_path .'/settings.php', "\n" . '$databases = '. var_export($databases, TRUE) . ';', FILE_APPEND);
+  }
 }
 
 // Some unavoidable errors happen because the database is not yet up-to-date.
@@ -675,16 +709,18 @@ function update_check_requirements() {
   drupal_maintenance_theme();
 
   // Check the update requirements for Drupal.
-  update_check_requirements();
+  $warnings = update_check_requirements();
 
   // Display the warning messages (if any) in a dedicated maintenance page,
   // or redirect to the update information page if no message.
-  $messages = drupal_set_message();
-  if (!empty($messages['warning'])) {
+  if ($warnings) {
     drupal_maintenance_theme();
     print theme('update_page', '<form method="post" action="update.php?op=info"><input type="submit" value="Continue" /></form>', FALSE);
     exit;
   }
+  // Write D7 settings file.
+  update_check_d7_settings();
+
   install_goto('update.php?op=info');
 }