Skip to content

Instantly share code, notes, and snippets.

@martin-juul
Last active July 19, 2020 22:33
Show Gist options
  • Save martin-juul/8f8cfce9334f2b36cddb6065ceed6d7f to your computer and use it in GitHub Desktop.
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
#!/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
@martin-juul
Copy link
Author

martin-juul commented Feb 7, 2018

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 Mountpoint Minimum recommended Filesystem
/boot /dev/sda 128 MB ext4
/ /dev/sdb 3 GB ext4
/data /dev/sdc Rest of your space ext4
swap /dev/sdd 512 MB 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

  • /dev/sda
    • boot
  • /dev/sdb
    • root
  • /dev/sdc
    • data
  • /dev/sdd
    • swap

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:

curl -o- https://gist.githubusercontent.com/snowydane/8f8cfce9334f2b36cddb6065ceed6d7f/raw/16d3db4013a23829758f6230f2ad9cec60857b9f/alpine-boostrap.sh | bash

Once that finishes, shut the Linode down from recovery mode and, staying in the Lish console, run:

boot 1

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment