Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper configuration using a nocloud iso image #25

Open
alexsarmiento opened this issue Nov 21, 2021 · 1 comment
Open

Proper configuration using a nocloud iso image #25

alexsarmiento opened this issue Nov 21, 2021 · 1 comment

Comments

@alexsarmiento
Copy link

The provided "vmbuilders/ubuntu.sh" is a good start but it didn't work for me to configure the ubuntu cloud image: The openssh-server failed to initialize, my user was not created, no network connection. Instead of using the initramfs we can just provide an iso image with the necessary 'user-data' and 'meta-data' files to initialize the image at the first boot.

# create cloudinit config iso
rm -rf iso_folder seed.iso
mkdir iso_folder

cat << EOF > iso_folder/user-data
#cloud-config
users:
  - default
  - name: $USER
    lock_passwd: False
    gecos: $USER
    groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
    ssh-authorized-keys:
      - $(cat ~/.ssh/id_rsa.pub | head -n 1)
bootcmd:
  - apt remove -y irqbalance
network:
    version: 2
    renderer: networkd
    ethernets:
        enp0s1:
            dhcp4: true
EOF

Plenty of examples here. Then to create the iso file:

touch iso_folder/meta-data

hdiutil makehybrid -iso -joliet -iso-volume-name cidata -joliet-volume-name cidata -o seed.iso iso_folder

Then add the seed.iso file to the vm.conf

cat << EOF > vm.conf
kernel=vmlinux
initrd=initrd
cmdline=console=hvc0 irqfixup root=/dev/vda
cpu-count=1
memory-size=1024
disk=disk.img
cdrom=seed.iso
network=nat
EOF

There's no need to launch the initramfs anymore to edit the image. The openssh initialization, user creation and networking do work for me now. Full example: https://gist.github.com/alexsarmiento/c52874738c3bdb96424c57b297b2678d

@dmarkey
Copy link

dmarkey commented Mar 24, 2022

FYI, this gave me an idea, so using cloud-init nocloud, I cobbled together a project to make using Virtualization.Framework easier.

This is it if you want to give it a go: https://github.com/dmarkey/macos-virt

Thanks so much to @gyf304 for the starting point and the POC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants