Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp	(revision 68338)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp	(revision 68339)
@@ -3981,5 +3981,29 @@
         }
 
+        /* For each controller ('updating' step): */
+        // We need to separately update controllers first because
+        // attachments should be removed/updated/created same separate way.
+        for (int iControllerIndex = 0; fSuccess && iControllerIndex < m_pCache->childCount(); ++iControllerIndex)
+        {
+            /* Get controller cache: */
+            const UISettingsCacheMachineStorageController &controllerCache = m_pCache->child(iControllerIndex);
+
+            /* Update controller marked for 'update' (if it can be updated): */
+            if (controllerCache.wasUpdated() && isControllerCouldBeUpdated(controllerCache))
+                fSuccess = updateStorageController(controllerCache, true);
+        }
+        for (int iControllerIndex = 0; fSuccess && iControllerIndex < m_pCache->childCount(); ++iControllerIndex)
+        {
+            /* Get controller cache: */
+            const UISettingsCacheMachineStorageController &controllerCache = m_pCache->child(iControllerIndex);
+
+            /* Update controller marked for 'update' (if it can be updated): */
+            if (controllerCache.wasUpdated() && isControllerCouldBeUpdated(controllerCache))
+                fSuccess = updateStorageController(controllerCache, false);
+        }
+
         /* For each controller ('creating' step): */
+        // Finally we are creating new controllers,
+        // with attachments which were released for sure.
         for (int iControllerIndex = 0; fSuccess && iControllerIndex < m_pCache->childCount(); ++iControllerIndex)
         {
@@ -3990,10 +4014,4 @@
             if (controllerCache.wasCreated() || (controllerCache.wasUpdated() && !isControllerCouldBeUpdated(controllerCache)))
                 fSuccess = createStorageController(controllerCache);
-
-            else
-
-            /* Update controller marked for 'update' (if it can be updated): */
-            if (controllerCache.wasUpdated() && isControllerCouldBeUpdated(controllerCache))
-                fSuccess = updateStorageController(controllerCache);
         }
     }
@@ -4117,5 +4135,6 @@
 }
 
-bool UIMachineSettingsStorage::updateStorageController(const UISettingsCacheMachineStorageController &controllerCache)
+bool UIMachineSettingsStorage::updateStorageController(const UISettingsCacheMachineStorageController &controllerCache,
+                                                       bool fRemovingStep)
 {
     /* Prepare result: */
@@ -4179,32 +4198,37 @@
                 notifyOperationProgressError(UIMessageCenter::formatErrorInfo(comController));
 
-            /* For each attachment ('removing' step): */
             // We need to separately remove attachments first because
-            // there could be limited amount of attachments available.
-            for (int iAttachmentIndex = 0; fSuccess && iAttachmentIndex < controllerCache.childCount(); ++iAttachmentIndex)
+            // there could be limited amount of attachments or media available.
+            if (fRemovingStep)
             {
-                /* Get attachment cache: */
-                const UISettingsCacheMachineStorageAttachment &attachmentCache = controllerCache.child(iAttachmentIndex);
-
-                /* Remove attachment marked for 'remove' or 'update' (if it can't be updated): */
-                if (attachmentCache.wasRemoved() || (attachmentCache.wasUpdated() && !isAttachmentCouldBeUpdated(attachmentCache)))
-                    fSuccess = removeStorageAttachment(controllerCache, attachmentCache);
+                /* For each attachment ('removing' step): */
+                for (int iAttachmentIndex = 0; fSuccess && iAttachmentIndex < controllerCache.childCount(); ++iAttachmentIndex)
+                {
+                    /* Get attachment cache: */
+                    const UISettingsCacheMachineStorageAttachment &attachmentCache = controllerCache.child(iAttachmentIndex);
+
+                    /* Remove attachment marked for 'remove' or 'update' (if it can't be updated): */
+                    if (attachmentCache.wasRemoved() || (attachmentCache.wasUpdated() && !isAttachmentCouldBeUpdated(attachmentCache)))
+                        fSuccess = removeStorageAttachment(controllerCache, attachmentCache);
+                }
             }
-
-            /* For each attachment ('creating' step): */
-            for (int iAttachmentIndex = 0; fSuccess && iAttachmentIndex < controllerCache.childCount(); ++iAttachmentIndex)
+            else
             {
-                /* Get attachment cache: */
-                const UISettingsCacheMachineStorageAttachment &attachmentCache = controllerCache.child(iAttachmentIndex);
-
-                /* Create attachment marked for 'create' or 'update' (if it can't be updated): */
-                if (attachmentCache.wasCreated() || (attachmentCache.wasUpdated() && !isAttachmentCouldBeUpdated(attachmentCache)))
-                    fSuccess = createStorageAttachment(controllerCache, attachmentCache);
-
-                else
-
-                /* Update attachment marked for 'update' (if it can be updated): */
-                if (attachmentCache.wasUpdated() && isAttachmentCouldBeUpdated(attachmentCache))
-                    fSuccess = updateStorageAttachment(controllerCache, attachmentCache);
+                /* For each attachment ('creating' step): */
+                for (int iAttachmentIndex = 0; fSuccess && iAttachmentIndex < controllerCache.childCount(); ++iAttachmentIndex)
+                {
+                    /* Get attachment cache: */
+                    const UISettingsCacheMachineStorageAttachment &attachmentCache = controllerCache.child(iAttachmentIndex);
+
+                    /* Create attachment marked for 'create' or 'update' (if it can't be updated): */
+                    if (attachmentCache.wasCreated() || (attachmentCache.wasUpdated() && !isAttachmentCouldBeUpdated(attachmentCache)))
+                        fSuccess = createStorageAttachment(controllerCache, attachmentCache);
+
+                    else
+
+                    /* Update attachment marked for 'update' (if it can be updated): */
+                    if (attachmentCache.wasUpdated() && isAttachmentCouldBeUpdated(attachmentCache))
+                        fSuccess = updateStorageAttachment(controllerCache, attachmentCache);
+                }
             }
         }
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.h	(revision 68338)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.h	(revision 68339)
@@ -775,5 +775,6 @@
     bool createStorageController(const UISettingsCacheMachineStorageController &controllerCache);
     /** Updates existing storage controller described by the @a controllerCache. */
-    bool updateStorageController(const UISettingsCacheMachineStorageController &controllerCache);
+    bool updateStorageController(const UISettingsCacheMachineStorageController &controllerCache,
+                                 bool fRemovingStep);
     /** Removes existing storage attachment described by the @a controllerCache and @a attachmentCache. */
     bool removeStorageAttachment(const UISettingsCacheMachineStorageController &controllerCache,
