#!/bin/sh ### Modifiable variables KERNEL_VARIANT="lts" #KERNEL_VARIANT="virt" MICROCODE="intel" #MICROCODE="amd" BOOT_PARTITION_SIZE="256M" #==================================================# # Add basic dependencies apk update && apk add lsblk #==================================================# printf '\n' printf '==============Warning==============\n' printf '\n' printf 'This script will format your entire disk!\n' printf 'Make sure you know what you are doing!\n' printf 'The system will be installed on the EXT4 partition.\n' printf 'Unified Kernel Image (UKI) and Secure Boot\n' printf 'will be automatically enabled (if enabled in UEFI).\n' printf 'The default memory allocator will be set to mimalloc.\n' printf 'You can open this script and edit the "Modifiable Variables" section.\n' printf 'If you want to exit press Ctrl+C.\n' printf '\n' printf '==========Available disks==========\n' printf '\n' # Disk selector lsblk -d | tail -n+2 | awk '{print $1" "$4}' printf '\n' read -p "Select the disk on which you want to install the system: " SELECTED_DRIVE INSTALL_DRIVE=/dev/$SELECTED_DRIVE printf 'Your installation disk is '$INSTALL_DRIVE'\n' if [ "$INSTALL_DRIVE" = "/dev/sda" -o "$INSTALL_DRIVE" = "/dev/sdb" -o "$INSTALL_DRIVE" = "/dev/sdc" -o "$INSTALL_DRIVE" = "/dev/sdd" ] then BOOT_PART="$INSTALL_DRIVE"1 ROOT_PART="$INSTALL_DRIVE"2 printf 'Your BOOT partition is '$BOOT_PART'\n' printf 'Your ROOT partition is '$ROOT_PART'\n' fi if [ "$INSTALL_DRIVE" = "/dev/vda" -o "$INSTALL_DRIVE" = "/dev/vdb" -o "$INSTALL_DRIVE" = "/dev/vdc" -o "$INSTALL_DRIVE" = "/dev/vdd" ] then BOOT_PART="$INSTALL_DRIVE"1 ROOT_PART="$INSTALL_DRIVE"2 printf 'Your BOOT partition is '$BOOT_PART'\n' printf 'Your ROOT partition is '$ROOT_PART'\n' fi if [ "$INSTALL_DRIVE" = "/dev/nvme0n1" -o "$INSTALL_DRIVE" = "/dev/nvme0n2" -o "$INSTALL_DRIVE" = "/dev/nvme0n3" -o "$INSTALL_DRIVE" = "/dev/nvme0n4" ] then BOOT_PART="$INSTALL_DRIVE"p1 ROOT_PART="$INSTALL_DRIVE"p2 printf 'Your BOOT partition is '$BOOT_PART'\n' printf 'Your ROOT partition is '$ROOT_PART'\n' fi printf '\n' #==================================================# # Modify installation script sed -i '7i BOOTLOADER="none"' /usr/sbin/setup-disk #==================================================# # Add repos rm /etc/apk/repositories printf 'http://ftp.icm.edu.pl/pub/Linux/distributions/alpine/edge/main\n' >> /etc/apk/repositories printf 'http://ftp.icm.edu.pl/pub/Linux/distributions/alpine/edge/community\n' >> /etc/apk/repositories printf 'http://ftp.icm.edu.pl/pub/Linux/distributions/alpine/edge/testing\n' >> /etc/apk/repositories #==================================================# # Add disk packages apk update && apk add dosfstools e2fsprogs efibootmgr #==================================================# # Cleaning disk dd if=/dev/zero of=$INSTALL_DRIVE bs=4096 count=1 sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk $INSTALL_DRIVE d # delete partition 1 # delete partition 1 d # delete partition 2 # delete partition 2 d # delete partition 3 # delete partition 3 d # delete partition 4 # delete partition 4 d # delete partition 5 # delete partition 5 p # print the in-memory partition table w # write the partition table q # and we're done EOF #==================================================# # Make partition table sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk $INSTALL_DRIVE g # set gpt table n # new partition p # primary partition 1 # partition number 1 # default - start at beginning of disk +$BOOT_PARTITION_SIZE # EFI parttion t # change partition type step 1 ef # change partition type step 2 n # new partition p # primary partition 2 # partion number 2 # default, start immediately after preceding partition # default, extend partition to end of disk a # make a partition bootable 1 # bootable partition is partition 1 -- /dev/sda1 p # print the in-memory partition table w # write the partition table q # and we're done EOF #==================================================# # Format partitions mkfs.vfat -F 32 $BOOT_PART && fatlabel $BOOT_PART ESP && mkfs.ext4 -F -L "Alpine Linux" $ROOT_PART #==================================================# # Mount partitions mount -t ext4 $ROOT_PART /mnt && mkdir -p /mnt/boot && mount -t vfat $BOOT_PART /mnt/boot && rm -rf /mnt/lost+found #==================================================# # Base install setup-disk -m sys /mnt #==================================================# # Create UKI dirs mkdir -p /mnt/etc/kernel && mkdir -p /mnt/etc/kernel-hooks.d #==================================================# # Create cmdline blkid $ROOT_PART | awk '{print $4}' | sed 's/"//g' $1 >> root_uuid.txt ROOT_UUID=$(cat root_uuid.txt) rm root_uuid.txt printf 'root='$ROOT_UUID' modules=sd-mod,usb-storage,ext4 rootfstype=ext4 rw '$MICROCODE'_iommu=on sysrq_always_enabled=1 audit=0 quiet loglevel=3 bgrt_disable\n' >> /mnt/etc/kernel/cmdline #==================================================# # Create UKI update script printf '#!/bin/sh\n' >> /mnt/etc/kernel-hooks.d/99-zz_uki.sh printf 'uki=/boot/alpine.efi\n' >> /mnt/etc/kernel-hooks.d/99-zz_uki.sh printf 'ukify build --linux /boot/'vmlinuz-$KERNEL_VARIANT' --initrd /boot/'$MICROCODE-ucode.img' --initrd /boot/'initramfs-$KERNEL_VARIANT' --cmdline @/etc/kernel/cmdline --os-release @/usr/lib/os-release --output $uki\n' >> /mnt/etc/kernel-hooks.d/99-zz_uki.sh printf 'sbctl sign $uki\n' >> /mnt/etc/kernel-hooks.d/99-zz_uki.sh chmod a+x /mnt/etc/kernel-hooks.d/99-zz_uki.sh #==================================================# # Stuff in chroot cat << EOF | chroot /mnt apk add ukify sbctl systemd-efistub mimalloc2 sbctl create-keys && sbctl enroll-keys -m ; apk add $MICROCODE-ucode kernel-hooks sed -i '3i LD_PRELOAD=/usr/lib/libmimalloc.so.2' /etc/profile sed -i '4i' /etc/profile EOF #==================================================# # Add bootable UEFI entry efibootmgr -c -d $INSTALL_DRIVE -L "Alpine Linux" -l '\alpine.efi' -u #==================================================# # Unmount partitions and reboot umount $BOOT_PART ; umount $ROOT_PART ; reboot #==================================================#