Skip to content

Instantly share code, notes, and snippets.

@profOnno
Last active February 25, 2024 13:35
Show Gist options
  • Save profOnno/e55c1b9be73fa1ff92ec8014b549d01c to your computer and use it in GitHub Desktop.
Save profOnno/e55c1b9be73fa1ff92ec8014b549d01c to your computer and use it in GitHub Desktop.
Alpine linux on Tilaa

Introduction

Tilaa is my vps provider but doesn't have alpine in the install options After playing around with the vps systems... coreos ubuntu.. i did make mistakes... coreos got invaded ... opened a webgui... forgot to protect it... needed to get some data from it. So used the Tilaa rescue boot (in the Dashboard) and mounted the disks. Also used it when i increased the disk size for an installation (if I remember correctly), deleting the partition, creating a new one with the same starting address), do a resize2fs to expand and voila.. Bob was my uncle.

After playing arround with Alpine Linux in coreos and ubuntu lxd. I thought it would be a nice distro to get running straight from the vps. A weekend without sunlight but with pixellight I got it running, needs another iteration to make it a smooth experiance :o.

DISCLAIMER Any action you take upon the information on this page is strictly at your own risk, I won't be liable for any losses and damages in connection with the use of this page.

Step 1

Install Arch linux

Step 2

Boot rescue

Step 3

Open video display Optional startx but is handy.. to copy urls etc.

fdisk /dev/vda
print
d  (delete first and only partition)
n (new)
p (primary)
<cr> (partition number 1)
<cr> (default 2048 first sector)
+12G
n (new)
p (primary)
<cr> (partition number 2)
<cr> (first sector, keep default (starts after end 1st partition))
<cr> (last sector, keep default going to the end)
a (bootflag)
2
print
w

Now you should have 2 devices /dev/vda1 (12G) and /dev/vda2 (8G)

mkfs.ext4 /dev/vda1 -L ROOT
mkfs.ext4 /dev/vda2 -L INSTALL
resize2fs /dev/vda1 -s (disables 64bit, syslinux wont work on 64bit, grub will)

mount /dev/vda2 /mnt

