[Yandex Cloud documentation](../../../index.md) > [Yandex Compute Cloud](../../index.md) > [Step-by-step guides](../index.md) > Dedicated hosts > Creating a VM in a group of dedicated hosts

# Creating a VM in a group of dedicated hosts


The VM you create will be linked to a host from a group of [dedicated hosts](../../concepts/dedicated-host.md). Once stopped, the VM becomes unavailable on the group hosts and can be linked to a different host from the group when you restart it.

If you do not have a group of dedicated hosts yet, [create](create-host-group.md) one.

To create a VM:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder to create your VM in.
  1. Navigate to **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/server.svg) **Virtual machines**.
  1. Click **Create virtual machine**.
  1. [Set](../vm-create/create-linux-vm.md) the required VM parameters.
  1. Expand **Additional**.
  1. Next to **Host affinity rules**, click **Add**.
  1. In the **Type of affinity** field, select **Dedicated host group**.
  1. In the **Dedicated host groups** field, select the groups whose dedicated hosts the VM will be running on.

      {% note tip %}
      
      You can set up multiple [host binding rules](../../concepts/dedicated-host.md#bind-vm), such as a group-based rule and a rule for a specific host.
      
      {% endnote %}

  1. Click **Create VM**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. Get the ID of the dedicated host group to create your VM in:

      ```bash
      yc compute host-group list
      ```

      Result:

      ```bash
      +------------------------------+-------+--------------+-------+---------------+
      |              ID              | CORES |    MEMORY    | DISKS |   DISK SIZE   |
      +------------------------------+-------+--------------+-------+---------------+
      ...
      | intel-6338-c108-m704-n3200x6 |   108 | 755914244096 |     6 | 3198924357632 |
      +------------------------------+-------+--------------+-------+---------------+
      ```

  1. Get a list of available subnets:

      ```bash
      yc vpc subnet list
      ```

      Result:

      ```text
      +----------------------+-----------------------+----------------------+----------------+---------------+-----------------+
      |          ID          |         NAME          |      NETWORK ID      | ROUTE TABLE ID |     ZONE      |      RANGE      |
      +----------------------+-----------------------+----------------------+----------------+---------------+-----------------+
      | b0c6n43f9lgh******** | default-ru-central1-d | enpe3m3fa00u******** |                | ru-central1-d | [10.130.0.0/24] |
      | e2l2da8a20b3******** | default-ru-central1-b | enpe3m3fa00u******** |                | ru-central1-b | [10.129.0.0/24] |
      | e9bnlm18l70a******** | default-ru-central1-a | enpe3m3fa00u******** |                | ru-central1-a | [10.128.0.0/24] |
      +----------------------+-----------------------+----------------------+----------------+---------------+-----------------+
      ```

  1. Run this command to create a VM:

      ```bash
      yc compute instance create \
        --host-group-id <dedicated_host_group_ID> \
        --zone <availability_zone> \
        --platform <platform_ID> \
        --network-interface subnet-name=<subnet_name> \
        --attach-local-disk size=<disk_size>
      ```

      Where:

      * `--host-group-id`: ID of the dedicated host group.
      * `--zone`: [Availability zone](../../../overview/concepts/geo-scope.md) where the group of dedicated hosts resides.
      * `--platform`: [Platform](../../concepts/vm-platforms.md). It must match the platform of the dedicated host group:
        
        * `standard-v3`: For hosts based on Intel<sup>®</sup> Ice Lake.
        * `standard-v2`: For archived hosts based on Intel Cascade Lake.
      * `--network-interface`: VM network interface description:

        * `subnet-name`: Name of the subnet in the availability zone.

      * `--attach-local-disk`: Properties of the local disk being attached to the VM:
        
        * `size`: Disk size in bytes. You can find the possible values in the [list of dedicated host types](../../concepts/dedicated-host.md#host-types-list) and the `yc compute host-type list` command output. For example, for the `intel-6338-c108-m704-n3200x6` host type, specify `3198924357632` (~ 2.91 TB). You cannot set a size different from the host disk size.
        
        The `--attach-local-disk` parameter is optional. To attach multiple local disks, specify this parameter as many times as needed. For more information, see [Local and network disks](../../concepts/dedicated-host.md#resource-disks).

      To specify other VM properties, use the `yc compute instance create` command parameters as described in the [CLI reference](../../../cli/cli-ref/compute/cli-ref/instance/create.md). For more information, see [VMs in Compute Cloud](../../concepts/vm.md) and [Creating a VM](../index.md#vm-create).

      Result:

      ```text
      done (20s)
      id: fhmbdt1jj2k3********
      folder_id: m4n56op78mev********
      created_at: "2020-10-13T07:41:19Z"
      zone_id: ru-central1-a
      ...
      placement_policy:
        host_affinity_rules:
        - key: yc.hostGroupId
          op: IN
          values:
          - abcdefg1hi23********
      ```

- API {#api}

  1. Get the ID of the dedicated host group using the [list](../../api-ref/HostGroup/list.md) REST API method for the [HostGroup](../../api-ref/HostGroup/index.md) resource or the [HostGroupService/List](../../api-ref/grpc/HostGroup/list.md) gRPC API call.
  1. Create a VM using the [create](../../api-ref/Instance/create.md) REST API method for the [Instance](../../api-ref/Instance/index.md) resource or the [InstanceService/Create](../../api-ref/grpc/Instance/create.md) gRPC API call.

{% endlist %}

If you attached local disks to your VM, [partition and mount them](../vm-control/vm-attach-disk.md#mount) after the VM is created.


## Example of creating a VM with a local disk in a group of dedicated hosts {#host-vm-nvme}

Before creating a VM:

1. [Create a group of dedicated hosts](create-host-group.md) and get its ID using the `yc compute host-group list` [CLI command](../../../cli/cli-ref/compute/cli-ref/host-group/list.md).
1. [Generate a key pair](../vm-connect/ssh.md#creating-ssh-keys) to connect to your VM over SSH.

Create a VM with the following parameters:
* Location: Dedicated host group.
* Platform: Intel Ice Lake.
* Number of vCPUs: 64.
* Amount of RAM: 704 GB.
* Number of local disks: 2.
* Size of a local disk: 3,198,924,357,632 B (~ 2.91 TB).
* Operating system: [Ubuntu 22.04 LTS](https://yandex.cloud/en/marketplace/products/yc/ubuntu-22-04-lts).

To do this, follow these steps:

{% list tabs group=instructions %}

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  Run this command to create a VM:

  ```bash
  yc compute instance create \
    --cloud-id <cloud_ID> \
    --folder-id <folder_ID> \
    --zone <availability_zone> \
    --name <VM_name> \
    --platform standard-v3 \
    --cores 64 \
    --memory 704 \
    --host-group-id <dedicated_host_group_ID> \
    --network-interface subnet-id=<subnet_ID> \
    --attach-local-disk "size=3198924357632" \
    --attach-local-disk "size=3198924357632" \
    --ssh-key <path_to_public_SSH_key_file> \
    --create-boot-disk name=boot-disk,size=1000,image-folder-id=standard-images,image-family=ubuntu-2204-lts
  ```

  Where:

  * `--cloud-id`: [Cloud ID](../../../resource-manager/operations/cloud/get-id.md).
  * `--folder-id`: Folder ID.
  * `--zone`: Availability zone where the group of dedicated hosts resides.
  * `--name`: VM name.
  * `--platform`: VM platform.
  * `--cores`: Number of vCPUs.
  * `--memory`: Amount of RAM.
  * `--host-group-id`: ID of the dedicated host group.
  * `--network-interface`: VM network interface description:
    * `subnet-id`: ID of the subnet in the availability zone hosting the VM.
  * `--attach-local-disk`: Description of the local disk being attached:
    * `size`: Disk size.
  * `--ssh-key`: Public SSH key path. The VM will automatically create a user named `yc-user` for this key.
  * `--create-boot-disk`: Boot disk parameters.

  Result:

  ```text
  done (20s)
  id: fhmbdt1jj2k3********
  folder_id: m4n56op78mev********
  created_at: "2023-01-16T12:46:50Z"
  zone_id: ru-central1-a
  ...
  placement_policy:
    host_affinity_rules:
    - key: yc.hostGroupId
      op: IN
      values:
      - abcdefg1hi23********
  ```

{% endlist %}

_Intel is a trademark of Intel Corporation or its subsidiaries._