diff --git a/commands/core/site_install.drush.inc b/commands/core/site_install.drush.inc
index 589b1bb..8ba52af 100644
--- a/commands/core/site_install.drush.inc
+++ b/commands/core/site_install.drush.inc
@@ -16,7 +16,7 @@ function drush_core_site_install_validate() {
 /**
  * Perform setup tasks for installation.
  */
-function drush_core_pre_site_install() {
+function drush_core_pre_site_install($profile = NULL) {
   if (!$db_spec = _drush_sql_get_db_spec()) {
     drush_set_error(dt('Could not determine database connection parameters. Pass --db-url option.'));
     return;
@@ -81,6 +81,12 @@ function drush_core_pre_site_install() {
         }
         file_put_contents($settingsfile, "\n" . $db_prefix_config . "\n", FILE_APPEND);
       }
+      // If there is a profile, write it into $conf['install_profile']
+      // to help drush find commandfiles earlier in the drush bootstrap.
+      if (!empty($profile)) {
+        $install_profile_config = "\$conf['install_profile'] = '$profile';";
+        file_put_contents($settingsfile, "\n" . $install_profile_config . "\n", FILE_APPEND);
+      }
     }
   }
 
diff --git a/includes/command.inc b/includes/command.inc
index 6b5e256..fe1ccf7 100644
--- a/includes/command.inc
+++ b/includes/command.inc
@@ -885,11 +885,15 @@ function _drush_find_commandfiles($phase, $phase_max = FALSE) {
       // enabled modules.
       if ($phase_max < DRUSH_BOOTSTRAP_DRUPAL_FULL) {
         $searchpath[] = conf_path() . '/modules';
-        // Too early for variable_get('install_profile', 'default'); Just use default.
-        $searchpath[] = "profiles/default/modules";
         // Add all module paths, even disabled modules. Prefer speed over accuracy.
         $searchpath[] = 'sites/all/modules';
       }
+      if ($phase_max < DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION) {
+        // Too early for variable_get('install_profile', 'default'); look in all profiles.
+        // If we're definitely going to get to DRUPAL_CONFIGURATION, then wait and
+        // see if we have 'install_profile' available there.
+        $searchpath[] = "profiles";
+      }
       $searchpath[] = 'sites/all/themes';
       $searchpath[] = conf_path() . '/themes';
       break;
@@ -901,6 +905,10 @@ function _drush_find_commandfiles($phase, $phase_max = FALSE) {
         if ($profile = variable_get('install_profile', NULL)) {
           $searchpath[] = "profiles/$profile/modules";
         }
+        else {
+          // If 'install_profile' is not available, check all profiles.
+          $searchpath[] = "profiles";
+        }
       }
       break;
     case DRUSH_BOOTSTRAP_DRUPAL_FULL:
