Skip to content

Instantly share code, notes, and snippets.

@longtian
Last active August 24, 2024 15:51
Show Gist options
  • Save longtian/499261f4c68f0fb40b481bb1e74aa8ca to your computer and use it in GitHub Desktop.
Save longtian/499261f4c68f0fb40b481bb1e74aa8ca to your computer and use it in GitHub Desktop.
cloud-init for alpine on proxmox

Enable cloud-init for a Alpine VM on proxmox

alpine version 3.17.4 cloud-init version 22.4

Install

Download alpine-virt-3.17.4-x86_64.iso Uploda to PVE Create a VM Boot From ISO

Script

SWAP_SIZE=0 setup-alpine

keyboard: us
variant: us
hostname: alpine
interface: eth0
ip: dhcp
timezone: Asia/Shanghai
proxy: none
mirrors: 51
network: DHCP

reboot

Configure

  • add cloud-init device
  • enable qemu guest agent
  • remove iso device

Start

apk add vim 

vim /etc/apk/repositories

apk add cloud-init qemu-guest-agent e2fsprogs-extra ca-certificates
echo iso9660 > /etc/modules-load.d/iso9660.conf
wget "" -o /etc/cloud/cloud.cfg

cd /etc/profile.d
mv color_promot.sh.disable color_promot.sh


rc-update add qemu-guest-agent boot
setup-cloud-init

## Tweak

cloud-init status -l
cloud-init clean --logs 
cloud-init query userdata
poweroff
# The top level settings are used as module
# and base configuration.
# A set of users which may be applied and/or used by various modules
# when a 'default' entry is found it will reference the 'default_user'
# from the distro configuration specified below
users:
- default
# If this is set, 'root' will not be able to ssh in and they
# will get a message to login instead as the default $user
disable_root: false
mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
resize_rootfs_tmp: /dev
ssh_pwauth: false
# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: false
# If you use datasource_list array, keep array items in a single line.
# If you use multi line array, ds-identify script won't read array items.
# Example datasource config
# datasource:
# Ec2:
# metadata_urls: [ 'blah.com' ]
# timeout: 5 # (defaults to 50 seconds)
# max_wait: 10 # (defaults to 120 seconds)
datasource_list: ['NoCloud']
runcmd:
- hostname | figlet > /etc/motd
# The modules that run in the 'init' stage
cloud_init_modules:
- migrator
- seed_random
- bootcmd
- write-files
- growpart
- resizefs
- disk_setup
- mounts
- set_hostname
- update_hostname
- update_etc_hosts
- resolv_conf
- ca-certs
- rsyslog
- users-groups
- ssh
# The modules that run in the 'config' stage
cloud_config_modules:
- locale
- set-passwords
- apk-configure
- ntp
- timezone
- disable-ec2-metadata
- runcmd
# The modules that run in the 'final' stage
cloud_final_modules:
- package-update-upgrade-install
- write-files-deferred
- puppet
- chef
- ansible
- mcollective
- salt-minion
- rightscale_userdata
- scripts-vendor
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- scripts-user
- ssh-authkey-fingerprints
- keys-to-console
- install-hotplug
- phone-home
- final-message
- power-state-change
# System and/or distro specific settings
# (not accessible to handlers/transforms)
system_info:
# This will affect which distro class gets used
distro: alpine
# Default user name + that default users groups (if added/used)
default_user:
name: root
lock_passwd: False
shell: /bin/ash
# Other config here will be given to the distro class and/or path classes
paths:
cloud_dir: /var/lib/cloud/
templates_dir: /etc/cloud/templates/
ssh_svcname: sshd
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
@JulianVennen
Copy link

If anyone else is wondering what they're supposed to do in /etc/apk/repositories:
You need to uncomment the community repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment