Proxmox | Cloud-Init initialization using FreeBSD VM QCOW2 image

Hello!
I managed to successfully clone the FreeBSD images for versions 12.3 and 13.0 but I have two small issues with the "FreeBSD - cloudinit" combination.
Specifically, I intend to activate the `sshd` service from the first boot and set the root user password.
The lines below do exactly the right thing in Linux but not in FreeBSD.

YAML:
chpasswd:
  list: |
     root:RANDOM-PASSWORD
  expire: True


YAML:
runcmd:
  - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config
  - sed -i -e ' root' /etc/ssh/sshd_config
  - systemctl restart sshd

Any tip is welcome.

EDIT: I realised that default images don't have cloud-init installed.
 
sed -i on linux means inline editing, on FreeBSD it means extension.
There is no equivalent to linux sed -i. On FreeBSD you will need to use intermediate files.
 
sed -i on linux means inline editing, on FreeBSD it means extension.
There is no equivalent to linux sed -i. On FreeBSD you will need to use intermediate files.
No. On FreeBSD -i requires an argument, on Linux that argument is optional. sed -i "" ... will work the same on Linux and FreeBSD.

Code:
     -i extension
             Edit files in-place similarly to -I, but treat each file
             independently from other files.  In particular, line numbers in
             each file start at 1, the “$” address matches the last line of
             the current file, and address ranges are limited to the current
             file.  (See Sed Addresses.) The net result is as though each file
             were edited by a separate sed instance.

The lines below do exactly the right thing in Linux but not in FreeBSD.
Note that systemctl restart sshd obviously won't work on FreeBSD. If you use service sshd restart then it'll work on both Linux and FreeBSD.
 
No. On FreeBSD -i requires an argument, on Linux that argument is optional. sed -i "" ... will work the same on Linux and FreeBSD.

Code:
     -i extension
             Edit files in-place similarly to -I, but treat each file
             independently from other files.  In particular, line numbers in
             each file start at 1, the “$” address matches the last line of
             the current file, and address ranges are limited to the current
             file.  (See Sed Addresses.) The net result is as though each file
             were edited by a separate sed instance.


Note that systemctl restart sshd obviously won't work on FreeBSD. If you use service sshd restart then it'll work on both Linux and FreeBSD.
Thank you for feedback!
Is there any way to include cloud-init into default VM template without rebuilding it?
 
Back
Top