- Any live usb bootable.
- Alpine Linux minirootfs archive, we can get it here. We can choose
alpine-minirootfs-3.20.2-x86_64.tar.gz
. - Some partitions, for root system (/), efi (if you have uefi machine) and swap (optional).
- Basic commandline knowledge.
We need to do some steps here, It's not hard at all. I took some steps from here as reference.
-
Format and mount partitions.
$ sudo mkfs.ext4 /dev/vda1 $ sudo mkswap /dev/vda2 $ sudo mount /dev/vda1 /mnt/ $ sudo swapon /dev/vda2
PS : I only use 2 partitions here, you can adjust as you wish.
-
Extract rootfs archive.
$ cd /mnt $ sudo tar -xf minirootfs-3.20.2-x86_64.tar.gz
-
Mount some filesystems and do chroot.
$ sudo mount -o bind /proc proc/ $ sudo mount -o bind /dev dev/ $ sudo mount -o bind /sys sys/ $ sudo chroot /mnt /bin/sh
-
Doing some setups.
There are some setups we need to run, setup scripts are unavailable by default, so we need to get them first.
# echo "nameserver 8.8.8.8" > /etc/resolv.conf # apk add alpine-conf
- setup hostname.
# setup-hostname
- setup network.
# setup-interface
- setup repository. I don't mind using the default repository, if you insist to configure it, you can run this command :
# setup-apkrepos -f
-
Install base packages.
minirootfs archive has litte package, we still need to install some base pakages.
# apk update # apk add linux-lts linux-firmware-none acpi mkinitfs
-
Edit fstab.
# vi /etc/fstab
Example :
UUID=YOUR_PARTITION_UUID / ext4 errors=remount-ro 0 1 UUID=YOUR_PARTITION_UUID swap swap defaults 0 0
-
Add services to boot.
We need to add some services to boot in order to boot properly. Some service are still unavailable by default, we need install some packages first.
# apk add acpid busybox-openrc busybox-extras busybox-mdev-openrc
After those package are installed, we are good to enable services.
# rc-update add acpid default # rc-update add bootmisc boot # rc-update add crond default # rc-update add devfs sysinit # rc-update add dmesg sysinit # rc-update add hostname boot # rc-update add hwclock boot # rc-update add hwdrivers sysinit # rc-update add killprocs shutdown # rc-update add mdev sysinit # rc-update add modules boot # rc-update add mount-ro shutdown # rc-update add networking boot # rc-update add savecache shutdown # rc-update add seedrng boot # rc-update add swap boot
-
Handle bootloader stuffs.
We need to install bootloader tool. We will choose
grub
here, if you have other preferences feel free to adjust.# apk add grub grub-bios
We need to adjust
/etc/default/grub
so we can boot normally. Just add this line and we are good.GRUB_CMDLINE_LINUX_DEFAULT="root=UUID=5499bc10-9561-497d-be69-2148ac1554bb rw rootfstype=ext4 modules="sd-mod,usb-storage,ext4""
Update grub and install grub to disk.
# grub-mkconfig -o /boot/grub/grub.cfg # grub-install /dev/vda
-
Set root password.
Almost forgot, we need to set password for root user.
# passwd
-
Exit chroot and unmount some filesystems.
We need to exit chroot and unmount some filesystems we mount before.
# exit # umount proc # umount dev/ # umount sys/ # cd / # umount /mnt
-
Reboot.
After everything are done, let's reboot !
# reboot