<button class="button button-with-icon cloud-select-dropdown__button button-primary" aria-haspopup="true">Version 1.12 </button>

- [Latest](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/latest/vm-runtime/create-manage-disks)
- [Version 1.16](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.16/vm-runtime/create-manage-disks.md.txt)
- [Earlier versions (unsupported)](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/getting-support.md.txt#version-support)

<br />

This document is intended for application owners that run Google Distributed Cloud.
This document shows you how to create and manage disk resources for virtual
machines (VMs) that use VM Runtime on Google Distributed Cloud.

## Before you begin

To complete this document, you need access to the following resources:

- Access to Google Distributed Cloud version 1.12.0 (`anthosBareMetalVersion: 1.12.0`) or higher cluster. You can use any cluster type capable of running workloads. If needed, [try Google Distributed Cloud on Compute Engine](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/try/gce-vms.md.txt) or see the [cluster creation overview](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/installing/creating-clusters/create-clusters-overview.md.txt).
- The `virtctl` client tool installed as a plugin for `kubectl`. If needed, [install the virtctl client tool](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/quickstart.md.txt#install_the_virtctl_client_tool).

## Create a VM with an attached disk

When you create a VM, you can attach an existing boot or data disk, create a
disk from an image (including for the boot disk), or create a blank disk.

### Blank disk

In this scenario, you create a blank disk and attach it to the VM. This
scenario lets you create a data disk to store application data.

1. Create a manifest that defines a `VirtualMachineDisk` and `VirtualMachine`,
   such as *my-vm.yaml,* in the editor of your choice:

   ```bash
   nano my-vm.yaml
   ```
2. Copy and paste the following YAML definition:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachineDisk
   metadata:
     name: DISK_NAME
   spec:
     size: 10Gi
   ---
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachine
   metadata:
     name: VM_NAME
   spec:
     interfaces:
       - name: eth0
         networkName: pod-network
         default: true
     disks:
       - boot: true
         virtualMachineDiskName: VM_NAME-boot-dv
       - virtualMachineDiskName: DISK_NAME
   ```

   This example creates a blank `10Gi` (10 gibibyte) disk named
   `DISK_NAME`. In the VM's `spec.disks`
   section, you must also attach a boot disk, such as from an image as shown in
   the next section.
3. Save and close the manifest file in your editor.

4. Create the VM and disk using `kubectl`:

   ```bash
   kubectl apply -f my-vm.yaml
   ```

### From image

In this scenario, you create a disk from an image and attach it to the VM. This
scenario lets you create a boot disk, for example, from an image. You can also
create and attach data disks from an image.

1. Create a manifest that defines a `VirtualMachineDisk` and `VirtualMachine`,
   such as *my-vm.yaml,* in the editor of your choice:

   ```bash
   nano my-vm.yaml
   ```
2. Copy and paste the following YAML definition:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachineDisk
   metadata:
     name: VM_NAME-boot-dv
   spec:
     size: 20Gi
     source:
       http:
         url: https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img
   ---
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachine
   metadata:
     name: VM_NAME
   spec:
     interfaces:
       - name: eth0
         networkName: pod-network
         default: true
     disks:
       - boot: true
         virtualMachineDiskName: VM_NAME-boot-dv
   ```

   This example creates a `20Gi` (20 gibibyte) disk named
   `VM_NAME-boot-dv` using a public Ubuntu
   image. In the VM's `spec.disks` section, the disk is set to `boot: true`.

   > [!NOTE]
   > **Note:** To import images from Cloud Storage, see [create and use credentials to import images from Cloud Storage](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/create-storage-credentials.md.txt).

3. Save and close the manifest in your editor.

4. Create the VM and disk using `kubectl`:

   ```bash
   kubectl apply -f my-vm.yaml
   ```

### Existing disk

In this scenario, you create a blank disk and attach it to the VM. This
scenario lets you create a data disk to store application data.

1. Create a `VirtualMachine` manifest, such as *my-vm.yaml,* in the editor of
   your choice:

   ```bash
   nano my-vm.yaml
   ```
2. Copy and paste the following YAML definition:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachine
   metadata:
     name: VM_NAME
   spec:
     interfaces:
       - name: eth0
         networkName: pod-network
         default: true
     disks:
       - boot: true
         virtualMachineDiskName: VM_NAME-boot-dv
       - virtualMachineDiskName: EXISTING_DISK_NAME
   ```

   This example attaches an existing disk named
   `EXISTING_DISK_NAME`.

   In the VM's `spec.disks` section, you must also attach a boot disk, such as
   from an image as shown in the preceding section.
3. Save and close the VM manifest in your editor.

4. Create the VM using `kubectl`:

   ```bash
   kubectl apply -f my-vm.yaml
   ```

## Create and attach disks to existing VM

If you have an existing VM, you can create and attach disks to support your
application lifecycles. The VM must be in a stopped state before you attach a
disk.

### Blank disk

In this scenario, you create a blank disk and attach it to the VM. This
scenario lets you create a data disk to store application data.

1. Use `kubectl` to stop the VM, if needed:

   ```bash
   kubectl virt stop vm VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you want to
   stop.
2. Edit your existing VM resource, such as `my-vm`:

   ```bash
   kubectl edit gvm VM_NAME
   ```
3. Update the `VirtualMachine` YAML manifest to add a `VirtualMachineDisk`
   section at the top, and then attach the disk at the end of the VM's
   `spec.disks` section:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachineDisk
   metadata:
     name: DISK_NAME
   spec:
     size: 10Gi
   ---
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachine
   metadata:
     name: VM_NAME
   spec:
     interfaces:
       - name: eth0
         networkName: pod-network
         default: true
     disks:
       - boot: true
         virtualMachineDiskName: VM_NAME-boot-dv
       - virtualMachineDiskName: DISK_NAME
   ```

   This example creates a blank `10Gi` (10 gibibyte) disk named
   `DISK_NAME`.
4. Save and close the updated VM manifest in your editor.

5. Use `kubectl` to start the VM:

   ```bash
   kubectl virt start vm VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you want to
   start.

### From image

In this scenario, you create a disk from a source image and attach it to the
VM.

1. Use `kubectl` to stop the VM, if needed:

   ```bash
   kubectl virt stop vm VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you want to
   stop.
2. Edit your existing VM resource, such as `my-vm`:

   ```bash
   kubectl edit gvm VM_NAME
   ```
3. Update the `VirtualMachine` manifest to add a `VirtualMachineDisk` section at
   the top, and then attach the disk at the end of the VM's `spec.disks` section:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachineDisk
   metadata:
     name: DISK_NAME
   spec:
     size: 10Gi
     source:
       http:
         url: http://example.com/my-disk-img.qcow2
   ---
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachine
   metadata:
     name: VM_NAME
   spec:
     interfaces:
       - name: eth0
         networkName: pod-network
         default: true
     disks:
       - boot: true
         virtualMachineDiskName: VM_NAME-boot-dv
       - virtualMachineDiskName: DISK_NAME
   ```

   This example creates a `10Gi` (10 gibibyte) disk named
   `DISK_NAME` from the
   `http://example.com/my-disk-img.qcow2` HTTP source.

   > [!NOTE]
   > **Note:** To import images from Cloud Storage, see [create and use credentials to import images from Cloud Storage](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/create-storage-credentials.md.txt).

4. Save and close the updated VM manifest in your editor.

5. Use `kubectl` to start the VM:

   ```bash
   kubectl virt start vm VM_NAME
   ```

   Replace `VM_NAME` with the name of the VM that you want to
   start.

## Create a disk

In this scenario, you create the disk resources separately from the VM
resources. This scenario lets you create disks ahead of time, and then attach to
VMs as needed.

### Blank disk

To create a blank disk, complete the following steps.

1. Create a `VirtualMachineDisk` manifest, such as *my-disk.yaml,* in the editor
   of your choice:

   ```bash
   nano my-disk.yaml
   ```
2. Copy and paste the following YAML definition:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachineDisk
   metadata:
     name: DISK_NAME
   spec:
     size: 10Gi
   ```

   This example creates a blank `10Gi` (10 gibibyte) disk named
   `DISK_NAME`.
3. Save and close the disk manifest in your editor.

4. Create the disk using `kubectl`:

   ```bash
   kubectl apply -f my-disk.yaml
   ```

### From image

To create a disk from an image, complete the following steps.

1. Create a `VirtualMachineDisk` manifest, such as *my-disk.yaml,* in the editor
   of your choice:

   ```bash
   nano my-disk.yaml
   ```
2. Copy and paste the following YAML definition:

   ```yaml
   apiVersion: vm.cluster.gke.io/v1
   kind: VirtualMachineDisk
   metadata:
     name: DISK_NAME
   spec:
     size: 20Gi
     source:
       http:
         url: https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img
   ```

   This example creates a `20Gi` (20 gibibyte) disk named
   `DISK_NAME` using a public Ubuntu image.
3. Save and close the disk manifest in your editor.

4. Create the disk using `kubectl`:

   ```bash
   kubectl apply -f my-disk.yaml
   ```

## What's next

- [Create and use credentials to import images from Cloud Storage](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/create-storage-credentials.md.txt).
- [Create and use storage classes in Google Distributed Cloud](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/storage-classes.md.txt).
- When you no longer need VMs or their virtual disk resources, [Delete a VM in Google Distributed Cloud](https://docs.cloud.google.com/anthos/clusters/docs/bare-metal/1.12/vm-runtime/delete.md.txt).