Skip to content

Commit

Permalink
Add Alpine to the ZBM test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
ahesford committed Nov 29, 2021
1 parent 3ca7631 commit b9c4ed9
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
57 changes: 57 additions & 0 deletions testing/helpers/chroot-alpine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh
# vim: softtabstop=2 shiftwidth=2 expandtab

# Make sure APK knows where to find packages
cat <<EOF > /etc/apk/repositories
http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/
https://dl-cdn.alpinelinux.org/alpine/latest-stable/main/
EOF

# Update all packages
apk update

# Add and enable ZFS tools
apk add linux-lts linux-lts-dev zfs zfs-lts bash

rc-update add zfs-import sysinit
rc-update add zfs-mount sysinit

# Enable DHCP and add SSH
apk add openssh
rc-update add sshd

cat > /etc/network/interfaces <<EOF
auto eth0
iface eth0 inet dhcp
EOF

# Make sure any ZFS keyfiles and ZFS modules are included in initramfs
for keyfile in /etc/zfs/*.key; do
[ -e "${keyfile}" ] || continue
echo "${keyfile}" >> /etc/mkinitfs/features.d/zfshost.files
done

echo "/etc/hostid" >> /etc/mkinitfs/features.d/zfshost.files
echo "/etc/zfs/zpool.cache" >> /etc/mkinitfs/features.d/zfshost.files

echo 'features="ata base keymap kms mmc scsi usb virtio zfs zfshost"' > /etc/mkinitfs/mkinitfs.conf
mkinitfs -c /etc/mkinitfs/mkinitfs.conf "$(ls /lib/modules)"

# Set kernel commandline
if [ -n "${ZBM_POOL}" ]; then
cmdline="spl_hostid=$( hostid ) rw loglevel=4 console=tty1 console=ttyS0"
zfs set org.zfsbootmenu:commandline="${cmdline}" "${ZBM_POOL}/ROOT"
fi

# Set root password
echo 'root:zfsbootmenu' | chpasswd -c SHA256

# /bin/ash sucks
sed -i '/^root/s@/bin/ash@/bin/bash@' /etc/passwd

# enable root login over ssh with a password
sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config

# enable getty on serial port
sed -i 's/^#ttyS0::/ttyS0::/' /etc/inittab
grep -q ttyS0 /etc/securetty || echo ttyS0 >> /etc/securetty
41 changes: 41 additions & 0 deletions testing/helpers/install-alpine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
# vim: softtabstop=2 shiftwidth=2 expandtab

cleanup () {
if [ -n "${APKROOT}" ]; then
rm -rf "${APKROOT}"
unset APKROOT
fi

exit
}

if [ -z "${CHROOT_MNT}" ] || [ ! -d "${CHROOT_MNT}" ]; then
echo "ERROR: chroot mountpoint must be specified and must exist"
exit 1
fi

if ! APKROOT="$( mktemp -d )"; then
echo "ERROR: cannot make directory to unpack apk"
exit 1
else
export APKROOT
fi

trap cleanup EXIT INT TERM

MIRROR="http://dl-cdn.alpinelinux.org/alpine/latest-stable/main"
PATTERN="apk-tools-static-[.0-9]\+-r[0-9]\+.apk"
if ! ./helpers/extract_remote.sh "${MIRROR}/x86_64/" "${APKROOT}" "${PATTERN}"; then
echo "ERROR: could not fetch and extract static apk tools"
exit 1
fi

"${APKROOT}/sbin/apk.static" --arch "x86_64" -X "${MIRROR}" \
-U --allow-untrusted --root "${CHROOT_MNT}" --initdb add alpine-base

mkdir -p "${CHROOT_MNT}/etc"
cp /etc/hostid "${CHROOT_MNT}/etc/"
cp /etc/resolv.conf "${CHROOT_MNT}/etc/"

# Alpine does not even provide dracut, why bother populating a ZBM repo?
2 changes: 1 addition & 1 deletion testing/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Usage: $0 [options]
-x Use an existing pool image
-k Populate host SSH host and authorized keys
-o Distribution to install (may specify more than one)
[ void, void-musl, arch, debian, ubuntu ]
[ void, void-musl, alpine, arch, debian, ubuntu ]
EOF
}

Expand Down

0 comments on commit b9c4ed9

Please sign in to comment.