browse (in the rescue window) to www.alpinelinux.org get the latest download link (I'm using standard) (check the sha256)

cd /mnt
wget http://dl-cdn.alpinelinux.org/alpine/v3.7/releases/x86_64/alpine-standard-3.7.0-x86_64.iso
wget http://dl-cdn.alpinelinux.org/alpine/v3.7/releases/x86_64/alpine-standard-3.7.0-x86_64.iso.sha256
sha256 -c alpine-standard-3.7.0.x86_64.iso.sha256
should give OK... 

mkdir install
mount -o loop <download link here> /mnt/install
cp -R /mnt/install/* .
ls

You've should have apks boot efi, and the install and iso stuff

grub-install --boot-directory=/mnt/boot /dev/vda

No errors?... yeah...

Step 4

Reboot. (type reboot on the commandline) System is going to halt. Click Start in your Tilaa dashboard. Wait Till task Open video display' is there. Click it It should have booted in Alpine Linux root `

Step 5

Setup the system. Now it is minimal and root is mounted to tmpfs... Can be used but then you've to use lbu commit after changing anything on the rootfs. Continue by using parts of the guide .. (http://https://wiki.alpinelinux.org/wiki/Native_Harddisk_Install_1.9)

setup-alpine
<cr> (or select what you want)
alpine (hostname that you want)
  <cr> (eth0)
  <cr> (dhcp)
  <cr> (no manual network configuration)
  enter a password
  again
  Europe/Amsterdam (or whatever)
  <cr> (no proxy)
  <cr> (f find fasted, or what rocks your boot)
  <cr> (openssh if nice)
  <cr> chrony (works for me)
  <cr> (none disk(s))
  <cr> (vda2 for config?)
  <cr> (defaults for cache is ok)

almost done.


apk update
apk add e2fsprogs e2fsprogs-extra mkinitfs syslinux util-linux
lbu commit (save changes so we can reboot to this point)

Optional? reboot? (setup as system (root mounted on disk not on mem).. read the alpine docs for that -s 0 (no swap)

mount /dev/vda1 /mnt
setup-disk -m sys -s 0 -v /mnt
cd /mnt/boot
mkdir syslinux
mv *.c32 syslinux
mv extlinux.conf syslinux

edit /mnt/boot/syslinux/extlinux.conf so it looks like below.

TIMEOUT 20
PROMPT 1
DEFAULT hardened

LABEL hardened
MENU LABEL Linux hardened
KERNEL ../vmlinuz-hardened
INITRD ../initramfs-hardened
DEVICETREEDIR /boot/dtbs
APPEND modules=ext4 rootfstype=ext4 root=LABEL=ROOT rw
extlinux --install /mnt/boot/syslinux

type blkid to see if there is a TYPE="swap" and LABEL="SWAP" partition. edit /mnt/etc/fstab

LABEL=ROOT / ext4 rw,relatime,data=ordered 0 1
LABEL=SWAP none swap defaults 0 0

then do

cat /usr/share/syslinux/mbr.bin > /dev/vda

REBOOT

vingers crossed... and yeah or... go to rescue... and try to fix it.

df -h should give root mounted on /dev/vda1 (instead of root being mounted on tmpfs)

RESCUE

mount /dev/vda2 /mntroot

grub-install --boot-directory /mnt/boot

END RESCUE

Step 6

Delete install partition and resize fs. Use the fdisk from util-linux package, it gets the start sector right (no puzzle for you)... Do not remove signature if asked.

fdisk /dev/vda
d (delete)
2 (partition 2)
d (delete)
n (new)
p (primary)
<cr> (partition number 1)
<cr> (default start (2048), MUST be the same as the partition 1 you've deleted. Do not write (w) if you'r not sure)
<cr> (default end)
N (do not remove signature, if asked)
a (make sure the one partition has a boot flag
w (write)

resize2fs /dev/vda1

that should be it.

df -h shows 19.6G

Enable swap

Did not test this, but should work (source: https://wiki.alpinelinux.org/wiki/Setting_up_disks_manually). Do rc-service swap start to start swapping free -m will show how much swap space is available (in MB).

Conclusion

It works... yeah

Tip

Create snapshot now. This makes future endeavors easy.

Grub

You can use grub as bootloader and then the resize /dev/vda1 -s can be ommited. I found grub bloated and didn't work out of the box. Probe errors and such. If you go this way, it seems to be easier to craft a /boot/grub/grub.cfg

set default=0
set timeout=3

menuitem 'Alpine hardened' {
  set root='(hd0,1)'
  linux vmlinuz-hardened modules=ext4 fstype=ext4 root=LABEL=ROOT rw
  initrd initramfs-hardened
}

Then do the grub-install --boot-directory=/mnt/boot /dev/vda

BTRFS

apk add btrfs-progs btrfs-progs-extra do same steps .. replace ext4 with btrfs

Make the two partitions into one partition like above. Resize like this btrfs filesystem resize max /

Didn't work consistently

Seems when using ext4 to boot from it HAS to be non 64 bit. I was lucky some time and it worked, but i could not repeat my steps. Guess that has something to do with the different mkfs.ext4 version difference on the rescue disk and the booted alpine install partiton.

The uncleaned log

mkfs.ext4 -L ROOT /dev/vda1 mount /dev/vda1 /mnt mkdir -p /mnt/boot/syslinux cp /media/vda2/boot/syslinux/syslinux.cfg /mnt/boot/syslinux

apk add e2fsprogs mkinitfs syslinux cat /usr/share/syslinux/mbr.bin > /dev/vda setup-disk -m sys -s 0 -v /mnt doesn't use the syslinux folder extlinux --install /mnt/boot/syslinux/ reboot

failed to load ldlinux.c32

recue mount /dev/vda1 /mnt extlinux 4.07 from rescu extlinux --install /mnt/boot/syslinux no configuration file found

chattr -i /mnt/boot/ldlinux.* rm -f /mnt/boot/ldlinux.* extlinux --install /mnt/boot/syslinux

no configuration found?

do rescue mount /dev/vda1 /mnt cp /mnt/boot/syslinux/syslinux.cfg /mnt/boot/systlinux/extlinux.conf used the ../stuf and stripped the append cat /usr/share/syslinux/mbr.bin > /dev/vda (from rescue)

no configuration found?

do rescue boot from /dev/vda2 mount /dev/vda1 /mnt dd bs=440 count=1 if=/usr/share/syslinux/bios/mbr.bin of=/dev/vda edit /sbin/setup-disk ...change extlinux .... /boot to extlinux ... /boot/syslinux setup-disk -m sys -s 0 -v /mnt syslinux --version 6.04 extlinux --version 6.04

failed to load ldlinux.c32 -------------- AAAAAAAAAAAARGH --------------- rebooted my image where i did something magically to make it work learned it booted from /boot instead of /boot/syslinux there was also a /boot/grub...

-rw-r--r--    1 root     root       4131160 Nov 27 16:59 System.map-hardened
lrwxrwxrwx    1 root     root             1 Jan 21 21:39 boot -> /
-rw-r--r--    1 root     root        165139 Nov 27 16:59 config-hardened
-rw-r--r--    1 root     root           638 Jan 26 14:11 extlinux.conf
-rw-r--r--    1 root     root      11576047 Jan 21 22:06 initramfs-hardened
-r--r--r--    1 root     root        116924 Jan 26 14:18 ldlinux.c32
-r--r--r--    1 root     root         69632 Jan 26 14:18 ldlinux.sys
-rw-r--r--    1 root     root        181996 Jan 21 22:06 libcom32.c32
-rw-r--r--    1 root     root         23616 Jan 21 22:06 libutil.c32
-rw-r--r--    1 root     root         11712 Jan 21 22:06 mboot.c32
-rw-r--r--    1 root     root         26568 Jan 21 22:06 menu.c32
-rw-r--r--    1 root     root      81547264 Jan 21 21:20 modloop-hardened
-rw-r--r--    1 root     root         27020 Jan 21 22:06 vesamenu.c32
-rw-r--r--    1 root     root       4502608 Nov 27 16:59 vmlinuz-hardened

reboot to rescue then boot from /dev/vda2 mkfs.ext4 -L ROOT /dev/vda1 (wipe) mount /dev/vda1 /mnt setup-disk -m sys -s 0 -v /mnt (then there is no modloop-hardened in the /boot directory) cat /usr/share/syslinux/mbr.bin /dev/vda reboot Missing operation system No bootable device?

reboot rescue cat /usr/share/syslinux/mbr.bin > /dev/vda reboot Missing operation system No bootable device?

reboot rescue mount /dev/vda1 /mnt extlinux --install /mnt/boot cat /usr/share/syslinux/mbr.bin > /dev/vda as expected it boots and says menu.c32 is not a com32r image...(wrong version)

reboot rescue grub-install ...

reboot (to vda2) extlinux --install /mnt/boot reboot ...does grub reboot.. to vda2 again

cat /usr/share/syslinux/mbr.bin > /dev/vda reboot

yes...works

why?

trying it again, use extlinux from rescue .. don't copy mbr reboot.. using grub.. do extlinux again and copy mbr.

mkfs.ext4 -L ROOT /dev/vda1 (wipe) mount /dev/vda1 /mnt setup-disk -m sys -s 0 -v /mnt

reboot rescue mount /dev/vda1 /mnt extlinux --install /mnt/boot

reboot mount /dev/vda1 /mnt extlinux --install /mnt/boot cat /usr/share/syslinux/mbr.bin > /dev/vda reboot failed to load ldlinux.c32 (AAARGHHH)

boot recue mount /dev/vda1 /mnt extlinux --install /mnt/boot cat /usr/share/syslinux/mbr.bin > /dev/vda

ERROR no configuration file found No Default or Ui configureation directive found (Aaargh again)

reboot rescue mount /dev/vda2 /mnt grub-install --boot-directory=/mnt/boot /dev/vda reboot

cat /usr/share/syslinux/mbr.bin > /dev/vda reboot no configuration file found (aargh)

reboot rescue mount /dev/vda1 /mnt extlinux --install /mnt/boot reboot no configuration file found

reboot rescue mount /dev/vda1 /mnt extlinux --install /mnt/boot cat /usr/share/syslinux/mbr.bin > /dev/vda reboot no configuration file found...


mkfs.ext4 -L ROOT /dev/vda1 (wipe) mount /dev/vda1 /mnt setup-disk -m sys -s 0 -v /mnt cat /usr/share/syslinux/mbr.bin /dev/vda reboot Error No bootable device

reboot rescue mount /dev/vda1 /mnt extlinux --install /mnt/boot cat /usr/share/syslinux/mbr.bin > /dev/vda reboot ERROR No configuration file found

reboot rescue mount /dev/vda1 /mnt grub-install --boot-directory=/mnt/boot /dev/vda reboot mount /dev/vda1 /mnt extlinux --install /mnt/boot cat /usr/share/syslinux/mbr.bin > /dev/vda reboot Error failed to load ldlinux.c32

reboot rescue mount /dev/vda1 /mnt extlinux --install /mnt/boot reboot Error: no configuration file found (aargh)

reboot rescue mount /dev/vda2 /mnt ( !! vda2) extlinux --install /mnt/boot reboot Error: no configuration file found (aargh)

----------------------------------------- try 872 mkfs.ext4 -L ROOT /dev/vda1 (wipe) mount /dev/vda1 /mnt setup-disk -m sys -s 0 -v /mnt cat /usr/share/syslinux/mbr.bin > /dev/vda reboot No bootable device

reboot rescue cat /usr/share/syslinux/mbr.bin > /dev/vda reboot Missing operation system No bootable device?

reboot rescue mount /dev/vda1 /mnt extlinux --install /mnt/boot cat /usr/share/syslinux/mbr.bin > /dev/vda reboot Error: No configuration file found !??? (did same as before now different result, eat that Einstein)

reboot rescue mount /dev/vda2 /mnt grub-install --boot-directory=/mnt/boot /dev/vda

reboot cat /usr/share/syslinux/mbr.bin > /dev/vda reboot Error no configuration file found

reboot rescue mount /dev/vda2 /mnt grub-install --boot-directory=/mnt/boot /dev/vda reboot extlinux --install /mnt/boot only leave root line in /mnt/fstab cat /usr/share/syslinux/mbr.bin > /dev/vda reboot

Error failed to load ldlinux.c32

reboot rescue mount /dev/vda1 /mnt extlinux -s -i /mnt/boot reboot Error: No configuration file found

reboot rescue mount /dev/vda2 /mnt grub-install --boot-directory=/mnt/boot /dev/vda reboot

mount /dev/vda1 /mnt extlinux -s -i /mnt/boot cat /usr/share/syslinux/mbr.bin > /dev/vda reboot (6.04-pre) Error failed to load ldlinux.c32

restore snapshot.

the working bootline > .linux vmlinuz-hardened root=LABEL=ROOT modules=sd-mod,usb-storage,ext4 nomodeset quiet rootfspe=ext4 initrd=initramfs-hardened

backup bootsector dd if=/dev/vda of=/tmp/alpine512.mbr bs=512 count=1 dd if=/dev/vda of=/tmp/alpine446.mbr bs=446 count=1

scp to remote computer xxd to show, output to ascii file then do a vimdiff

reboot to rescue mkfs.ext4 -L ROOT /dev/vda1 mount /dev/vda2 /mnt grub-install --boot-directory=/mnt/boot /dev/vda reboot

mount /dev/vda1 /mnt setup-disk -m sys -s 0 -v /mnt dd if=/usr/share/syslinux/mbr.bin of=/dev/vda bs=446 count=1 reboot Missing operating system. No bootable devices. (did the bootable flag gone missing.. or the filetable get fucked up?)

reboot rescue a 1 (remove) a 1 (add) w reboot

Missing operating system No bootable device. (so that didn'd work)

copy alpine446.mbr to /tmp/alpine446.mbr (vda2) dd if=/tmp/alpine446.mbr of=/dev/vda bs=446 count=1 reboot failed to load ldlinux.c32

reboot rescue setup for boot /dev/vda2 reboot

mount /dev/vda1 /mnt extlinux -s -i /mnt/boot dd if=/tmp/alpine446.mbr of=/dev/vda bs=446 count=1 reboot failed to load ldlinux.c32

reboot rescue boot to vda2

do not whipe vda1 mount /dev/vda1 /mnt setup-disk -m sys -s 0 -v /mnt cat /usr/share/syslinux/mbr.bin > /dev/vda failed to load ldlinux.c32


AAARGGGHH... new plan switch to grub first and maybe turn, maybe it works in with one partition boot rescue boot (vda2) apk add grub lbu commit mkfs.ext4 -L ROOT /dev/vda1 mount /dev/vda1 /mnt apk del syslinux setup-disk -m sys -s 0 -v /mnt

reboot rescue grub-install --root-dir=/mnt/boot /vda reboot

insmod ext2
set root='(hd0,1)'
linux /vmlinuz-2.6.32-server root=/dev/mapper/SS928-root ro quiet
initrd /initrd.img-2.6.32.30-server
boo…

mount -t ext4 /dev/vda1 /sysroot exit apk add grub-bios grub-install /dev/vda

reboot now hangs at loading hardware drivers

reboot rescue

vi /mnt/boot/grub/grub.cfg

set default=0
set timeout=3

menuitem 'Alpine hardened' {
  set root='(hd0,1)'
  linux vmlinuz-hardened modules=ext4 fstype=ext4 root=LABEL=ROOT rw
  initrd initramfs-hardened
}

then an grub-install --root-directory=/mnt/boot /dev/vda whould do the trick apk add util-linux fdisk /dev/vda d 1 d 2 n 1 p a w resize2fs /dev/vda1 bobs your uncle

BIOS (http://www.syslinux.org/wiki/index.php?title=Config)

SYSLINUX / EXTLINUX default to searching for the config file in the installed directory (containing ldlinux.sys or extlinux.sys).

[3.35+] SYSLINUX also searches for the config file in "/boot/syslinux/", "/syslinux/" and "/", in this order.

The first configuration file that is found stops the search and the configuration file is parsed / used.

[-3.xx] SYSLINUX uses syslinux.cfg as config file name. EXTLINUX (merged into SYSLINUX as of 4.00) used extlinux.conf.

[4.00+] In each searched-for directory, SYSLINUX searches first for extlinux.conf and then for syslinux.cfg before falling back to the next directory.

[-4.02] ISOLINUX uses isolinux.cfg as config file name, searching first in "/boot/isolinux/" [2.00+] , then in "/isolinux/" and then in "/".

[4.03+] ISOLINUX searches for isolinux.cfg and then for syslinux.cfg in "/boot/isolinux/" before searching for the same files in "/isolinux/", "/boot/syslinux/", "/syslinux/", and "/", in this order.


Since version 4.03, the resulting behavior is that the same "/[[boot/]syslinux/]syslinux.cfg" file can optionally be used for SYSLINUX / EXTLINUX / ISOLINUX, while specific isolinux.cfg and/or extlinux.conf files would take precedence if present.

Since version 4.03, the resulting behavior is that any of the respective config files (or even all of them) — namely isolinux.cfg, and/or extlinux.conf, and/or syslinux.cfg — can optionally be located together in the same "/[[boot/]syslinux/]" directory. 
@Mon-ius
Copy link

Mon-ius commented Feb 25, 2024

Hi, I has the similar vps as yours, but I dont have the rescue mode to enter, only ssh and re-install option. Recently, I make a script that looks like everything works fine, but after reboot twice, the system cannot be ssh. Not sure, if u meet such as problem and has a solution.

The script can be directly run under the original debian system and replace the debian with alpine linux 3.19.

#!/bin/dash

_ARC=$(arch)
_REL=3.19
_TARGET="https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/${_ARC}/alpine-minirootfs-3.19.1-${_ARC}.tar.gz"

XUSER=m0nius
HOST=computing-alpine
PEM="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBUG8QsUdArpYbyQPgXIYISf6G2q9t6s+qxP5K8Vafc6"
XPEM="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKEJeeEzrSnWvMXyPmW8M0L09V/vqhVKAadnE9G62hHC"
FEATURES="ata base ide scsi usb virtio ext4"
MODULES="sd-mod,usb-storage,ext4"

ROOT=$(findmnt -no SOURCE /)
ROOT_DEV="/dev/$(lsblk -ndo pkname "$ROOT")"
ROOTFS_MNT=/mnt.$_ARC
BOOT_PATH=/boot
BOOT_LIB="/usr/share/syslinux"

sudo mkdir -p "$ROOTFS_MNT"/"$BOOT_PATH"
curl -fsSL "$_TARGET" | sudo tar -C "$ROOTFS_MNT" -xz

IFACE=$(ip route get 8.8.8.8 | sed -n 's/.*dev \([^\ ]*\).*/\1/p' | head -n 1)
_IPV4=$(ip addr show dev "$IFACE" | awk '/inet /{print $2}' | cut -d' ' -f2)
_IPv6=$(ip addr show dev "$IFACE" | awk '/inet6 /{print $2}' | cut -d' ' -f2)
GATEWAY=$(ip route show default | awk '/default/ {print $3}')

cat <<EOF | sudo tee "$ROOTFS_MNT"/etc/network/interfaces
auto lo
iface lo inet loopback

auto $IFACE
iface $IFACE inet static
    address $_IPV4
    gateway $GATEWAY
EOF

cat <<EOF | sudo tee "$ROOTFS_MNT"/etc/resolv.conf
nameserver 1.1.1.1
EOF

cat <<EOF | tee "$ROOTFS_MNT"/etc/fstab
$ROOT / ext4 rw,discard,errors=remount-ro 0 1
EOF

find / \( ! -path '/dev/*' -and ! -path '/proc/*' -and ! -path '/sys/*' -and ! -path '/selinux/*' -and ! -path "$ROOTFS_MNT/*" \) -delete 2>/dev/null || true

"$ROOTFS_MNT/lib/ld-musl-x86_64.so.1" "$ROOTFS_MNT/bin/busybox" cp -a "$ROOTFS_MNT"/* /
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
rm -rf "$ROOTFS_MNT"

apk update
apk add openrc openssh alpine-base curl syslinux util-linux sgdisk sudo bash
rc-update -q add devfs sysinit
rc-update -q add dmesg sysinit
rc-update -q add mdev sysinit
rc-update -q add hwdrivers sysinit

rc-update -q add hwclock boot
rc-update -q add modules boot
rc-update -q add sysctl boot
rc-update -q add hostname boot
rc-update -q add bootmisc boot
rc-update -q add syslog boot
rc-update -q add networking boot

rc-update -q add mount-ro shutdown
rc-update -q add killprocs shutdown
rc-update -q add savecache shutdown

rc-update -q add acpid default
rc-update -q add crond default
rc-update -q add sshd default
rc-update -q add cgroups default

ssh-keygen -A
rc-service sshd restart

echo features=\""$FEATURES"\" > /etc/mkinitfs/mkinitfs.conf

cat << EOF | tee /etc/update-extlinux.conf
overwrite=1
vesa_menu=0
default_kernel_opts="quiet"
modules=$MODULES
root=$ROOT
verbose=0
hidden=1
timeout=1
default=grsec
serial_port=
serial_baud=115200
password=''
EOF

apk add linux-virt
setup-hostname -n $HOST
mv /boot/extlinux.conf $BOOT_PATH/syslinux.cfg

grep -q '^[[:space:]]*eth' /proc/net/dev && _policy=" net.ifnames=0"
sed -i "s;\\(^[[:space:]]*APPEND.*\\)root=[^[:space:]]*;\\1root=$ROOT$_policy;" $BOOT_PATH/syslinux.cfg

adduser --disabled-password --gecos "" $XUSER sudo && echo "$XUSER:$HOST" | chpasswd
mkdir -p /home/$XUSER/.ssh && echo "$PEM" >> /home/$XUSER/.ssh/authorized_keys
{
    echo "$PEM"
    echo "$XPEM"
} >> /home/$XUSER/.ssh/authorized_keys
chmod 600 /home/$XUSER/.ssh/authorized_keys && chown -R "$XUSER:root" /home/$XUSER/.ssh
echo "$XUSER ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers.d/$XUSER

extlinux --install $BOOT_PATH
sgdisk "$ROOT_DEV" --attributes=1:set:2
dd bs=440 count=1 conv=notrunc if="$BOOT_LIB"/gptmbr.bin of="$ROOT_DEV"
sync; reboot -f

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