Last active
July 19, 2020 22:33
-
-
Save martin-juul/8f8cfce9334f2b36cddb6065ceed6d7f to your computer and use it in GitHub Desktop.
[Alpine Bootstrapping script for Linode] Script for installing an alpine linode via lish/rescue console - Forked from https://github.com/jcorme/alpine-linode-bootstrap
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
#!/bin/sh | |
HOST=${HOST:-alpine} | |
INTERFACES="auto lo | |
iface lo inet loopback | |
auto eth0 | |
iface eth0 inet dhcp | |
hostname $HOST | |
" | |
ALPINE_VER=${ALPINE_VER:-"latest-stable"} | |
APK_TOOLS_VER=${APK_TOOLS_VER:-"2.9.1-r0"} | |
ARCH=$(uname -m) | |
MIRROR="https://nl.alpinelinux.org/alpine" | |
BOOT_DEV="/dev/sda" | |
ROOT_DEV="/dev/sdb" | |
DATA_DEV="/dev/sdc" | |
SWAP_DEV="/dev/sdd" | |
mkdir /alpine | |
mount $ROOT_DEV /alpine | |
cd /alpine | |
mkdir boot | |
mount $BOOT_DEV /alpine/boot | |
curl -s $MIRROR/$ALPINE_VER/main/$ARCH/apk-tools-static-${APK_TOOLS_VER}.apk | tar xz | |
./sbin/apk.static --repository $MIRROR/$ALPINE_VER/main/ --update-cache --allow-untrusted --root /alpine --initdb add alpine-base alpine-mirrors | |
cat <<EOF >> /alpine/etc/fstab | |
$ROOT_DEV / ext4 defaults,noatime 0 0 | |
$BOOT_DEV /boot ext4 defaults,noatime 0 1 | |
$DATA_DEV /data ext4 defaults,noatime 0 0 | |
$SWAP_DEV swap swap defaults 0 0 | |
EOF | |
cat <<EOF > /alpine/etc/inittab | |
# /etc/inittab | |
::sysinit:/sbin/openrc sysinit | |
::sysinit:/sbin/openrc boot | |
::wait:/sbin/openrc default | |
# Put a getty on the serial port | |
ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100 | |
# Stuff to do for the 3-finger salute | |
::ctrlaltdel:/sbin/reboot | |
# Stuff to do before rebooting | |
::shutdown:/sbin/openrc shutdown | |
EOF | |
mkdir /alpine/boot/grub | |
cat <<EOF > /alpine/boot/grub/grub.cfg | |
set root=(hd0) | |
set default="Alpine Linux" | |
set timeout=0 | |
menuentry "Alpine Linux" { | |
linux /vmlinuz-hardened root=/dev/sdb modules=sd-mod,usb-storage,ext4 console=ttyS0 quiet | |
initrd /initramfs-hardened | |
} | |
EOF | |
mkdir /alpine/etc/mkinitfs | |
cat <<EOF > /alpine/etc/mkinitfs/mkinitfs.conf | |
features="ata ide scsi virtio base ext4" | |
EOF | |
cp /etc/resolv.conf /alpine/etc | |
echo ttyS0 >> /alpine/etc/securetty | |
mount --bind /proc /alpine/proc | |
mount --bind /dev /alpine/dev | |
chroot /alpine /bin/sh<<CHROOT | |
setup-apkrepos -f | |
apk update | |
setup-hostname -n $HOST | |
printf "$INTERFACES" | setup-interfaces -i | |
rc-update add networking boot | |
rc-update add urandom boot | |
rc-update add crond | |
apk add linux-grsec | |
CHROOT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alpine Linux Bootstrap for Linode
Should work everywhere else. If you have access to a console that can mount your volumes, and run a shell script.
A simple script that can be executed in recovery mode to bootstrap Alpine Linux on a Linode server.
Creating a Linode
This script assumes your Linode will have four disks for boot, root, data and swap.
Name is the mountpoint in the OS, Mountpoint is the mountpoints in the control panel.
If you decide not to use a swap disk, you will need to manually delete the relevant parts from the script (which should be fairly easy).
Configuration profile
Label and notes
Label: Alpine
Boot Settings
Kernel: GRUB 2
Block Device Assignment
Filesystem/Boot helpers
Turn everything off.
Boot the Linode into recovery mode with the disks assigned as above.
Executing the Script
Connect to the Linode with Lish either via SSH or the browser console. To download and run the script:
Once that finishes, shut the Linode down from recovery mode and, staying in the Lish console, run:
After a bit, you should be at the Alpine login screen. The root user, by default, does not have a password. At this point, you can install an SSH server, which pretty much completes the installation.
Credit
This script is basically Andy Leap's guide written as a working script (with fixed networking!), so big thanks to him.
Jason Chen for original script
Github user jcorme for his version