Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Vous pouvez dissocier des disques de démarrage de votre instance de VM et associer de nouveaux disques de démarrage.
Cette fonctionnalité simplifie le processus de réparation des disques de démarrage en vous permettant de les installer sur une autre instance de VM sans supprimer l'instance d'origine.
En outre, vous pouvez remplacer les disques de démarrage d'une instance au lieu de devoir recréer toute l'instance de VM.
Si une instance de VM ne dispose d'aucun disque de démarrage, toute tentative de démarrage de l'instance génère une erreur. Toutefois, vous pouvez toujours modifier d'autres propriétés de l'instance.
Avant de commencer
Si ce n'est pas déjà fait, configurez l'authentification.
L'authentification valide votre identité pour accéder aux services et aux API Google Cloud . Pour exécuter du code ou des exemples depuis un environnement de développement local, vous pouvez vous authentifier auprès de Compute Engine en sélectionnant l'une des options suivantes :
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and
APIs, you don't need to set up authentication.
gcloud
Installez la Google Cloud CLI.
Une fois que la Google Cloud CLI est installée, initialisez-la en exécutant la commande suivante :
Pour utiliser les exemples API REST de cette page dans un environnement de développement local, vous devez utiliser les identifiants que vous fournissez à la gcloud CLI.
Installez la Google Cloud CLI.
Une fois que la Google Cloud CLI est installée, initialisez-la en exécutant la commande suivante :
Si vous y êtes invité(e), sélectionnez votre projet et cliquez sur Continuer.
Cliquez sur l'instance dont vous souhaitez dissocier le disque de démarrage.
Cliquez sur stopArrêter pour arrêter la VM. Si l'option Arrêter n'est pas disponible, cliquez sur more_vertAutres actions > stopArrêter.
Cliquez sur Modifier.
Faites défiler la page jusqu'à la section Disque de démarrage et cliquez sur la croix X située en regard du disque de démarrage que vous souhaitez dissocier.
DISK_NAME : nom du disque à dissocier.
Le nom du disque est généralement identique à celui de l'instance.
REST
Envoyez une requête POST pour dissocier le disque :
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/detachDisk?deviceName=DISK_NAME
Remplacez les éléments suivants :
PROJECT_ID : par l'ID du projet.
INSTANCE_NAME : nom de l'instance.
ZONE : zone dans laquelle se trouve l'instance.
DISK_NAME : nom du disque à dissocier.
Le nom du disque est généralement identique à celui de l'instance.
Réassocier un disque de démarrage
Tout disque peut être réassocié à une instance en tant que disque de démarrage à condition que cette dernière ne dispose pas déjà d'un disque de démarrage et que le disque de démarrage soit dans la même zone que l'instance de VM. Si vous personnalisez un disque de démarrage, vous devez vous assurer que celui-ci démarre correctement une fois qu'il a été associé.
Le disque existant et le nouveau disque doivent être tous deux du même type : compatibles UEFI ou non compatibles UEFI.
Pour créer un disque compatible UEFI, utilisez la commande gcloud compute disk create avec l'option --guest-os-features définie sur UEFI_COMPATIBLE.
Si vous y êtes invité(e), sélectionnez votre projet et cliquez sur Continuer.
Cliquez sur l'instance à laquelle vous souhaitez associer le disque de démarrage.
Si la VM est en cours d'exécution, cliquez sur stopArrêter pour l'arrêter. Si l'option Arrêter n'est pas disponible, cliquez sur more_vertAutres actions > stopArrêter.
Cliquez sur Modifier.
Accédez à la section Disque de démarrage.
Cliquez sur Ajouter un élément.
Sélectionnez un disque de démarrage dans le menu déroulant.
Cliquez sur Enregistrer.
gcloud
Exécutez la commande gcloud compute instances attach-disk pour associer ou réassocier un disque de démarrage à une instance de VM. Incluez l'option --boot pour indiquer que le disque est utilisé comme disque de démarrage de l'instance.
Si cette option n'est pas spécifiée, le disque est associé en tant que disque de données non amorçable.
DISK_NAME : nom du disque à associer.
Le nom du disque peut être identique à celui de l'instance.
REST
Envoyez une requête POST pour associer le disque. Incluez le paramètre facultatif "boot": true pour indiquer qu'il s'agit du disque de démarrage. Si ce paramètre n'est pas spécifié, le disque est associé en tant que disque de données non amorçable.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/attachDisk
{
"boot": true,
"source": "zones/ZONE/disks/DISK_NAME"
}
Remplacez les éléments suivants :
PROJECT_ID : par l'ID du projet.
INSTANCE_NAME : nom de l'instance à laquelle vous associez le nouveau disque persistant.
ZONE : la zone où se trouvent l'instance et le nouveau disque.
DISK_NAME : le nom du nouveau disque.
Après avoir associé le disque à l'instance de VM, redémarrez-la.
Mettre à jour un disque de démarrage pour une instance
La mise à jour du disque de démarrage d'une VM en une seule étape ne peut être effectuée que via la console Google Cloud . Plus précisément, vous pouvez dissocier un disque de démarrage existant et associer un nouveau disque de démarrage en une seule action.
Cette fonctionnalité n'est pas disponible via la gcloud CLI ou REST.
Si vous y êtes invité(e), sélectionnez votre projet et cliquez sur Continuer.
Cliquez sur l'instance à laquelle vous souhaitez associer le disque de démarrage.
Si la VM est en cours d'exécution, cliquez sur stopArrêter pour l'arrêter. Si l'option Arrêter n'est pas disponible, cliquez sur more_vertAutres actions > stopArrêter.
Cliquez sur Modifier en haut de la page.
Faites défiler jusqu'à la section Disque de démarrage.
Cliquez sur la croix X située en regard du disque de démarrage actuel.
Cliquez sur Ajouter un élément.
Sélectionnez un disque de démarrage dans le menu déroulant.
Cliquez sur Enregistrer.
La console Google Cloud va dissocier votre disque de démarrage existant et associer le nouveau disque de démarrage que vous avez spécifié. Une fois ce processus terminé, redémarrez l'instance de VM.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eYou can detach and attach boot disks to VM instances, which is useful for repairing boot disks or replacing them without recreating the entire VM.\u003c/p\u003e\n"],["\u003cp\u003eDetaching or attaching a boot disk can only be done when the VM instance is stopped, and each VM can only have one boot disk at a time.\u003c/p\u003e\n"],["\u003cp\u003eTo detach a boot disk, you can use the Google Cloud console, \u003ccode\u003egcloud\u003c/code\u003e CLI, or REST API, and the process involves stopping the instance, and then detaching the disk.\u003c/p\u003e\n"],["\u003cp\u003eTo attach a boot disk, ensure the disk and instance are in the same zone, and utilize the Google Cloud console, \u003ccode\u003egcloud\u003c/code\u003e CLI, or REST API, making sure to specify that it is the boot disk when using the CLI or API.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud console allows for updating a boot disk in one step by detaching an existing one and attaching a new one, a feature not supported by \u003ccode\u003egcloud\u003c/code\u003e or REST.\u003c/p\u003e\n"]]],[],null,["# Detaching and reattaching boot disks\n\n*** ** * ** ***\n\nYou can detach boot disks from your VM instance and attach new boot disks.\nThis feature simplifies the process of repairing boot disks by letting you\nmount them to another VM instance without deleting your original instance.\nAdditionally, you can replace the boot disks for an instance rather than having\nto recreate the entire VM instance.\n\nIf a VM instance does not have a boot disk, attempting to start\nthe instance generates an error. However, you can still edit other instance\nproperties.\n\nBefore you begin\n----------------\n\n- If you haven't already, set up [authentication](/compute/docs/authentication). Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:\n\n Select the tab for how you plan to use the samples on this page: \n\n ### Console\n\n\n When you use the Google Cloud console to access Google Cloud services and\n APIs, you don't need to set up authentication.\n\n ### gcloud\n\n 1.\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n | **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.\n 2. [Set a default region and zone](/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).\n\n ### REST\n\n\n To use the REST API samples on this page in a local development environment, you use the\n credentials you provide to the gcloud CLI.\n 1. [Install](/sdk/docs/install) the Google Cloud CLI. After installation, [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command: \n\n ```bash\n gcloud init\n ```\n 2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n\n For more information, see\n [Authenticate for using REST](/docs/authentication/rest)\n in the Google Cloud authentication documentation.\n\n#### Permissions required for this task\n\nTo perform this task, you must have the following [permissions](/iam/docs/overview#permissions):\n\n- `compute.instances.detachDisk` on the instance\n- `compute.instances.attachDisk` on the instance\n\nRestrictions\n------------\n\n- You can attach or detach a boot disk only from a [stopped VM instance](/compute/docs/instances/stop-start-instance).\n- You can attach only one boot disk per VM instance.\n- If using the gcloud CLI or REST, you can attach only existing boot disks to a VM instance.\n\nDetach a boot disk\n------------------\n\nBefore detaching the boot disk from the VM instance, you must\n[stop the instance](/compute/docs/instances/stopping-or-deleting-an-instance#stop_an_instance).\nYou don't need to unmount the disk. \n\n### Console\n\n1. Go to the VM instances page. [Go to VM instances](https://console.cloud.google.com/compute/instances)\n\n2. If prompted, select your project and click **Continue**.\n3. Click the instance for which you want to detach the boot disk.\n4. Click stop **Stop** to stop the VM. If there is no **Stop** option, click more_vert **More actions \\\u003e** stop **Stop**.\n5. Click **Edit**.\n6. Scroll down to the **Boot Disk** section and click **X** next to the boot disk that you want to detach.\n7. Click **Save**.\n\n### gcloud\n\nUse the\n[`gcloud compute instances detach-disk` command](/sdk/gcloud/reference/compute/instances/detach-disk)\nto detach the boot disk from the instance: \n\n```\ngcloud compute instances detach-disk INSTANCE_NAME \\\n --disk=DISK_NAME\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eINSTANCE_NAME\u003c/var\u003e: the name of the instance.\n- \u003cvar translate=\"no\"\u003eDISK_NAME\u003c/var\u003e: the name of the disk to detach. The disk name is usually the same as the instance name.\n\n### REST\n\nConstruct a `POST` request to detach the disk: \n\n```\nPOST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/detachDisk?deviceName=DISK_NAME\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of your project.\n- \u003cvar translate=\"no\"\u003eINSTANCE_NAME\u003c/var\u003e: the name of the instance.\n- \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone where your instances is located.\n- \u003cvar translate=\"no\"\u003eDISK_NAME\u003c/var\u003e: the name of the disk to detach. The disk name is usually the same as the instance name.\n\nReattach a boot disk\n--------------------\n\nAny disk can be reattached as a boot disk to an instance as long as the instance\ndoes not already have a boot disk attached and the boot disk is in the same\nzone as the VM instance. If you customize a boot disk, you\nmust ensure that the boot disk boots properly after it is attached.\n\nBoth the existing disk and the new disk must either be UEFI-compatible or not.\nTo create a UEFI-compatible disk, use the [`gcloud compute disk create` command](/sdk/gcloud/reference/compute/disks/create)\nwith the `--guest-os-features` flag set to `UEFI_COMPATIBLE`. \n\n### Console\n\n1. Go to the VM instances page. [Go to VM instances](https://console.cloud.google.com/compute/instances)\n\n2. If prompted, select your project and click **Continue**.\n3. Click the instance for which you want to attach the boot disk.\n4. If the VM is running, click stop **Stop** to stop the VM. If there is no **Stop** option, click more_vert **More actions \\\u003e** stop **Stop**.\n5. Click **Edit**.\n6. Go to the **Boot Disk** section.\n7. Click **Add item**.\n8. Select a boot disk from the drop-down menu.\n9. Click **Save**.\n\n### gcloud\n\nUse the\n[`gcloud compute instances attach-disk` command](/sdk/gcloud/reference/compute/instances/attach-disk)\nto attach or reattach a boot disk to a VM instance. Include the `--boot`\nflag to indicate that the disk is used as the boot disk for the instance.\nIf this flag is absent, the disk is attached as a non-boot data disk. \n\n```\ngcloud compute instances attach-disk INSTANCE_NAME \\\n --disk=DISK_NAME \\\n --boot\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eINSTANCE_NAME\u003c/var\u003e: the name of the instance.\n- \u003cvar translate=\"no\"\u003eDISK_NAME\u003c/var\u003e: the name of the disk to attach. The disk name may be the same as the instance name.\n\n### REST\n\nConstruct a `POST` request to attach the disk. Include the optional\n`\"boot\": true` parameter to indicate that this disk is the boot disk. If\nthis parameter is absent, the disk is attached as a non-boot data disk. \n\n```\nPOST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/attachDisk\n{\n \"boot\": true,\n \"source\": \"zones/ZONE/disks/DISK_NAME\"\n}\n```\n\n\u003cbr /\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of your project.\n- \u003cvar translate=\"no\"\u003eINSTANCE_NAME\u003c/var\u003e: the name of the instance to which you're attaching the new Persistent Disk.\n- \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone where your instance and new disk are located.\n- \u003cvar translate=\"no\"\u003eDISK_NAME\u003c/var\u003e: the name of the new disk.\n\nAfter you attach the disk to your VM instance,\n[restart the instance](/compute/docs/instances/restarting-an-instance).\n\nUpdate a boot disk for an instance\n----------------------------------\n\nYou can use only the Google Cloud console to update the boot disk for a VM in\none step. Specifically, you can detach an existing boot disk and attach a new\nboot disk as one action.\n\nThis feature is not available through the gcloud CLI or REST.\n\n1. Go to the VM instances page. [Go to VM instances](https://console.cloud.google.com/compute/instances)\n\n2. If prompted, select your project and click **Continue**.\n3. Click the instance for which you want to attach the boot disk.\n4. If the VM is running, click stop **Stop** to stop the VM. If there is no **Stop** option, click more_vert **More actions \\\u003e** stop **Stop**.\n5. Click **Edit** at the top of the page.\n6. Scroll down to the **Boot Disk** section.\n7. Click **X** next to the current boot disk.\n8. Click **Add item**.\n9. Select a boot disk from the drop-down menu.\n10. Click **Save**.\n\nThe Google Cloud console proceeds to detach your existing boot disk and attach\nthe new boot disk that you specified. When this process is complete,\n[restart the VM instance](/compute/docs/instances/restarting-an-instance).\n\nWhat's next?\n------------\n\n- [Create a new disk from a snapshot](/compute/docs/disks/restore-and-delete-snapshots#restoresnapshotlargersize)\n- [Transfer files to VM instances](/compute/docs/instances/transfer-files)"]]