Create Custom Image from GCP VM with OS and data disks - google-cloud-platform

I set up centos and windows VMs in Google Cloud which has many custom installations and configuration, with 1 boot disk and 4 data disks.
I am trying to create an image of both VMs. Only options I see in google cloud to create an image from disk, snapshot, another image, cloud file or virtual disk.
Looking for some way to create an image at VM level, which I can reuse to create new VMs something similar to custom ami in AWS or custom image in Azure.
The intention is if I create VM out of that image, my new VM will come up with all 5 disks. On GCP console, when I try to create an image, it has no option of using whole VM as a source instead, I can choose single disk as source.
Is there any way or workaround to achieve this in Google Cloud?
Thanks in advance.

I found GCP Instance Templates as a solution to my problem. I can reuse Instance Templates to deploy my custom VMs.

Related

How to get CentOS 8 option available as a VM option in GCP / GCE?

How would I go about getting CentOS 8 as a VM option in GCP/GCE? or creating my own CentOS 8 VM to run on GCP?
Any guides (README's, documents) there or contacts on how to get this done?
There is an article on GCP that talks about a technique/recipe for creating a boot image that is custom. The article is called Manually importing virtual disks. If I understand the basics of the story, you could use a technology such as VirtualBox to create a local VM image and then prepare that for import into Google Cloud Storage. From there, one could then seem to use that as a source for a new Compute Engine instance.
Currently GCP supports Centos-7 as a public image. As suggested by the previous member you can create a Custom image from source disks, images, snapshots, or images stored in Cloud Storage.
See instructions HERE
Your other option is to wait for Google to introduce Centos-8 in their supported family
Centos 8 is already available on GCE but it is without shielded VM support.

GCP - moving VMs across projects with the Google Cloud SDK

I want to move some VMs across projects on GCP using the Cloud SDK.
I'd like the process on a high level, and then possibly also some links out to the relevant docs, although I can RTFM when I know what the general high-level steps are.
I think what I want to do is
Create a snapshot
Save it somewhere
Create two Cloud SDK contexts?
Prepare a destination in the context for the new project
Copy the snapshots over to the new context and its associated storage
Rehydrate from the copied snapshot in the new project once everything is copied.
Please help. I'm new with this stuff and want to know whether this is really how it should be done.
Thanks!
You can use this guide
Quick summary of steps needed
Detach the boot disk from the VM that you intend to move by deselecting “Delete boot disk on instance delete” and terminating the VM
Create an image from the detached boot disk
Upload the image to Google Cloud Storage and share it with the new project
Create a custom image under the new project based on the image you uploaded to Google Cloud Storage
Create a new VM instance under the new project based on the custom image

How to enable Nested Virtualization on an existing Google cloud VM instance?

I'm trying to enable Nested Virtualization on a existing VM instance. The VM is on the Intel Haswell CPU platform so Nested Virtualization is possible.
Now I've read this support article at Google: https://cloud.google.com/compute/docs/instances/enable-nested-virtualization-vm-instances
Under the first section Enabling nested virtualization on an instance it says the following:
Create a boot disk from a public image or from a custom image with an
operating system. Alternatively, you can skip this step and apply
the license to an existing disk from one of your VM instances.
However I can't figure out how to apply the Nested Virtualization license to an existing VM instance. The only steps described are for new disks and I want to apply it to an existing disk.
My question is: How can I enable Nested Virtualization on a existing Google Cloud Instance?
Thanks in advance,
Hugo.
I will share with you instructions on how to enable Nested Virtualization on an existing GCP VM instance. More detailed steps are described in the article you shared.
From your existing VM instance, you should already have a boot disk in your project. If not, you should create a boot disk from that VM instance.
Using the boot disk from that existing VM instance, please create a custom image with the special license key required for virtualization.
a- If you are creating an image using the gcloud command-line tool, provide the following license URL using the --licenses flag:
https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx
For example, the following command creates an image named nested-vm-image from an example disk named disk1:
$ gcloud compute images create nested-vm-image \
--source-disk disk1 --source-disk-zone us-central1-b \
--licenses "https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
b- If you are using the API, please include the licenses property in your API request:
POST https://www.googleapis.com/compute/v1/projects/[PROJECT_ID]/global/images
{
"licenses": ["projects/vm-options/global/licenses/enable-vmx"],
"name": "nested-vm-image",
"sourceDisk": "zones/us-central1-b/disks/disk1"
}
where [PROJECT_ID] is your project ID.

Which method is best to create Google Cloud VM from existing VM?

Cloning VM from console?
I tried this solution but changes inside VM before cloning are not available in new VM
Create snapshot from bootdisk and then use snapshot to create VM.
Use existing boot disk when creating VM from select boot disk popup.
Create new Image form snapshot and use that Image to create the VM.
Since you asked the best, it will be #4 (Create new Image form snapshot and use that Image to create the VM.). This will give you an option to refer to the image by family name while doing the automation. Also it will help you version the image and deprecate the older image etc.

Create Google Cloud instance with custom ISO

I want to create a new Google Cloud Compute Engine instance with Ubuntu 18.04 LTS. I tried doing it with the inbuilt image and tried to set up an Ubuntu desktop with VNC. I did end up getting everything to work but felt it was too much of a hassle to install a desktop environment and set up a VNC service.
So I was wondering how I could upload a desktop Ubuntu ISO to Google Cloud and using that as the starting image for a Google Cloud Compute Engine instance.
In order to create custom images there are two possible way:
You can create custom images of boot disks and use these images to create new instances. This is ideal for situations where you have created and modified a persistent boot disk to a certain state and need to save that state to create new instances.
Alternatively, you can import boot disk images to Compute Engine from your existing systems and add them to your custom images list.
There is a whole section of the Google Documentation "How-to" regarding the creation of Custom images that I advise you to follow.
In particular I believe you are interested how to import a Boot Disk to Compute engine.
Shortly the steps are the following:
Plan your import path. You must identify where you are going to prepare your boot disk image before you upload it, and how you are going to connect to that image after it boots in the Compute Engine environment.
Prepare your boot disk so it can boot within the Compute Engine environment and so you can access it after it boots.
Create and compress the boot disk image file.
Upload the image file to Google Cloud Storage and import the image to Compute Engine as a new custom image.
Use the imported image to create a virtual machine instance and make sure it boots properly.
If the image does not successfully boot, you can troubleshoot the issue by attaching the boot disk image to another instance and reconfiguring it.
Optimise the image and install the Linux Guest Environment so that your imported operating system image can communicate with the metadata server and use additional Compute Engine features.