Create a persistent disk image from an ISO file

Windows

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

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

  1. In the Google Cloud console, openCloud Shell by clicking theActivate Cloud ShellActivate Cloud Shell.button.

    Go to the Google Cloud console

  2. 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

  1. In the Google Cloud console,create a Cloud Storage bucket.

    Go to the Google Cloud console

  2. Upload the ISO file.

    Depending on the size of the ISO file, the upload can take severalminutes or hours.

  3. In theStorage browser, navigate tothe uploaded object.

  4. On theObject details page, copy the URI of the object. The URIstarts withgs://.

  5. OpenCloud Shell by clicking theActivate Cloud ShellActivate Cloud Shell.button.

    Go to the Google Cloud console

  6. Create an environment variable for the download URL. ReplaceURI 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:

  1. From Cloud Shell, specify the name that you want to assign to the newdisk:

    DISK_NAME=iso
  2. 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.

  3. Create a startup script for the temporary VM. The startup script performsthe following actions:

    1. Format the secondary disk with the NTFS file system.
    2. Download the ISO file from the HTTP or Cloud Storage URL youspecified.
    3. 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
  4. 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)
  5. 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
  6. 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 parameterauto-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:

  1. 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:

  1. Delete the disk:

    gcloud compute disks delete $DISK_NAME \    --zone=$(gcloud config get-value compute/zone) \    --quiet
  2. Delete the image:

    gcloud compute images delete $DISK_NAME

What's next

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.