Alpine image: fix networking in with qemu -nic user, haveged,
uncloud-init
This commit is contained in:
parent
7eacf4c8f5
commit
3ca0c38d15
1 changed files with 40 additions and 22 deletions
|
@ -13,7 +13,7 @@ RELEASE=v3.11
|
||||||
ARCH=x86_64
|
ARCH=x86_64
|
||||||
IMAGE_PATH=alpine-uncloud-$RELEASE-$(date -I).img.qcow2
|
IMAGE_PATH=alpine-uncloud-$RELEASE-$(date -I).img.qcow2
|
||||||
IMAGE_SIZE=10G
|
IMAGE_SIZE=10G
|
||||||
NBD_DEVICE=/dev/nbd1
|
NBD_DEVICE=/dev/nbd0
|
||||||
APK_MIRROR=http://dl-2.alpinelinux.org/alpine/ # Mind the trailing /
|
APK_MIRROR=http://dl-2.alpinelinux.org/alpine/ # Mind the trailing /
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
|
@ -79,7 +79,7 @@ apk add -U -X $APK_MIRROR$RELEASE/main/ \
|
||||||
--arch="$ARCH" \
|
--arch="$ARCH" \
|
||||||
--root=/mnt \
|
--root=/mnt \
|
||||||
--initdb \
|
--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 /mnt/dev
|
||||||
mount --bind /dev/pts /mnt/dev/pts
|
mount --bind /dev/pts /mnt/dev/pts
|
||||||
|
@ -91,7 +91,12 @@ mount --bind /sys /mnt/sys
|
||||||
# Required to resolve package mirror in chroot.
|
# Required to resolve package mirror in chroot.
|
||||||
cp /etc/resolv.conf /mnt/etc/resolv.conf
|
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
|
cat > /mnt/etc/hosts << EOF
|
||||||
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
|
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
|
||||||
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
|
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
|
||||||
|
@ -122,13 +127,16 @@ run_root apk update
|
||||||
|
|
||||||
# Install RDNSSD for DNS discovery from router advertisement.
|
# Install RDNSSD for DNS discovery from router advertisement.
|
||||||
run_root apk add ndisc6
|
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.
|
# 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
|
run_root rc-update add $i default
|
||||||
done
|
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
|
run_root rc-update add $i boot
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -139,20 +147,6 @@ done
|
||||||
# Set hostname.
|
# Set hostname.
|
||||||
run_root setup-hostname -n alpine
|
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.
|
# Generate fstab file.
|
||||||
boot_uuid=$(blkid --match-tag UUID --output value "${NBD_DEVICE}p1")
|
boot_uuid=$(blkid --match-tag UUID --output value "${NBD_DEVICE}p1")
|
||||||
root_uuid=$(blkid --match-tag UUID --output value "${NBD_DEVICE}p2")
|
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
|
UUID=$root_uuid / ext4 rw,relatime,data=ordered 0 1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# FIXME: add fnux's SSH key for testing purposes.
|
# Install kernel and bootloader.
|
||||||
mkdir -p /mnt/root/.ssh
|
run_root apk add linux-virt syslinux
|
||||||
curl https://key.wf/fnux > /mnt/root/.ssh/authorized_keys
|
|
||||||
|
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.
|
# Make sure everything is written to disk before exiting.
|
||||||
sync
|
sync
|
||||||
|
|
Loading…
Reference in a new issue