how to manually install alpine linux on any linux distribution

# Assuming

You can easily change these factors when you notice them, for example in the alpine rootfs you can always change the version, or in timezone, well time timezone, the drive whenever it comes up, though networking is needed here

# Installation (pt. 1)

# Installation (pt. 2)

# Mount root

mkdir -p /mnt/alpine
mount /dev/sda3 /mnt/alpine

# Mount boot

mkdir -p /mnt/alpine/boot
mount /dev/sda1 /mnt/alpine/boot

# Download an extract the RootFS

cd /mnt/alpine
wget https://dl-cdn.alpinelinux.org/alpine/v3.16/releases/x86_64/alpine-minirootfs-3.16.2-x86_64.tar.gz
tar xpvf alpine-minirootfs-3.16.2-x86_64.tar.gz --xattrs-include='*.*' --numeric-owner

# FSTAB generation

wget https://raw.githubusercontent.com/cemkeylan/genfstab/master/genfstab
sh genfstab -U /mnt/alpine >>/mnt/alpine/etc/fstab
cat /mnt/alpine/etc/fstab
echo "$(blkid /dev/sda2 | awk '{print $2}' | sed 's/"//g') none swap sw 0 0" >>/mnt/alpine/etc/fstab

# Mount the needed fake filesystems

mount --types proc /proc /mnt/alpine/proc
mount --rbind /sys /mnt/alpine/sys
mount --make-rslave /mnt/alpine/sys
mount --rbind /dev /mnt/alpine/dev
mount --make-rslave /mnt/alpine/dev
mount --bind /run /mnt/alpine/run
mount --make-slave /mnt/alpine/run

# Copy host's resolv.conf to the chroot environment

cp /etc/resolv.conf /mnt/alpine/etc/resolv.conf

# Chroot

chroot /mnt/alpine /bin/ash

# Setup PATH

export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

# Update and install setup scripts

apk update
apk add alpine-conf openrc --no-cache

# Installation (pt. 3)

If you see any errors regarding rc-service, rc-update, etc. ignore them

This part is based off https://docs.alpinelinux.org/user-handbook/0.1a/Installing/manual.html

# Setup keymap

setup-keymap us us  # This will use the US keyboard

# Setup hostname

export HOSTNAME='alpine'
setup-hostname "$HOSTNAME"  # Hostname will be alpine

# Setup hosts file

tee /etc/hosts <<EOF
127.0.0.1 localhost.localdomain localhost $HOSTNAME.localdomain $HOSTNAME
::1       localhost.localdomain localhost $HOSTNAME.localdomain $HOSTNAME
EOF

# Setup networking

https://docs.alpinelinux.org/user-handbook/0.1a/Installing/manual.html#_networking

# Timezone

apk add tzdata
export _TZ='Europe/Vilnius'
install -Dm 0644 "/usr/share/zoneinfo/$_TZ" "/etc/zoneinfo/$_TZ"
export TZ="$_TZ"
echo "export TZ='$TZ'" >> /etc/profile.d/timezone.sh

# Root password

passwd

# Networking tools

apk add dhcp wpa_supplicant

# Bootloader (GRUB) and kernel

apk add grub grub-efi efibootmgr linux-lts
apk add linux-firmware
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=ALPINE
grub-mkconfig -o /boot/grub/grub.cfg

# Enable vital services

rc-update add hostname boot
rc-update add devfs sysinit
rc-update add cgroups sysinit
rc-update add bootmisc boot
rc-update add binfmt boot
rc-update add fsck boot
rc-update add urandom boot
rc-update add root boot
rc-update add procfs boot
rc-update add swap boot
rc-update add sysfs sysinit
rc-update add localmount boot
rc-update add sysctl boot

# Make grub use a menu

tee -a /etc/default/grub <<EOF
GRUB_TIMEOUT_STYLE=menu
GRUB_GFXMODE=1920x1080
GRUB_GFXPAYLOAD_LINUX=keep
GRUB_CMDLINE_LINUX="rootfstype=ext4 loglevel=3"
EOF
grub-mkconfig -o /boot/grub/grub.cfg

# Exiting the installation

exit
umount -a
poweroff