add: Add image creation data

This commit is contained in:
Christian Goeschel Ndjomouo 2024-11-17 05:11:35 +00:00
parent 26455546be
commit ef92a0684a
24 changed files with 380 additions and 0 deletions

1
VERSION Normal file

@ -0,0 +1 @@
0.1

0
asahi.install.images/.gitignore vendored Normal file

116
build.sh Executable file

@ -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

48
dependencies.sh Executable file

@ -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

0
mkosi.cache/.gitignore vendored Normal file

50
mkosi.conf Normal file

@ -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

0
mkosi.output/.gitignore vendored Normal file

15
mkosi.skeleton/boot.sh Executable file

@ -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

@ -0,0 +1,3 @@
search.fs_uuid BOOT_UUID root
set prefix=($root)'/grub'
configfile $prefix/grub.cfg

@ -0,0 +1,6 @@
Section "OutputClass"
Identifier "appledrm"
MatchDriver "apple"
Driver "modesetting"
Option "PrimaryGPU" "true"
EndSection

@ -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

@ -0,0 +1 @@
deb https://thomas.glanzmann.de/asahi testing main

Binary file not shown.

@ -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"

3
mkosi.skeleton/etc/fstab Normal file

@ -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

@ -0,0 +1 @@
asahi-debian

1
mkosi.skeleton/etc/hosts Normal file

@ -0,0 +1 @@
127.0.0.1 localhost asahi-debian

@ -0,0 +1 @@
root=UUID=ROOT_UUID root

@ -0,0 +1 @@
uninitialized

@ -0,0 +1,2 @@
blacklist brcmfmac
blacklist brcmutil

@ -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

@ -0,0 +1 @@
nameserver 8.8.8.8

@ -0,0 +1,6 @@
network={
ssid="linksys"
scan_ssid=1
key_mgmt=WPA-PSK
psk="password"
}

68
mkosi.skeleton/post-install.sh Executable file

@ -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 <<EOF
#search.fs_uuid "${BOOT_UUID}" root
#set prefix=(\$root)'/grub'
#configfile \$prefix/grub.cfg
#EOF
log "Creating /efi/EFI/BOOT/grub.cfg"
cat > /efi/EFI/BOOT/grub.cfg <<EOF
search --no-floppy --fs-uuid --set=dev ${BOOT_UUID}
set prefix=(\$dev)/grub
export \$prefix
configfile \$prefix/grub.cfg
EOF
log "Creating /efi/EFI/debian/grub.cfg"
cat > /efi/EFI/debian/grub.cfg <<EOF
search --no-floppy --fs-uuid --set=dev ${BOOT_UUID}
set prefix=(\$dev)/grub
export \$prefix
configfile \$prefix/grub.cfg
EOF
INITRD="$(ls -1 /boot/initrd* | cut -d/ -f3 | sort | head -1)"
VMLINUZ="$(ls -1 /boot/vmlinuz* | cut -d/ -f3 | sort | head -1)"
log "Creating /boot/grub/grub.cfg"
cat > /boot/grub/grub.cfg <<EOF
load_video
insmod gzio
insmod part_gpt
insmod ext2
search --no-floppy --fs-uuid --set=root ${BOOT_UUID}
echo "Loading Linux ${VMLINUZ} ..."
linux /${VMLINUZ} root=UUID=${ROOT_UUID} rw net.ifnames=0
echo "Loading Linux ${INITRD} ..."
initrd /${INITRD}
boot
EOF
log "Setting hostname"
echo "asahi-debian" > /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