How to create alpine linux cloud image

Difference between revision 1 and current revision

Changed:

< # The main thing is needed to build a simple openstack alpine image is to install cloud-init apk package!
< # Optionally qemu-guest-agent for better integration with KVM and e2fsprogs-extra for resizing file system
< # are installed, as well as sudo and acpi
< # Download the latest alpine-virt iso

to

> The main thing is needed to build a simple openstack alpine image is to install cloud-init apk package! Optionally qemu-guest-agent for better integration with KVM and e2fsprogs-extra for resizing file system are installed, as well as sudo and acpi
> - Download the latest alpine-virt iso
>

Changed:

< # Create an empty 512MB image

to

> - Create an empty 512MB image
>

Changed:

< # Boot alpine from the iso file using QEMU (or anything else like VirtualBox or VMWare, in which case you may need to create an appropriate image as raw may not work)
< /usr/bin/qemu-system-x86_64 -drive file=alpine-virt-3.15.4-x86_64.qcow,if=virtio,cache=writeback,discard=ignore,format=qcow2 -drive file=alpine-virt-3.15.4-x86_64.iso,media=cdrom -boot once=d -vnc 0.0.0.0:15 -name alpine -machine type=pc,accel=tcg -netdev bridge,id=user.0,br=virbr0 -m 512M -device virtio-net,netdev=user.0
< # Connect to alpine VM with a VNC client to port 0.0.0.0:5915 if using QEMU.
< # login with root (no password)
< # run "setup-alpine" answering "us us" for keyboard, "alpine" for hostname, "dhcp" for eth0, "sda",
< # "sys" for disk drive, enable "openssh", use "1" mirror for apk, reboot.
< # If volumes are required, then for the disk drive choose "none" and run setup-disk but growpart won't work in this case
< #setup-disk -m sys -L
< # Or with the answer file:

to

> - Boot alpine from the iso file using QEMU (or anything else like VirtualBox or VMWare, in which case you may need to create an appropriate image as raw may not work)
> /usr/bin/qemu-system-x86_64 -drive file=alpine-virt-3.15.4-x86_64.qcow,if=virtio,cache=writeback,discard=ignore,format=qcow2 -drive file=alpine-virt-3.15.4-x86_64.iso,media=cdrom -boot once=d -vnc 0.0.0.0:15 -name alpine -machine type=pc,accel=tcg -netdev bridge,id=user.0,br=virbr0 -m 512M -device virtio-net,netdev=user.0
> - Connect to alpine VM with a VNC client to port 0.0.0.0:5915 if using QEMU.
> - login with root (no password)
> - run "setup-alpine" answering "us us" for keyboard, "alpine" for hostname, "dhcp" for eth0, "sda", "sys" for disk drive, enable "openssh", use "1" mirror for apk, reboot.
> - If volumes are required, then for the disk drive choose "none" and run setup-disk but growpart won't work in this case
> setup-disk -m sys -L
> - Or with the answer file:

Changed:

< # Then:

to

> - Then:

Changed:

< # Enable community apk repo

to

> - Enable community apk repo

Changed:

< # Upgrade All Packages in OneShot

to

> - Upgrade All Packages in OneShot

Changed:

< # Install sudo, cloud-init, acpi, qemu-guest-agent and e2fsprogs-extra

to

> - Install sudo, cloud-init, acpi, qemu-guest-agent and e2fsprogs-extra

Changed:

< # Add cloud-init and qemu-guest-agent to startup

to

> - Add cloud-init and qemu-guest-agent to startup

Changed:

< # prevent cloud-init config overwriting /etc/network/interfaces

to

> - prevent cloud-init config overwriting /etc/network/interfaces

Changed:

< # add udhcpc staticroutes option to create a route for 169.254.169.254 Openstack datasource address

to

> - add udhcpc staticroutes option to create a route for 169.254.169.254 Openstack datasource address

Changed:

< # allow ssh-rsa algorithm

to

> - allow ssh-rsa algorithm

Changed:

< # Configure Openstack datasource and unlock alpine account setting lock_passwd to false and adding passwd line!

to

> - Configure Openstack datasource and unlock alpine account setting lock_passwd to false and adding passwd line!

Changed:

< # metadata_urls: ["http://169.254.169.254"]
< # max_wait: -1
< # apply_network_config: True

to

> #metadata_urls: ["http://169.254.169.254"]
> #max_wait: -1
> #apply_network_config: True

Changed:

< # Update /etc/inittab to allow serial console on ttyS1 (serial1), serial0 is used for logging by kvm

