Answers: <h1>Cloud-init solution</h1>
  <p><code>cloud-init</code> accommodates the partitioning with <a href="https://cloudinit.readthedocs.io/en/latest/topics/examples.html#disk-setup" rel="nofollow noreferrer"><code>disk_setup</code></a></p>
  <pre class="lang-yaml prettyprint-override"><code>disk_setup:
    /dev/vdb:
      table_type: gpt
      layout: true
  </code></pre>
  <p>And the corresponding filesystem initialization with <a href="https://cloudinit.readthedocs.io/en/latest/topics/examples.html#create-partitions-and-filesystems" rel="nofollow noreferrer"><code>fs_setup</code></a></p>
  <pre><code>fs_setup:
  - label: repo
    filesystem: ext4
    device: /dev/vdb1
    partition: auto
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2022-06-10T19:02:08.793Z
Answers: 2022-06-10T19:02:08.793Z
Answers: Evan Carroll
Body: <p>I'm using OpenStack and I am trying to provision a compute resource on it. I want that compute resource to attach to a volume. We have three things in play.</p>
  <ul>
  <li><strong>Volume</strong> <a href="https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/blockstorage_volume_v3" rel="nofollow noreferrer"><code>openstack_blockstorage_volume_v3</code></a></li>
  <li><strong>Compute Resource</strong> <a href="https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/compute_instance_v2" rel="nofollow noreferrer"><code>openstack_compute_instance_v2</code></a></li>
  <li><strong>Mapping/Attachment</strong> <a href="https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/compute_volume_attach_v2" rel="nofollow noreferrer"><code>openstack_compute_volume_attach_v2</code></a></li>
  </ul>
  <p>I need something to,</p>
  <ol>
  <li>Create a partition table on first mount.</li>
  <li>To create a file system (ext4) on first mount.</li>
  <li>To initialize the file system with the things I need.</li>
  </ol>
  <p>Does the logic to initialize this volume typically hang out in the cloud-init for the machine? If I initialize it manually, I can mount it using <a href="https://cloudinit.readthedocs.io/en/latest/topics/examples.html?highlight=mount#adjust-mount-points-mounted" rel="nofollow noreferrer"><code>cloud-init</code>'s directive for <code>mounts</code></a>. But without manually installation, how do we instruct <code>user_data</code> to initialize the volume before if necessary before the mount?</p>
  <p>What I'm trying to do is store the <code>.git</code> file for a monorepo on an external shared mount. What I would like is on first boot of the sandbox for that to be ready. On subsequent boots/refreshes, I would just like them to run <code>git fetch</code> so they only pull down what's necessary rather than needing to re-clone.</p>
  
Tags: <terraform><openstack><volume><cloud-init>
Title: How do you a initialize a new volume without a file system or partition table?
UserDisplayName: Evan Carroll
ThreadText: # How do you a initialize a new volume without a file system or partition table?
  
  (Asked by: username_0 on 2022-03-21)
  
  I'm using OpenStack and I am trying to provision a compute resource on it. I want that compute resource to attach to a volume. We have three things in play.
  
  * **Volume** [`openstack_blockstorage_volume_v3`](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/blockstorage_volume_v3)
  * **Compute Resource** [`openstack_compute_instance_v2`](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/compute_instance_v2)
  * **Mapping/Attachment** [`openstack_compute_volume_attach_v2`](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/compute_volume_attach_v2)
  
  I need something to,
  
  1. Create a partition table on first mount.
  2. To create a file system (ext4) on first mount.
  3. To initialize the file system with the things I need.
  
  Does the logic to initialize this volume typically hang out in the cloud-init for the machine? If I initialize it manually, I can mount it using [`cloud-init`'s directive for `mounts`](https://cloudinit.readthedocs.io/en/latest/topics/examples.html?highlight=mount#adjust-mount-points-mounted). But without manually installation, how do we instruct `user_data` to initialize the volume before if necessary before the mount?
  
  What I'm trying to do is store the `.git` file for a monorepo on an external shared mount. What I would like is on first boot of the sandbox for that to be ready. On subsequent boots/refreshes, I would just like them to run `git fetch` so they only pull down what's necessary rather than needing to re-clone.
  
  **Tags:** terraform, openstack, volume, cloud-init
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-06-10. Score: 0 | Accepted answer
  
  # Cloud-init solution
  
  `cloud-init` accommodates the partitioning with [`disk_setup`](https://cloudinit.readthedocs.io/en/latest/topics/examples.html#disk-setup)
  
  ```yaml
  disk_setup:
    /dev/vdb:
      table_type: gpt
      layout: true
  
  ```
  
  And the corresponding filesystem initialization with [`fs_setup`](https://cloudinit.readthedocs.io/en/latest/topics/examples.html#create-partitions-and-filesystems)
  
  ```
  fs_setup:
  - label: repo
    filesystem: ext4
    device: /dev/vdb1
    partition: auto
  
  ```
  
  
  ---
  
  