Score:0

Creating and mounting a disk using cloud-init after a server is installed

cn flag

Is it actually possible to run cloud-init to create a disk after the VM itself has been created?

I have a VM created on a VMware platform. Currently cloud-init is not enabled on the GUI for creating VMs. I am trying to attach a newly-created disk. This appears as sdb but is not formatted or mounted.

I can create the disk manually using:

fdisk /dev/sdb
mkfs -t ext4 /dev/sdb1
mount /dev/sdb1 /data

but obviously this leaves me with a non-reproducible installation, and I'd rather this stuff was defined in the cloud-init file.

I have tried including this in the cloud-init file:

# Disk
resize_rootfs: false

disk_setup:
#  /dev/sda:
#    table_type: 'mbr'
#    layout: true
#    overwrite: false
  /dev/sdb:
    table_type: 'mbr'
    layout: true
    overwrite: false

fs_setup:
#  - label: root_fs
#    filesystem: 'ext4'
#    device: /dev/sda
#    partition: auto
#    overwrite: false
  - label: data1
    filesystem: 'ext4'
    device: /dev/sdb
    partition: auto
    overwrite: false

mounts:
  - ['/dev/sdb1', '/data']

then running it using

sudo DI_LOG=stderr /usr/lib/cloud-init/ds-identify --force
sudo cloud-init clean --logs
sudo cloud-init init --local
sudo cloud-init init

which I understand will run cloud-init as if it were instantiated upon first boot install. I have confirmed the file is being run as I've tested this by adding a write_files section to write a test file successfully.

However, this disk creation seems not to take effect.

(Do I actually need to include the pre-existing disk, or is it enough to show only additions in disk_setup and fs_setup?)

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.