to

> - Update /etc/inittab to allow serial console on ttyS1 (serial1), serial0 is used for logging by kvm

Changed:

< # Optionally update MOTD

to

> - Optionally update MOTD

Changed:

< # Poweroff

to

> - Poweroff

Changed:

< # Upload the alpine openstack image to glance

to

> - Upload the alpine openstack image to glance


Currently (27 April 2022) alpine linux does not provide cloud images for Openstack. Here is how to make it.

Step-by-step guide

The main thing is needed to build a simple openstack alpine image is to install cloud-init apk package! Optionally qemu-guest-agent for better integration with KVM and e2fsprogs-extra for resizing file system are installed, as well as sudo and acpi

 wget https://dl-cdn.alpinelinux.org/alpine/v3.15/releases/x86_64/alpine-virt-3.15.4-x86_64.iso
 qemu-img create -f qcow2 alpine-virt-3.15.4-x86_64.qcow 512M
 /usr/bin/qemu-system-x86_64 -drive file=alpine-virt-3.15.4-x86_64.qcow,if=virtio,cache=writeback,discard=ignore,format=qcow2 -drive file=alpine-virt-3.15.4-x86_64.iso,media=cdrom -boot once=d -vnc 0.0.0.0:15 -name alpine -machine type=pc,accel=tcg -netdev bridge,id=user.0,br=virbr0 -m 512M -device virtio-net,netdev=user.0 
 setup-disk -m sys -L
 setup-alpine -c answers
 sed -i -e 's/alpine-test/alpine/g' answers
 sed -i -e '/^PROXYOPTS/cPROXYOPTS="none"' answers
 sed -i -e '/^APKREPOSOPTS/s/-r/-1/' answers
 sed -i -e '/hostname/d' answers
 sed -i -e 's/openntpd/chrony/' answers
 #sed -i -e '/^DISKOPTS/cDISKOPTS="-m sys -L /dev/vda"' answers
 sed -i -e '/^DISKOPTS/cDISKOPTS="-m sys /dev/sda"' answers
 sed -i -e 's/^LBUOPTS/#LBUOPTS/' answers
 sed -i -e 's/^APKCACHEOPTS/#APKCACHEOPTS/' answers
 sed -i -e '/^DNSOPTS/cDSNOPTS="-m ${DOMAIN_NAME} 8.8.8.8"' answers
 setup-alpine -f answers
 reboot
 . /etc/os-release
 VERSION=`echo ${VERSION_ID}|cut -f1-2 -d"."`
 sed -i -e "/\/v${VERSION}\/community$/s/^#//" /etc/apk/repositories
 apk upgrade --update-cache --available
 apk add sudo cloud-init acpi qemu-guest-agent e2fsprogs-extra
 setup-cloud-init
 rc-update add qemu-guest-agent
 cat << EOF > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
 network:
   config: disabled
 EOF
   
 - add udhcpc staticroutes option to create a route for 169.254.169.254 Openstack datasource address 
 cat << EOF > /etc/network/interfaces
 auto lo
 iface lo inet loopback
 auto eth0
 iface eth0 inet dhcp
         udhcpc_opts -O staticroutes
 EOF
 cat << EOF >> /etc/ssh/sshd_config
 PubkeyAuthentication yes
 PubkeyAcceptedAlgorithms ssh-rsa,rsa-sha2-256,rsa-sha2-512
 EOF
 vi /etc/cloud/cloud.cfg
 datasource:
   OpenStack:
     timeout: 5
     retries: 3
     #metadata_urls: ["http://169.254.169.254"]
     #max_wait: -1
     #apply_network_config: True
 system_info:
    distro: alpine
     default_user:
       lock_passwd: false
       passwd: $6$e.MLvnlNXAjBVtGV$LoeBb3B0c9fZ6TSAZvKnv0lLLJa61blgpJJUGyy5KIjRRdXK6xH8am7TckNEMW8bgd8IpcBC7BnebTO9PbYi00
 cat << EOF >> /etc/inittab 
 ttyS1::respawn:/sbin/getty -L 0 ttyS1 vt100  
 EOF
 cat << EOF > /etc/motd
 Welcome to $PRETTY_NAME ($VERSION_ID)!
 Home URL: $HOME_URL
 EOF
 poweroff
 openstack image create --public --file alpine-virt-3.15.4-x86_64.qcow --property hw_scsi_model=virtio-scsi --property hw_disk_bus=scsi --property hw_qemu_guest_agent=yes --property os_require_quiesce=yes alpine-virt-3.15.4-x86_64