Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Created April 10, 2018 01:46
Show Gist options
  • Select an option

  • Save mohemohe/fc5cf30041482872734e31f09b49a4d8 to your computer and use it in GitHub Desktop.

Select an option

Save mohemohe/fc5cf30041482872734e31f09b49a4d8 to your computer and use it in GitHub Desktop.
Alpine Linuxをsystemd-nspawnで動かす
#!/bin/bash
MIRROR=http://ftp.tsukuba.wide.ad.jp/Linux/alpine
VERSION=edge
if [ $UID -ne 0 ]; then
echo "rootじゃなきゃやだ" >&2
exit 1
fi
if [ -z "$1" ]; then
echo "$0 フォルダ名" >&2
exit 0
fi
dest="$1"
apkdir=$(mktemp -d)
arch="$(uname -m)"
apktools_version=$(curl -s $MIRROR/$VERSION/main/$arch/ | awk -F'=' 'match($0, /href="apk-tools-static-(.*).apk">/, a) {print a[1]}')
wget -O - $MIRROR/$VERSION/main/$arch/apk-tools-static-$apktools_version.apk \
| tar -xz -C $apkdir || \
{ echo "Couldn't download apk-tools, the version might have changed..."; exit 1; }
$apkdir/sbin/apk.static \
-X $MIRROR/$VERSION/main -U --arch $arch \
--allow-untrusted --root "$dest" \
--initdb add alpine-base
mkdir -p "$dest"/{etc/apk,root}
cat /etc/resolv.conf >"$dest"/etc/resolv.conf
printf '%s/%s/main\n' $MIRROR $VERSION >"$dest"/etc/apk/repositories
sed '/tty[0-9]:/ s/^/#/' -i "$dest"/etc/inittab
printf 'console::respawn:/sbin/getty 38400 console\n' >>"$dest"/etc/inittab
for s in hostname bootmisc syslog; do
ln -s /etc/init.d/$s "$dest"/etc/runlevels/boot/$s
done
for s in killprocs savecache; do
ln -s /etc/init.d/$s "$dest"/etc/runlevels/shutdown/$s
done
rm -r $apkdir
echo ""
echo "だん!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment