Skip to main content

Windows Host: Create Cloud-Init ISO File

Example comes from my VirtualBox cybersecurity lab project

mkdir "$env:USERPROFILE\Desktop\cloud-init-iso"
[System.IO.File]::WriteAllText("$env:USERPROFILE\Desktop\cloud-init-iso\meta-data", @"
instance-id: i-$(Get-Random)
local-hostname: test-server
"@, [System.Text.UTF8Encoding]::new($false))

PowerShell v5+ compatible way to create meta-data file with UTF8 encoding

user-data example below assumes a username of ubuntu and sets the password accordingly

[System.IO.File]::WriteAllText("$env:USERPROFILE\Desktop\cloud-init-iso\user-data", @"
#cloud-config
chpasswd:
  list: |
    ubuntu:password123
  expire: false
ssh_pwauth: true
"@, [System.Text.UTF8Encoding]::new($false))

PowerShell v5+ compatible way to create user-data file with UTF8 encoding

& 'C:\Program Files\Oracle\VirtualBox\vbox-img.exe' createiso `
-o "$env:USERPROFILE\Desktop\cloud-init.iso" `
--volid "cidata" `
"$env:USERPROFILE\Desktop\cloud-init-iso\user-data" `
"$env:USERPROFILE\Desktop\cloud-init-iso\meta-data"

Uses the vbox-img.exe utility to create the .iso file which should be attached as an additional CD-ROM on the target VM