Créer une image de disque persistant à partir d'un fichier ISO
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Windows
Le support d'installation pour les applications Windows est souvent fourni sous forme de fichier ISO, mais Compute Engine ne permet pas d'exposer un fichier ISO en tant que lecteur DVD virtuel sur une instance de VM.
Pour accéder au contenu du fichier ISO sur une seule VM Windows, vous pouvez effectuer l'une des opérations suivantes :
Copiez le fichier ISO sur la VM et installez-le localement. Cette approche fonctionne bien si vous n'avez besoin d'accéder au contenu du fichier ISO que sur une seule instance de VM.
Créez un disque persistant à partir du fichier ISO et associez le disque en mode lecture seule à une ou plusieurs instances de VM. Cette approche fonctionne bien si plusieurs VM nécessitent d'accéder au contenu du fichier ISO.
Ce document explique comment créer un disque persistant à partir du fichier ISO et l'associer en mode lecture seule à une ou plusieurs VM.
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 :
Si le fichier ISO est accessible au public via HTTP, vous n'avez pas besoin de le télécharger au préalable. Pour utiliser un fichier ISO local, vous pouvez l'importer dans Cloud Storage.
URL HTTP
Dans la console Google Cloud , ouvrez Cloud Shell en cliquant sur le bouton Activer Cloud Shell.
Créez une variable d'environnement pour l'URL de téléchargement. Vous pouvez utiliser une URL HTTP ou HTTPS, pourvu qu'elle soit accessible de manière anonyme.
Le démarrage de la VM prend environ deux minutes. Selon la taille du fichier ISO, l'opération de copie du fichier peut prendre entre 5 et 15 minutes. Vous pouvez suivre la progression en exécutant la commande suivante :
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/03 (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/03 (UTC)."],[[["\u003cp\u003eCompute Engine cannot directly expose an ISO file as a virtual DVD drive to a VM instance, but provides two methods to access the ISO contents: locally mounting the file on a single VM or creating a Persistent Disk for read-only access by multiple VMs.\u003c/p\u003e\n"],["\u003cp\u003eTo prepare an ISO file for use, it can either be accessed publicly via HTTP or uploaded to Cloud Storage if it's a local file.\u003c/p\u003e\n"],["\u003cp\u003eA temporary VM is used to copy the ISO file contents onto a new disk, which involves formatting the disk, downloading the ISO, mounting it, and copying its contents, handled by a startup script.\u003c/p\u003e\n"],["\u003cp\u003eAfter the contents are copied, the temporary VM can be shut down and deleted, and the new Persistent Disk can then be attached in read-only mode to one or more VM instances.\u003c/p\u003e\n"],["\u003cp\u003eTo extend the availability of the ISO contents to other zones or regions, you can create a Compute Engine image from the disk.\u003c/p\u003e\n"]]],[],null,["# Create a persistent disk image from an ISO file\n\nWindows\n\n*** ** * ** ***\n\nInstallation media for Windows applications is often provided as an ISO file,\nbut Compute Engine does not let you expose an ISO file as a virtual DVD drive to a\nVM instance.\n\nTo access the contents of the ISO file on a single Windows VM, you can do either\nof the following:\n\n- Copy the ISO file to the VM and [mount it locally](https://docs.microsoft.com/en-us/powershell/module/storage/mount-diskimage?view=win10-ps). This approach works well if you\n only need to access the contents of the ISO file on a single VM instance.\n\n- Create a Persistent Disk from the ISO file and attach the disk in read-only mode\n to one or more VM instances. This approach works well if multiple VMs need\n access to the contents of the ISO file.\n\nThis document describes how you can create a Persistent Disk from the ISO file and\nattach the disk in read-only mode to one or more VMs.\n| **Note:** The process described in this document does not apply to creating bootable operating system images from ISO files. For creating a bootable operating system image, see [Creating custom Windows BYOL images](/compute/docs/images/creating-custom-windows-byol-images).\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\nPrepare the ISO file\n--------------------\n\nIf the ISO file is publicly available via HTTP, you do not need to download\nthe ISO file first. To use a local ISO file, you can upload the ISO file to\nCloud Storage. \n\n### HTTP URL\n\n1. In the Google Cloud console, open\n [Cloud Shell](/shell/docs/using-cloud-shell)\n by clicking the\n **Activate Cloud Shell**\n button.\n\n [Go to the Google Cloud console](https://console.cloud.google.com/)\n2. Create an environment variable for the download URL. The URL can be\n an HTTP or HTTPS URL, but it must be accessible anonymously.\n\n ```\n ISO_URL=https://example.com/big.iso\n ```\n\n### Local ISO file\n\n1. In the Google Cloud console, [create a Cloud Storage bucket](/storage/docs/creating-buckets).\n\n [Go to the Google Cloud console](https://console.cloud.google.com/)\n2. [Upload the ISO file](/storage/docs/uploading-objects).\n\n Depending on the size of the ISO file, the upload can take several\n minutes or hours.\n3. In the [Storage browser](https://console.cloud.google.com/storage/browser), navigate to\n the uploaded object.\n\n4. On the **Object details** page, copy the URI of the object. The URI\n starts with `gs://`.\n\n5. Open [Cloud Shell](/shell/docs/using-cloud-shell)\n by clicking the\n **Activate Cloud Shell**\n button.\n\n [Go to the Google Cloud console](https://console.cloud.google.com/)\n6. Create an environment variable for the download URL. Replace\n \u003cvar translate=\"no\"\u003eURI\u003c/var\u003e with the URI that you copied.\n\n ```\n ISO_URL=URI\n ```\n\nCreate a disk containing the contents of the ISO file\n-----------------------------------------------------\n\nTo copy the contents of the ISO file to a new disk, create a temporary VM, then\ncreate an image from the disk:\n\n1. From Cloud Shell, specify the name that you want to assign to the new\n disk:\n\n DISK_NAME=iso\n\n2. Create a new disk to which to copy the contents of the ISO files:\n\n ```\n gcloud compute disks create $DISK_NAME \\\n --size=10GB \\\n --zone=$(gcloud config get-value compute/zone)\n ```\n\n Use a larger disk size if your ISO file exceeds 9 GB.\n3. Create a startup script for the temporary VM. The startup script performs\n the following actions:\n\n 1. Format the secondary disk with the NTFS file system.\n 2. Download the ISO file from the HTTP or Cloud Storage URL you specified.\n 3. Mount the ISO file and copy its contents to the secondary disk.\n\n ```\n cat \u003c\u003c \"EOF\" \u003e startup.ps1\n\n $DownloadDirectory = 'c:\\download\\'\n $ErrorActionPreference = 'Stop'\n $MetadataUrl = 'http://metadata.google.internal/computeMetadata/v1/instance'\n\n $DownloadUrl = (Invoke-RestMethod `\n -Headers @{\"Metadata-Flavor\" = \"Google\"} `\n -Uri \"$MetadataUrl/attributes/iso\")\n\n mkdir $DownloadDirectory\\Source -Force\n\n Write-Host '== Formatting secondary disk... ===' -ForegroundColor Black -BackgroundColor Yellow\n Set-Disk -Number 1 -IsOffline $false\n Clear-Disk -Number 1 -RemoveData -Confirm:$false -ErrorAction SilentlyContinue\n Initialize-Disk -Number 1 -PartitionStyle MBR\n New-Partition -DiskNumber 1 -UseMaximumSize -DriveLetter D -IsActive |\n Format-Volume -FileSystem 'NTFS' -Confirm:$false\n\n Write-Host '== Downloading ISO... =============' -ForegroundColor Black -BackgroundColor Yellow\n if ($DownloadUrl.StartsWith('gs:')) {\n & gcloud storage cp $DownloadUrl \"$DownloadDirectory\\Source\\image.iso\" | Out-Default\n }\n else {\n Import-Module BitsTransfer\n Start-BitsTransfer -Source $DownloadUrl -Destination \"$DownloadDirectory\\Source\\image.iso\"\n }\n\n Write-Host '== Mounting ISO... ================' -ForegroundColor Black -BackgroundColor Yellow\n Mount-DiskImage -ImagePath \"$DownloadDirectory\\Source\\image.iso\" -StorageType ISO\n\n Write-Host '== Copying ISO contents... ========' -ForegroundColor Black -BackgroundColor Yellow\n Copy-Item 'e:\\*' 'd:\\' -Force -Recurse -PassThru `\n | Where-Object { -Not $_.PSIsContainer } `\n | Set-ItemProperty -Name IsReadOnly -Value $False\n\n Write-Host '== Completed. =====================' -ForegroundColor Black -BackgroundColor Yellow\n Invoke-RestMethod `\n -Headers @{'Metadata-Flavor'='Google'} `\n -Method PUT `\n -Uri \"$MetadataUrl/guest-attributes/vm/ready\" `\n -Body true\n EOF\n ```\n4. Create a Windows Server 2019 VM that uses the startup script and the disk\n that you created previously:\n\n ```\n gcloud compute instances create iso-copier \\\n --machine-type=n1-standard-2 \\\n --image-family=windows-2019-core \\\n --image-project=windows-cloud \\\n --disk=name=$DISK_NAME,auto-delete=no \\\n --metadata=enable-guest-attributes=true,iso=$ISO_URL \\\n --metadata-from-file=windows-startup-script-ps1=startup.ps1 \\\n --scopes=https://www.googleapis.com/auth/devstorage.read_only\n ```\n\n The VM takes about 2 minutes to start. Depending on the size of the\n ISO file, it can take another 5-15 minutes for the file copy operation\n to complete. You can observe the progress by running the following\n command: \n\n ```\n gcloud compute instances tail-serial-port-output iso-copier \\\n --zone=$(gcloud config get-value compute/zone)\n ```\n5. Wait for the VM to finish running the startup script:\n\n ```\n until gcloud compute instances get-guest-attributes iso-copier \\\n --zone=$(gcloud config get-value compute/zone) \\\n --query-path=vm/ready \u003e /dev/null 2\u003e&1\n do\n sleep 5 && echo waiting for VM to finish...\n done\n ```\n6. Shut down and delete the VM:\n\n ```\n gcloud compute instances delete iso-copier \\\n --zone=$(gcloud config get-value compute/zone) \\\n --quiet\n ```\n\n Notice that the secondary disk is not deleted because it was mounted with\n the parameter `auto-delete=no`.\n\nThe disk is now ready to be used. You can [attach the disk in read-only mode\nto one or more VM instances](/compute/docs/disks/sharing-disks-between-vms)\nwithin the same zone.\n\nShare the disk across zones and regions by creating an image\n------------------------------------------------------------\n\nTo make the contents of the ISO file available in other zones or regions,\ncreate a Compute Engine image:\n\n1. From Cloud Shell, create an image from the disk that you created in the\n previous section:\n\n ```\n gcloud compute images create $DISK_NAME \\\n --source-disk=$DISK_NAME \\\n --source-disk-zone=$(gcloud config get-value compute/zone)\n ```\n\nClean up\n--------\n\nTo avoid incurring further costs after you have completed this process, you\ncan delete the resources that you created:\n\n1. Delete the disk:\n\n ```\n gcloud compute disks delete $DISK_NAME \\\n --zone=$(gcloud config get-value compute/zone) \\\n --quiet\n ```\n2. Delete the image:\n\n ```\n gcloud compute images delete $DISK_NAME\n ```\n\nWhat's next\n-----------\n\n- Learn how to\n [create custom images](/compute/docs/images/create-delete-deprecate-private-images).\n\n- Learn how to\n [manage access to custom images](/compute/docs/images/managing-access-custom-images).\n\n- Learn more about\n [Windows workloads on Compute Engine](/compute/docs/instances/windows)."]]