XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Ubuntu 22 Cloud Init/Config Network & Partition Assistance

    Scheduled Pinned Locked Moved Xen Orchestra
    11 Posts 3 Posters 8.5k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L Offline
      Lulina
      last edited by

      Good day

      Hope everyone is well 🙂

      I have begun to look into using Cloud Config to make it a simpler process to push out new VMs

      This is for Ubuntu 22.04, the only variables I'd want to input would be the hostname, a static IP, disk space and install specified packages

      So far I managed to get the config template to install the VM with the custom hostname
      I still have trouble getting the network config working and having the new VM make use of the entire assigned disk space. The new VM will only use the original template VM's disk space (10GBs) and not extend the volume with entered disk space value

      My current network template:

      #network:
        version: 1
      config:
        - type: physical
          name: eth0
          subnets:
            type: static
            address: 129.232.201.212/26
            gateway: 129.232.201.193
      dns_nameservers:
        - 8.8.8.8
        - 1.1.1.1
      

      Current user config

      #cloud-config
      hostname: TEST
      growpart:
          mode: 'on'
      resize_rootfs: true
      package_update: true
      packages:
        - htop
        - whois
      

      My process for creating the template:

      1. Install Ubuntu 22.04
      2. Install Guest tools
      3. apt update && sudo apt upgrade
      4. Reboot
      5. apt purge cloud-init cloud-initramfs-dyn-netconf cloud-initramfs-copymods -y
      6. rm -rf /etc/cloud/; rm -rf /var/lib/cloud/
      7. apt update && apt full-upgrade -y
      8. apt install cloud-initramfs-dyn-netconf cloud-initramfs-copymods cloud-initramfs-growroot -y
      9. cloud-init clean

      Remove/Clear the following:
      10.a rm /etc/cloud/cloud.cfg.d/99-installer.cfg
      10.b rm /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg
      10.c rm /etc/netplan/00-installer-config.yaml
      10.d rm -rf /tmp/* && rm -rf /var/tmp/*
      10.e rm -f /etc/ssh/ssh_host_*
      10.f truncate -s 0 /etc/hostname && truncate -s 0 /etc/machine-id

      1. Edit cloud.cfg
        Here I only commented out the default users, as the users I set won't need to change

      2. apt autoremove && apt clean

      3. cloud-init clean && cloud-init clean --logs

      Shutdown and convert to template

      I believe my error is the disk and network are not defined in cloud.cfg

      Would anyone be able to assist with examples or suggest how to correctly define the volumes and network interface

      I will happy to provide any additional information or logs

      Thank you 🙂

      G 1 Reply Last reply Reply Quote 0
      • G Offline
        gsrfan01 @Lulina
        last edited by

        @Lulina

        My cloud-inits are below, I don't mess around with building my own templates and just download the pre-made Ubuntu ones: https://cloud-images.ubuntu.com/jammy/

        #cloud-config
        hostname: {name}
        timezone: America/New_York
        users:
          - default
          - name: netserv
            passwd: passwordhash
            ssh_import_id:
              - gh:guthub_account
            sudo: ALL=(ALL) NOPASSWD:ALL
            groups: users, admin, sudo
            shell: /bin/bash
            lock_passwd: true
            ssh_authorized_keys:
              - ssh-ed25519 yourkey
        package_update: true
        packages:
          - xe-guest-utilities
        package_upgrade: true
        runcmd:
          - sudo reboot
        

        And network, though this is no longer the correct way to handle it, I've yet to update

        version: 2
        ethernets:
            eth0:
                dhcp4: false
                dhcp6: false
                addresses:
                  - 172.16.100.185/24
                gateway4: 172.16.100.1
                nameservers:
                  addresses:
                    - 172.16.100.21
                    - 172.16.100.22
                    - 1.1.1.1
                  search:
                    - dev.themaw.tech
        
        L 1 Reply Last reply Reply Quote 0
        • L Offline
          Lulina @gsrfan01
          last edited by

          @gsrfan01
          Hi there!

          Thank you for taking the time to reply, I will try out your example inits

          I initially went with setting up my own template since I have several golden disks to use

          So you only use those above inits and don't modify cloud.cfg at all?

          I appreciate the help!

          1 Reply Last reply Reply Quote 0
          • G Offline
            gsrfan01
            last edited by

            No modifications at all. I download the OVA, import into Xen Orchestra, usually change the cpu to 2 cores and ram to 2gb, then convert to template.

            I select the template and the cloud configs when creating a new VM. It expands the file system, sets up the user, imports SSH keys, updates packages, installs the tools, then reboots.

            You can expand it to add addition users, keys, packages, etc.

            R L 2 Replies Last reply Reply Quote 0
            • R Offline
              rajudm @gsrfan01
              last edited by

              @gsrfan01 I have taken up XCP-NG for setting up home lab (K8s), and would take your suggestions in creating the template. I would post any issues encountered here to bring up VM instances. thanks

              1 Reply Last reply Reply Quote 0
              • L Offline
                Lulina @gsrfan01
                last edited by

                @gsrfan01
                Good day Gsrfan

                I have managed to get the network going using your example network init, thank you it helped a bunch!

                So far I can't access the test VM, the default ubuntu user and my custom user don't accept the credentials.
                I have seen online it's possible to define the ssh keys in the init, is it a simple enough alternative to Github?

                Thank you 🙂

                R 1 Reply Last reply Reply Quote 0
                • R Offline
                  rajudm @Lulina
                  last edited by

                  @Lulina I was trying to have the cloud config and network saved but got error with redis. I couldn't progress further. Do you have the template for those configs.

                  L 1 Reply Last reply Reply Quote 0
                  • L Offline
                    Lulina @rajudm
                    last edited by

                    @rajudm
                    Hi there

                    We just need some more info from your side
                    What error did you get?
                    Which distro are you using to deploy the VMs?

                    R 1 Reply Last reply Reply Quote 0
                    • R Offline
                      rajudm @Lulina
                      last edited by

                      @Lulina using cloud image from ubuntu 22.04 --> ubuntu-22.04-server-cloudimg-amd64.ova

                      While creating config's i get errors

                      what would be the ideal cloud config and network config for the following.

                      Cloud config
                      Name
                      Template
                      #cloud-config
                      #hostname: {name}%
                      #ssh_authorized_keys:

                      - ssh-rsa <myKey>

                      #packages:

                      - htop

                      0 items
                      ID Name
                      No items found
                      Network config
                      Name
                      Template

                      With the same image got the VM template created and VM created in proxmox following Jay Linux's video. A similar one is required for XCP-NG to make popular in community edition. I was looking at exporting from Proxmox and Importing into XCP-NG. Not sure if that would work either given the networking variability among hypervisors.

                      G 1 Reply Last reply Reply Quote 0
                      • G Offline
                        gsrfan01 @rajudm
                        last edited by

                        If you don't want to import Github keys at all, you can remove that portion and specify it under ssh_authorized_keys for each user built from cloud-init.

                        #cloud-config
                        hostname: {name}
                        timezone: America/New_York
                        users:
                          - default
                          - name: YOURUSER
                            passwd: YOURPASSWORDHASH
                            sudo: ALL=(ALL) NOPASSWD:ALL
                            groups: users, admin, sudo
                            shell: /bin/bash
                            lock_passwd: true
                            ssh_authorized_keys:
                              - ssh-rsa YOURKEY
                        package_update: true
                        packages:
                          - xe-guest-utilities
                          - htop
                        package_upgrade: true
                        

                        If you want to be able to log in from the console instead of only SSH using keys, change lock_passwd: true to lock_passwd: false

                        1 Reply Last reply Reply Quote 0
                        • L Offline
                          Lulina
                          last edited by

                          Hi there Gsrfan

                          Apologies for the delayed response, I had to shelf this passion project to focus on other work
                          So far managed to get the host, static IP, packages, users & their keys/password etc sorted with the init

                          I was working last on lvm partitions, to grow them and that ended up a bit of a mess

                          I might return to this at a later stage but I found your help and advice invaluable to getting the config to where it is now

                          Thank you so much 🙂

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post