-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters