Alpine image: fix networking in with qemu -nic user, haveged,

uncloud-init
This commit is contained in:
fnux 2020-01-25 18:44:29 +01:00
parent 7eacf4c8f5
commit 3ca0c38d15

View file

@ -13,7 +13,7 @@ RELEASE=v3.11
ARCH=x86_64
IMAGE_PATH=alpine-uncloud-$RELEASE-$(date -I).img.qcow2
IMAGE_SIZE=10G
NBD_DEVICE=/dev/nbd1
NBD_DEVICE=/dev/nbd0
APK_MIRROR=http://dl-2.alpinelinux.org/alpine/ # Mind the trailing /
cleanup() {
@ -79,7 +79,7 @@ apk add -U -X $APK_MIRROR$RELEASE/main/ \
--arch="$ARCH" \
--root=/mnt \
--initdb \
alpine-base alpine-conf openssh sudo syslinux tzdata gnupg bash
alpine-base alpine-conf openssh sudo tzdata gnupg haveged bash eudev
mount --bind /dev /mnt/dev
mount --bind /dev/pts /mnt/dev/pts
@ -91,7 +91,12 @@ mount --bind /sys /mnt/sys
# Required to resolve package mirror in chroot.
cp /etc/resolv.conf /mnt/etc/resolv.conf
# Initialize /etc/hosts.
# Initialize networking.
run_root setup-interfaces -i << EOF
auto lo
iface lo inet loopback
EOF
cat > /mnt/etc/hosts << EOF
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
@ -122,13 +127,16 @@ run_root apk update
# Install RDNSSD for DNS discovery from router advertisement.
run_root apk add ndisc6
run_root rc-update add rdnssd boot
# TODO: fix upstream!
sed -i 's/-H \/etc\/rdnssd\/resolvconf/-H \/etc\/rdnssd\/merge-hook/' /mnt/etc/init.d/rdnssd
# Initialize base services.
for i in ntpd sshd crond rdnssd; do
for i in ntpd sshd crond; do
run_root rc-update add $i default
done
for i in hwclock modules sysctl hostname bootmisc networking syslog swap urandom; do
for i in hwclock modules hwdrivers acpid mdev sysctl hostname bootmisc networking syslog swap urandom haveged; do
run_root rc-update add $i boot
done
@ -139,20 +147,6 @@ done
# Set hostname.
run_root setup-hostname -n alpine
# Install kernel and bootloader.
dd if=/usr/share/syslinux/mbr.bin of=/dev/nbd0 bs=1 count=440
extlinux -i /mnt/boot
cat >/mnt/boot/extlinux.conf <<EOF
DEFAULT linux
LABEL linux
LINUX vmlinuz-$(echo "$linux" | cut -d- -f2-)
INITRD initramfs-$(echo "$linux" | cut -d- -f2-)
APPEND root=/dev/vda3 rw modules=sd-mod,usb-storage,ext4 quiet rootfstype=ext4
EOF
run_root apk add linux-virt
# Generate fstab file.
boot_uuid=$(blkid --match-tag UUID --output value "${NBD_DEVICE}p1")
root_uuid=$(blkid --match-tag UUID --output value "${NBD_DEVICE}p2")
@ -161,9 +155,33 @@ UUID=$boot_uuid /boot ext4 rw,relatime,data=ordered 0 2
UUID=$root_uuid / ext4 rw,relatime,data=ordered 0 1
EOF
# FIXME: add fnux's SSH key for testing purposes.
mkdir -p /mnt/root/.ssh
curl https://key.wf/fnux > /mnt/root/.ssh/authorized_keys
# Install kernel and bootloader.
run_root apk add linux-virt syslinux
dd if=/usr/share/syslinux/mbr.bin of="$NBD_DEVICE" bs=1 count=440
extlinux -i /mnt/boot
cat >/mnt/boot/extlinux.conf <<EOF
DEFAULT linux
LABEL linux
LINUX vmlinuz-virt
INITRD initramfs-virt
APPEND root=UUID=$root_uuid rw modules=sd-mod,usb-storage,ext4 quiet rootfstype=ext4
EOF
# Manually install uncloud-init.
run_root apk add git curl grep make
uncloud_init_dir=/tmp/uncloud-init
mkdir -p "$uncloud_init_dir"
run_root git clone https://code.ungleich.ch/uncloud/uncloud-init.git "$uncloud_init_dir"
run_root make -C "$uncloud_init_dir" install
run_root rm -r "$uncloud_init_dir"
run_root rc-update add uncloud-init boot
# Remove resolvconf: handled by uncloud-init.
run_root rm /etc/resolv.conf
# Make sure everything is written to disk before exiting.
sync