Created
October 30, 2025 21:47
-
-
Save master-of-zen/fd8996e0a2e95e938075b2544b4bb622 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -e | |
| # --- Configuration --- | |
| # !! IMPORTANT !!: Verify and change this to your target disk. | |
| DISK='/dev/nvme0n1' | |
| # EFI partition size. 1G is generous and safe. | |
| EFI_PART_SIZE='1G' | |
| # ZFS pool name | |
| ZPOOL_NAME='apool' | |
| # ZFS compression algorithm | |
| ZFS_COMPRESSION='zstd-19' | |
| # --- End of Configuration --- | |
| # --- Check for ZFS modules --- | |
| if ! lsmod | grep -q zfs; then | |
| echo "ZFS modules not loaded. Please ensure you are running the extended version of the Alpine ISO." | |
| exit 1 | |
| fi | |
| # --- Partition the disk --- | |
| echo "--> Partitioning the disk: ${DISK}" | |
| sgdisk --zap-all ${DISK} | |
| sgdisk -n 1:0:+${EFI_PART_SIZE} -t 1:ef00 ${DISK} | |
| sgdisk -n 2:0:0 -t 2:bf00 ${DISK} | |
| # --- Create filesystems --- | |
| echo "--> Creating filesystems" | |
| mkfs.vfat -F32 ${DISK}p1 | |
| # --- Create and encrypt the ZFS pool --- | |
| echo "--> Creating encrypted ZFS pool: ${ZPOOL_NAME}" | |
| zpool create \ | |
| -o ashift=12 \ | |
| -o autotrim=on \ | |
| -O acltype=posixacl \ | |
| -O xattr=sa \ | |
| -O dnodesize=auto \ | |
| -O normalization=formD \ | |
| -O relatime=on \ | |
| -O compression=${ZFS_COMPRESSION} \ | |
| -O encryption=aes-256-gcm \ | |
| -O keyformat=passphrase \ | |
| -O keylocation=prompt \ | |
| -R /mnt \ | |
| ${ZPOOL_NAME} ${DISK}p2 | |
| # --- Create ZFS datasets --- | |
| echo "--> Creating ZFS datasets" | |
| zfs create -o canmount=off -o mountpoint=none ${ZPOOL_NAME}/ROOT | |
| zfs create -o canmount=noauto -o mountpoint=/ ${ZPOOL_NAME}/ROOT/default | |
| zfs mount ${ZPOOL_NAME}/ROOT/default | |
| zfs create -o canmount=off -o mountpoint=none ${ZPOOL_NAME}/DATA | |
| zfs create ${ZPOOL_NAME}/DATA/home | |
| zfs create -o mountpoint=/var ${ZPOOL_NAME}/DATA/var | |
| zfs create -o mountpoint=/root ${ZPOOL_NAME}/DATA/home/root | |
| # --- Mount the boot partition --- | |
| echo "--> Mounting boot partition" | |
| mkdir -p /mnt/boot | |
| mount ${DISK}p1 /mnt/boot | |
| # --- Install Alpine Linux --- | |
| echo "--> Installing Alpine Linux" | |
| setup-disk -m sys /mnt | |
| # --- Finalizing installation --- | |
| echo "--> Finalizing installation" | |
| # Copy ZFS pool cache | |
| cp /etc/zfs/zpool.cache /mnt/etc/zfs/ | |
| # Add ZFS to initramfs | |
| echo "zfs" >> /mnt/etc/mkinitfs/features.d/zfs.features | |
| # Chroot into the new system to configure boot | |
| chroot /mnt /bin/sh <<'EOF' | |
| set -e | |
| # Update initramfs | |
| mkinitfs | |
| # Install bootloader | |
| apk add grub-efi | |
| grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=alpine --removable | |
| # Generate grub config | |
| grub-mkconfig -o /boot/grub/grub.cfg | |
| EOF | |
| # --- Unmount and reboot --- | |
| echo "--> Installation complete. Unmounting filesystems." | |
| umount -R /mnt | |
| echo "--> You can now reboot the system." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment