Create a persistent disk image from an ISO file Stay organized with collections Save and categorize content based on your preferences.
Installation media for Windows applications is often provided as an ISO file,but Compute Engine does not let you expose an ISO file as a virtual DVD drive to aVM instance.
To access the contents of the ISO file on a single Windows VM, you can do eitherof the following:
Copy the ISO file to the VM andmount it locally. This approach works well if youonly need to access the contents of the ISO file on a single VM instance.
Create a Persistent Disk from the ISO file and attach the disk in read-only modeto one or more VM instances. This approach works well if multiple VMs needaccess to the contents of the ISO file.
This document describes how you can create a Persistent Disk from the ISO file andattach the disk in read-only mode to one or more VMs.
Note: The process described in this document does not apply to creatingbootable operating system images from ISO files. For creating a bootableoperating system image, seeCreating custom Windows BYOL images.Before you begin
- If you haven't already, set upauthentication. 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:
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
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.- Set a default region and zone.
Prepare the ISO file
If the ISO file is publicly available via HTTP, you do not need to downloadthe ISO file first. To use a local ISO file, you can upload the ISO file toCloud Storage.
HTTP URL
In the Google Cloud console, openCloud Shell by clicking theActivate Cloud Shell
button.
Create an environment variable for the download URL. The URL can bean HTTP or HTTPS URL, but it must be accessible anonymously.
ISO_URL=https://example.com/big.iso
Local ISO file
In the Google Cloud console,create a Cloud Storage bucket.
Depending on the size of the ISO file, the upload can take severalminutes or hours.
In theStorage browser, navigate tothe uploaded object.
On theObject details page, copy the URI of the object. The URIstarts with
gs://
.OpenCloud Shell by clicking theActivate Cloud Shell
button.
Create an environment variable for the download URL. Replace
URI
with the URI that you copied.ISO_URL=URI
Create a disk containing the contents of the ISO file
To copy the contents of the ISO file to a new disk, create a temporary VM, thencreate an image from the disk:
From Cloud Shell, specify the name that you want to assign to the newdisk:
DISK_NAME=iso
Create a new disk to which to copy the contents of the ISO files:
gcloud compute disks create $DISK_NAME \ --size=10GB \ --zone=$(gcloud config get-value compute/zone)
Use a larger disk size if your ISO file exceeds 9 GB.
Create a startup script for the temporary VM. The startup script performsthe following actions:
- Format the secondary disk with the NTFS file system.
- Download the ISO file from the HTTP or Cloud Storage URL youspecified.
- Mount the ISO file and copy its contents to the secondary disk.
cat<< "EOF" > startup.ps1$DownloadDirectory = 'c:\download\'$ErrorActionPreference = 'Stop'$MetadataUrl = 'http://metadata.google.internal/computeMetadata/v1/instance'$DownloadUrl = (Invoke-RestMethod ` -Headers @{"Metadata-Flavor" = "Google"} ` -Uri "$MetadataUrl/attributes/iso")mkdir $DownloadDirectory\Source -ForceWrite-Host '== Formatting secondary disk... ===' -ForegroundColor Black -BackgroundColor YellowSet-Disk -Number 1 -IsOffline $falseClear-Disk -Number 1 -RemoveData -Confirm:$false -ErrorAction SilentlyContinueInitialize-Disk -Number 1 -PartitionStyle MBRNew-Partition -DiskNumber 1 -UseMaximumSize -DriveLetter D -IsActive |Format-Volume -FileSystem 'NTFS' -Confirm:$falseWrite-Host '== Downloading ISO... =============' -ForegroundColor Black -BackgroundColor Yellowif ($DownloadUrl.StartsWith('gs:')) { & gcloud storage cp $DownloadUrl "$DownloadDirectory\Source\image.iso" | Out-Default}else { Import-Module BitsTransfer Start-BitsTransfer -Source $DownloadUrl -Destination "$DownloadDirectory\Source\image.iso"}Write-Host '== Mounting ISO... ================' -ForegroundColor Black -BackgroundColor YellowMount-DiskImage -ImagePath "$DownloadDirectory\Source\image.iso" -StorageType ISOWrite-Host '== Copying ISO contents... ========' -ForegroundColor Black -BackgroundColor YellowCopy-Item 'e:\*' 'd:\' -Force -Recurse -PassThru ` | Where-Object { -Not $_.PSIsContainer } ` | Set-ItemProperty -Name IsReadOnly -Value $FalseWrite-Host '== Completed. =====================' -ForegroundColor Black -BackgroundColor YellowInvoke-RestMethod ` -Headers @{'Metadata-Flavor'='Google'} ` -Method PUT ` -Uri "$MetadataUrl/guest-attributes/vm/ready" ` -Body trueEOF
Create a Windows Server 2019 VM that uses the startup script and the diskthat you created previously:
gcloud compute instances create iso-copier \ --machine-type=n1-standard-2 \ --image-family=windows-2019-core \ --image-project=windows-cloud \ --disk=name=$DISK_NAME,auto-delete=no \ --metadata=enable-guest-attributes=true,iso=$ISO_URL \ --metadata-from-file=windows-startup-script-ps1=startup.ps1 \ --scopes=https://www.googleapis.com/auth/devstorage.read_only
The VM takes about 2 minutes to start. Depending on the size of theISO file, it can take another 5-15 minutes for the file copy operationto complete. You can observe the progress by running the followingcommand:
gcloud compute instances tail-serial-port-output iso-copier \ --zone=$(gcloud config get-value compute/zone)
Wait for the VM to finish running the startup script:
until gcloud compute instances get-guest-attributes iso-copier \ --zone=$(gcloud config get-value compute/zone) \ --query-path=vm/ready > /dev/null 2>&1do sleep 5 && echo waiting for VM to finish...done
Shut down and delete the VM:
gcloud compute instances delete iso-copier \ --zone=$(gcloud config get-value compute/zone) \ --quiet
Notice that the secondary disk is not deleted because it was mounted withthe parameter
auto-delete=no
.
The disk is now ready to be used. You canattach the disk in read-only modeto one or more VM instances within the same zone.
Share the disk across zones and regions by creating an image
To make the contents of the ISO file available in other zones or regions,create a Compute Engine image:
From Cloud Shell, create an image from the disk that you created in theprevious section:
gcloud compute images create $DISK_NAME \ --source-disk=$DISK_NAME \ --source-disk-zone=$(gcloud config get-value compute/zone)
Clean up
To avoid incurring further costs after you have completed this process, youcan delete the resources that you created:
Delete the disk:
gcloud compute disks delete $DISK_NAME \ --zone=$(gcloud config get-value compute/zone) \ --quiet
Delete the image:
gcloud compute images delete $DISK_NAME
What's next
Learn how tocreate custom images.
Learn how tomanage access to custom images.
Learn more aboutWindows workloads on Compute Engine.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-02 UTC.