diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..ceab6e1 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1 \ No newline at end of file diff --git a/asahi.install.images/.gitignore b/asahi.install.images/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..126b3a9 --- /dev/null +++ b/build.sh @@ -0,0 +1,116 @@ +#!/usr/bin/env bash + +PROJECT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +MKOSI_OUT_DIR="${PROJECT_DIR}/mkosi.output" +MKOSI_CACHE_DIR="${PROJECT_DIR}/mkosi.cache" +IMAGE_VERSION="$( head -n1 "${PROJECT_DIR}"/VERSION )" +IMAGE_ID="asahi-debian-12-base" +MKOSI_ROOT_FS_DIR_NAME="${IMAGE_ID}_${IMAGE_VERSION}" +MOUNTPOINT_DIR="${PROJECT_DIR}/mnt" +ASAHI_INSTALL_IMAGES_DIR="${PROJECT_DIR}/asahi.install.images" + +EFI_UUID=$(uuidgen | tr '[a-z]' '[A-Z]' | cut -c1-8 | fold -w4 | paste -sd '-') +ROOT_UUID=$(uuidgen) +BOOT_UUID=$(uuidgen) + + +function log() { + # In this case we are not passing command line arguments to 'echo' + # but instead an output string + # shellcheck disable=SC2145 + echo "[$(tput setaf 2)$(tput bold)info$(tput sgr0)] ${@}" +} + +function unmount_images() { + [[ -n "$(findmnt -n "${MOUNTPOINT_DIR}"/efi)" ]] && umount -Rf "${MOUNTPOINT_DIR}"/efi && log "Unmounted ${MOUNTPOINT_DIR}/efi" + [[ -n "$(findmnt -n "${MOUNTPOINT_DIR}"/boot)" ]] && umount -Rf "${MOUNTPOINT_DIR}"/boot && log "Unmounted ${MOUNTPOINT_DIR}/boot" + [[ -n "$(findmnt -n "${MOUNTPOINT_DIR}")" ]] && umount -Rf "${MOUNTPOINT_DIR}" && log "Unmounted ${MOUNTPOINT_DIR}" +} + +function mount_images() { + [[ -z "$(findmnt -n "${MOUNTPOINT_DIR}")" ]] && mount -o loop "${ASAHI_INSTALL_IMAGES_DIR}"/root.img "${MOUNTPOINT_DIR}" && log "Mounted ${ASAHI_INSTALL_IMAGES_DIR}/root.img to ${MOUNTPOINT_DIR}" + [[ -z "$(findmnt -n "${MOUNTPOINT_DIR}"/boot)" ]] && mount -o loop "${ASAHI_INSTALL_IMAGES_DIR}"/boot.img "${MOUNTPOINT_DIR}"/boot && log "Mounted ${ASAHI_INSTALL_IMAGES_DIR}/boot.img to ${MOUNTPOINT_DIR}/boot" + [[ -z "$(findmnt -n "${MOUNTPOINT_DIR}"/boot/efi)" ]] && mount --bind "${ASAHI_INSTALL_IMAGES_DIR}"/esp/ "${MOUNTPOINT_DIR}"/boot/efi/ && log "Bound ${ASAHI_INSTALL_IMAGES_DIR}/esp/ to ${MOUNTPOINT_DIR}/boot/efi/" +} + +function create_asahi_install_images() { + unmount_images + # Get the absolute path to the mkosi generated root filesystem + mkosi_rootfs_absolute_path="$( realpath -- "$(find "${MKOSI_OUT_DIR}" -type d -iname "${MKOSI_ROOT_FS_DIR_NAME}" | sort | head -1 )")" + + mkdir "${MOUNTPOINT_DIR}" + mkdir -p "${MOUNTPOINT_DIR}"/efi + + + log "Creating Asahi installation images ..." + rm -rf "${ASAHI_INSTALL_IMAGES_DIR:?}"/* + rm -rf "${mkosi_rootfs_absolute_path}"/var/lib/apt/lists/* + + log "Creating ${ASAHI_INSTALL_IMAGES_DIR}/efi.img ..." + fallocate -l "512MB" "${ASAHI_INSTALL_IMAGES_DIR}"/efi.img + + log "Creating ${ASAHI_INSTALL_IMAGES_DIR}/boot.img ..." + fallocate -l "2G" "${ASAHI_INSTALL_IMAGES_DIR}"/boot.img + + log "Creating ${ASAHI_INSTALL_IMAGES_DIR}/root.img ..." + fallocate -l "8G" "${ASAHI_INSTALL_IMAGES_DIR}"/root.img + + log "Creating fat filesystem on efi.img" + mkfs.msdos "${ASAHI_INSTALL_IMAGES_DIR}"/efi.img + + log "Creating ext2 filesystem on boot.img" + mkfs.ext2 -U "${BOOT_UUID}" -L debian-boot -b 4096 "${ASAHI_INSTALL_IMAGES_DIR}"/boot.img + + log "Creating ext4 filesystem on root.img" + mkfs.ext4 -U "${ROOT_UUID}" -L debian-root -b 4096 "${ASAHI_INSTALL_IMAGES_DIR}"/root.img + + mount -o loop "${ASAHI_INSTALL_IMAGES_DIR}"/root.img "${MOUNTPOINT_DIR}" + log "Mounted ${ASAHI_INSTALL_IMAGES_DIR}/root.img to ${MOUNTPOINT_DIR}" + + mkdir -p "${MOUNTPOINT_DIR}"/boot + mount -o loop "${ASAHI_INSTALL_IMAGES_DIR}"/boot.img "${MOUNTPOINT_DIR}"/boot + log "Mounted ${ASAHI_INSTALL_IMAGES_DIR}/boot.img to ${MOUNTPOINT_DIR}/boot" + + mkdir -p "${MOUNTPOINT_DIR}"/efi + mount -o loop "${ASAHI_INSTALL_IMAGES_DIR}"/efi.img "${MOUNTPOINT_DIR}"/efi + log "Mounted ${ASAHI_INSTALL_IMAGES_DIR}/efi.img to ${MOUNTPOINT_DIR}/efi" + + log 'Copying files to root.img' + rsync -aHAX --exclude '/tmp/*' --exclude '/boot/*' --exclude '/home/*' --exclude '/efi' "${mkosi_rootfs_absolute_path}/" "${MOUNTPOINT_DIR}" + log "Copying files to boot.img" + rsync -aHAX "${mkosi_rootfs_absolute_path}"/boot/ "${MOUNTPOINT_DIR}"/boot + + log "Setting pre-defined uuid (${EFI_UUID}) for efi vfat partition in /etc/fstab" + sed -i "s/EFI_UUID/${EFI_UUID}/" "${MOUNTPOINT_DIR}"/etc/fstab + + log "Setting uuid (${BOOT_UUID}) for ext2 boot partition in /etc/fstab" + sed -i "s/BOOT_UUID/${BOOT_UUID}/" "${MOUNTPOINT_DIR}"/etc/fstab + + log "Setting uuid (${ROOT_UUID}) for ext4 partition in /etc/fstab" + sed -i "s/ROOT_UUID/${ROOT_UUID}/" "${MOUNTPOINT_DIR}"/etc/fstab + + arch-chroot "${MOUNTPOINT_DIR}" grub-editenv create + + sed -i "s/ROOT_UUID/${ROOT_UUID}/" "${MOUNTPOINT_DIR}"/etc/kernel/cmdline + arch-chroot "${MOUNTPOINT_DIR}" grub-install --target=arm64-efi --efi-directory=/efi + arch-chroot "${MOUNTPOINT_DIR}" ./post-install.sh "${BOOT_UUID}" "${ROOT_UUID}" +} + +mkosi clean +mkosi +create_asahi_install_images + +log "Copying files ..." +rsync -aHAX "${MOUNTPOINT_DIR}"/efi/ "${ASAHI_INSTALL_IMAGES_DIR}"/esp/ +rsync -aHAX "${MOUNTPOINT_DIR}"/boot/efi/ "${ASAHI_INSTALL_IMAGES_DIR}"/esp/ + +cd "${ASAHI_INSTALL_IMAGES_DIR}" || exit 1 + +echo "${EFI_UUID}" > "${PROJECT_DIR}"/efi.uuid + +#log "Compressing boot.img root.img and esp/ ..." +#zip -r9 "${PROJECT_DIR}"/debian-12-base.zip . + +#log "Unmounting umages ..." +#unmount_images + diff --git a/dependencies.sh b/dependencies.sh new file mode 100755 index 0000000..b18a5fe --- /dev/null +++ b/dependencies.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +declare -a PACKAGES=( build-essential \ +bash \ +git \ +mount \ +zip \ +uuid-runtime \ +locales \ +gcc-aarch64-linux-gnu \ +libc6-dev \ +device-tree-compiler \ +imagemagick \ +ccache \ +eatmydata \ +debootstrap \ +pigz \ +libncurses-dev \ +qemu-user-static \ +binfmt-support \ +rsync \ +git \ +bc \ +kmod \ +cpio \ +libncurses5-dev \ +libelf-dev:native \ +libssl-dev \ +dwarves \ +zstd \ +lsb-release \ +clang-15 \ +lld-15 \ +debhelper \ +clang-15 \ +flex \ +bison \ +libclang-dev \ +arch-install-scripts \ +curl \ +bubblewrap \ +mkosi \ ) + +# shellcheck disable=SC2048 +for pkg in ${PACKAGES[*]}; do + sudo apt install -y "${pkg}" +done + diff --git a/mkosi.cache/.gitignore b/mkosi.cache/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/mkosi.conf b/mkosi.conf new file mode 100644 index 0000000..c997a51 --- /dev/null +++ b/mkosi.conf @@ -0,0 +1,50 @@ +[Distribution] +Distribution=debian +Release=bookworm + +[Match] +Architecture=aarch64 + +[Output] +Format=directory +ImageId=asahi-debian-12-base +ImageVersion=0.1 + +[Content] +Bootable=no +WithDocs=True +Environment= + KERNEL_INSTALL_BYPASS=0 +Packages= + initramfs-tools + pciutils + wpasupplicant + tcpdump + vim + tmux + vlan + ntpdate + parted + curl + wget + grub-efi-arm64 + mtr-tiny + dbus + ca-certificates + sudo + openssh-client + mtools + dhcpcd-base + gdisk + cryptsetup + wireless-regdb + systemd-boot + tree + lvm2 + ifupdown + iproute2 + network-manager + iputils-ping + zstd + + diff --git a/mkosi.output/.gitignore b/mkosi.output/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/mkosi.skeleton/boot.sh b/mkosi.skeleton/boot.sh new file mode 100755 index 0000000..9b94c02 --- /dev/null +++ b/mkosi.skeleton/boot.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +echo 'grub-efi-arm64 grub2/update_nvram boolean false' | chroot /target debconf-set-selections +echo 'grub-efi-arm64 grub2/force_efi_extra_removable boolean true' | chroot /target debconf-set-selections +chroot /target apt-get remove -y grub-efi-arm64-signed +chroot /target apt-get install -y ntpdate +chroot /target grub-install --removable /boot/efi +rm /target/boot/efi/EFI/BOOT/fbaa64.efi +rm /target/boot/efi/EFI/debian/fbaa64.efi +chroot /target wget https://tg.st/u/k.deb +chroot /target dpkg -i k.deb +chroot /target rm k.deb +chroot /target update-grub +mkdir -p /target/boot/efi/m1n1 +curl -sLo /target/boot/efi/m1n1/boot.bin https://tg.st/u/u-boot.bin diff --git a/mkosi.skeleton/efi/EFI/boot/grub.cfg b/mkosi.skeleton/efi/EFI/boot/grub.cfg new file mode 100644 index 0000000..1554fa2 --- /dev/null +++ b/mkosi.skeleton/efi/EFI/boot/grub.cfg @@ -0,0 +1,3 @@ +search.fs_uuid BOOT_UUID root +set prefix=($root)'/grub' +configfile $prefix/grub.cfg diff --git a/mkosi.skeleton/etc/X11/xorg.conf.d/30-modeset.conf b/mkosi.skeleton/etc/X11/xorg.conf.d/30-modeset.conf new file mode 100644 index 0000000..29e206c --- /dev/null +++ b/mkosi.skeleton/etc/X11/xorg.conf.d/30-modeset.conf @@ -0,0 +1,6 @@ +Section "OutputClass" + Identifier "appledrm" + MatchDriver "apple" + Driver "modesetting" + Option "PrimaryGPU" "true" +EndSection diff --git a/mkosi.skeleton/etc/apt/sources.list b/mkosi.skeleton/etc/apt/sources.list new file mode 100644 index 0000000..a42b123 --- /dev/null +++ b/mkosi.skeleton/etc/apt/sources.list @@ -0,0 +1,5 @@ +deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware +deb-src http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware + +deb http://deb.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware +deb-src http://deb.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware diff --git a/mkosi.skeleton/etc/apt/sources.list.d/glanzmann.list b/mkosi.skeleton/etc/apt/sources.list.d/glanzmann.list new file mode 100644 index 0000000..1317d18 --- /dev/null +++ b/mkosi.skeleton/etc/apt/sources.list.d/glanzmann.list @@ -0,0 +1 @@ +deb https://thomas.glanzmann.de/asahi testing main diff --git a/mkosi.skeleton/etc/apt/trusted.gpg.d/thomas-glanzmann.gpg b/mkosi.skeleton/etc/apt/trusted.gpg.d/thomas-glanzmann.gpg new file mode 100644 index 0000000..c0c8a03 Binary files /dev/null and b/mkosi.skeleton/etc/apt/trusted.gpg.d/thomas-glanzmann.gpg differ diff --git a/mkosi.skeleton/etc/default/grub b/mkosi.skeleton/etc/default/grub new file mode 100644 index 0000000..3147d33 --- /dev/null +++ b/mkosi.skeleton/etc/default/grub @@ -0,0 +1,41 @@ +# If you change this file, run 'update-grub' afterwards to update +# /boot/grub/grub.cfg. +# For full documentation of the options in this file, see: +# info -f grub -n 'Simple configuration' + +GRUB_DEFAULT=saved +GRUB_TIMEOUT=5 +GRUB_DISTRIBUTOR="$(lsb_release -i -s 2> /dev/null || echo Debian)" +GRUB_CMDLINE_LINUX_DEFAULT="quiet" +GRUB_CMDLINE_LINUX="" + +# If your computer has multiple operating systems installed, then you +# probably want to run os-prober. However, if your computer is a host +# for guest OSes installed via LVM or raw disk devices, running +# os-prober can cause damage to those guest OSes as it mounts +# filesystems to look for things. +GRUB_DISABLE_OS_PROBER=true + +# Uncomment to enable BadRAM filtering, modify to suit your needs +# This works with Linux (no patch required) and with any kernel that obtains +# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...) +#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef" + +# Uncomment to disable graphical terminal +#GRUB_TERMINAL=console +GRUB_TERMINAL_OUTPUT=gfxterm +# The resolution used on graphical terminal +# note that you can use only modes which your graphic card supports via VBE +# you can see them in real GRUB with the command `vbeinfo' +#GRUB_GFXMODE=640x480 + +# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux +#GRUB_DISABLE_LINUX_UUID=true + +# Uncomment to disable generation of recovery mode menu entries +GRUB_DISABLE_RECOVERY="true" +GRUB_ENABLE_BLSCFG=true +GRUB_FONT=/boot/grub/fonts/unicode.pf2 +GRUB_DISABLE_SUBMENU=true +# Uncomment to get a beep at grub start +#GRUB_INIT_TUNE="480 440 1" diff --git a/mkosi.skeleton/etc/fstab b/mkosi.skeleton/etc/fstab new file mode 100644 index 0000000..555bc5e --- /dev/null +++ b/mkosi.skeleton/etc/fstab @@ -0,0 +1,3 @@ +UUID=EFI_UUID /efi vfat umask=0077,shortname=winnt 0 2 +UUID=BOOT_UUID /boot ext2 defaults 0 2 +UUID=ROOT_UUID / ext4 defaults 0 1 \ No newline at end of file diff --git a/mkosi.skeleton/etc/hostname b/mkosi.skeleton/etc/hostname new file mode 100644 index 0000000..1c6810f --- /dev/null +++ b/mkosi.skeleton/etc/hostname @@ -0,0 +1 @@ +asahi-debian \ No newline at end of file diff --git a/mkosi.skeleton/etc/hosts b/mkosi.skeleton/etc/hosts new file mode 100644 index 0000000..05dfc8a --- /dev/null +++ b/mkosi.skeleton/etc/hosts @@ -0,0 +1 @@ +127.0.0.1 localhost asahi-debian diff --git a/mkosi.skeleton/etc/kernel/cmdline b/mkosi.skeleton/etc/kernel/cmdline new file mode 100644 index 0000000..c263ea9 --- /dev/null +++ b/mkosi.skeleton/etc/kernel/cmdline @@ -0,0 +1 @@ +root=UUID=ROOT_UUID root \ No newline at end of file diff --git a/mkosi.skeleton/etc/machine-id b/mkosi.skeleton/etc/machine-id new file mode 100644 index 0000000..4f9d9d5 --- /dev/null +++ b/mkosi.skeleton/etc/machine-id @@ -0,0 +1 @@ +uninitialized \ No newline at end of file diff --git a/mkosi.skeleton/etc/modprobe.d/blacklist.conf b/mkosi.skeleton/etc/modprobe.d/blacklist.conf new file mode 100644 index 0000000..60dfbb9 --- /dev/null +++ b/mkosi.skeleton/etc/modprobe.d/blacklist.conf @@ -0,0 +1,2 @@ +blacklist brcmfmac +blacklist brcmutil diff --git a/mkosi.skeleton/etc/network/interfaces b/mkosi.skeleton/etc/network/interfaces new file mode 100644 index 0000000..3691cbc --- /dev/null +++ b/mkosi.skeleton/etc/network/interfaces @@ -0,0 +1,10 @@ +# interfaces(5) file used by ifup(8) and ifdown(8) +# Include files from /etc/network/interfaces.d: +source /etc/network/interfaces.d/* + +allow-hotplug eth0 +iface eth0 inet dhcp + +# allow-hotplug wlan0 +iface wlan0 inet dhcp + wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf diff --git a/mkosi.skeleton/etc/resolv.conf b/mkosi.skeleton/etc/resolv.conf new file mode 100644 index 0000000..cae093a --- /dev/null +++ b/mkosi.skeleton/etc/resolv.conf @@ -0,0 +1 @@ +nameserver 8.8.8.8 diff --git a/mkosi.skeleton/etc/wpa_supplicant/wpa_supplicant.conf b/mkosi.skeleton/etc/wpa_supplicant/wpa_supplicant.conf new file mode 100644 index 0000000..1e1bbff --- /dev/null +++ b/mkosi.skeleton/etc/wpa_supplicant/wpa_supplicant.conf @@ -0,0 +1,6 @@ +network={ + ssid="linksys" + scan_ssid=1 + key_mgmt=WPA-PSK + psk="password" +} diff --git a/mkosi.skeleton/post-install.sh b/mkosi.skeleton/post-install.sh new file mode 100755 index 0000000..19a4f94 --- /dev/null +++ b/mkosi.skeleton/post-install.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +BOOT_UUID=${1} +ROOT_UUID=${2} + +function log() { + # In this case we are not passing command line arguments to 'echo' + # but instead an output string + # shellcheck disable=SC2145 + echo "[$(tput setaf 2)$(tput bold)info$(tput sgr0)] ${@}" +} + +log "Installing Firmware, UEFI Bootloader and Linux Asahi kernel" +apt update +apt install -y firmware-linux m1n1 linux-image-asahi +apt clean +rm -rf /var/lib/apt/lists/* + +log "Creating /efi/EFI/BOOT/" +mkdir -p /efi/EFI/BOOT +cp /usr/lib/grub/arm64-efi/monolithic/grubaa64.efi /efi/EFI/BOOT/bootaa64.efi + +#cat > /efi/EFI/boot/grub.cfg < /efi/EFI/BOOT/grub.cfg < /efi/EFI/debian/grub.cfg < /boot/grub/grub.cfg < /etc/hostname + +log "Changing 'root' user password" +passwd root + +log "Creating 'asahi' user and setting new password" +useradd -m -s /bin/bash asahi +passwd asahi