resize root partition on boot automatically, access instance using ssh public key, update vm hostname to match the name given and process user data and other metadata on the vm<\/em>.<\/p>\n\n\n\nOnce the vm boots, login and install cloud-init package;<\/p>\n\n\n\n
sudo apt install cloud-init<\/code><\/pre>\n\n\n\n\/etc\/cloud\/cloud.cfg<\/code> is the cloud-init configuration file and this is how it looks by default;<\/p>\n\n\n\ncat \/etc\/cloud\/cloud.cfg<\/code><\/pre>\n\n\n\n# The top level settings are used as module\n# and system configuration.\n# A set of users which may be applied and\/or used by various modules\n# when a 'default' entry is found it will reference the 'default_user'\n# from the distro configuration specified below\nusers:\n - default\n\n\n# If this is set, 'root' will not be able to ssh in and they\n# will get a message to login instead as the default $user\ndisable_root: true\n\n# This will cause the set+update hostname module to not operate (if true)\npreserve_hostname: false\n\n# If you use datasource_list array, keep array items in a single line.\n# If you use multi line array, ds-identify script won't read array items.\n# Example datasource config\n# datasource:\n# Ec2:\n# metadata_urls: [ 'blah.com' ]\n# timeout: 5 # (defaults to 50 seconds)\n# max_wait: 10 # (defaults to 120 seconds)\n\n\n\n\n# The modules that run in the 'init' stage\ncloud_init_modules:\n - migrator\n - seed_random\n - bootcmd\n - write-files\n - growpart\n - resizefs\n - disk_setup\n - mounts\n - set_hostname\n - update_hostname\n - update_etc_hosts\n - ca-certs\n - rsyslog\n - users-groups\n - ssh\n\n# The modules that run in the 'config' stage\ncloud_config_modules:\n - snap\n - ssh-import-id\n - keyboard\n - locale\n - set-passwords\n - grub-dpkg\n - apt-pipelining\n - apt-configure\n - ubuntu-advantage\n - ntp\n - timezone\n - disable-ec2-metadata\n - runcmd\n - byobu\n\n# The modules that run in the 'final' stage\ncloud_final_modules:\n - package-update-upgrade-install\n - fan\n - landscape\n - lxd\n - ubuntu-drivers\n - write-files-deferred\n - puppet\n - chef\n - mcollective\n - salt-minion\n - reset_rmc\n - refresh_rmc_and_interface\n - rightscale_userdata\n - scripts-vendor\n - scripts-per-once\n - scripts-per-boot\n - scripts-per-instance\n - scripts-user\n - ssh-authkey-fingerprints\n - keys-to-console\n - install-hotplug\n - phone-home\n - final-message\n - power-state-change\n\n# System and\/or distro specific settings\n# (not accessible to handlers\/transforms)\nsystem_info:\n # This will affect which distro class gets used\n distro: ubuntu\n # Default user name + that default users groups (if added\/used)\n default_user:\n name: ubuntu\n lock_passwd: True\n gecos: Ubuntu\n groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]\n sudo: [\"ALL=(ALL) NOPASSWD:ALL\"]\n shell: \/bin\/bash\n network:\n renderers: ['netplan', 'eni', 'sysconfig']\n # Automatically discover the best ntp_client\n ntp_client: auto\n # Other config here will be given to the distro class and\/or path classes\n paths:\n cloud_dir: \/var\/lib\/cloud\/\n templates_dir: \/etc\/cloud\/templates\/\n package_mirrors:\n - arches: [i386, amd64]\n failsafe:\n primary: http:\/\/archive.ubuntu.com\/ubuntu\n security: http:\/\/security.ubuntu.com\/ubuntu\n search:\n primary:\n - http:\/\/%(ec2_region)s.ec2.archive.ubuntu.com\/ubuntu\/\n - http:\/\/%(availability_zone)s.clouds.archive.ubuntu.com\/ubuntu\/\n - http:\/\/%(region)s.clouds.archive.ubuntu.com\/ubuntu\/\n security: []\n - arches: [arm64, armel, armhf]\n failsafe:\n primary: http:\/\/ports.ubuntu.com\/ubuntu-ports\n security: http:\/\/ports.ubuntu.com\/ubuntu-ports\n search:\n primary:\n - http:\/\/%(ec2_region)s.ec2.ports.ubuntu.com\/ubuntu-ports\/\n - http:\/\/%(availability_zone)s.clouds.ports.ubuntu.com\/ubuntu-ports\/\n - http:\/\/%(region)s.clouds.ports.ubuntu.com\/ubuntu-ports\/\n security: []\n - arches: [default]\n failsafe:\n primary: http:\/\/ports.ubuntu.com\/ubuntu-ports\n security: http:\/\/ports.ubuntu.com\/ubuntu-ports\n ssh_svcname: ssh\n<\/code><\/pre>\n\n\n\nIn most cases, the default settings works fine.<\/p>\n\n\n\n
If you want to update hosts file to use the name of the vm, add the line manage_etc_hosts: true<\/code><\/strong> to cloud.cfg file.<\/p>\n\n\n\nCreate Custom Linux Image into OpenStack<\/h3>\n\n\n\nCopy the Image to OpenStack<\/h4>\n\n\n\n
Shutdown the virtual machine from the virt-manager<\/code><\/strong> or from command line.<\/p>\n\n\n\nOn the host running KVM, you can find the image details;<\/p>\n\n\n\n
qemu-img info \/media\/kifarunix\/vol02\/kvm\/images\/ubuntu22.04.qcow2<\/code><\/pre>\n\n\n\nimage: \/media\/kifarunix\/vol02\/kvm\/images\/ubuntu22.04.qcow2\nfile format: qcow2\nvirtual size: 6 GiB (6442450944 bytes)\ndisk size: 3.73 GiB\ncluster_size: 65536\nFormat specific information:\n compat: 1.1\n lazy refcounts: true\n refcount bits: 16\n corrupt: false\n<\/code><\/pre>\n\n\n\nCopy its image to OpenStack node;<\/p>\n\n\n\n
rsync -avP path\/vm-name.qcow2 username@openstack:<\/code><\/pre>\n\n\n\nYou can now either create OpenStack Image from Horizon or create it on command line.<\/p>\n\n\n\n