Last active
December 26, 2022 05:17
-
-
Save MakiseKurisu/7b2f4122f11ce551eecb9b52c568a5dd to your computer and use it in GitHub Desktop.
Install vanilla UEFI Debian for ESPRESSOBin
This file contains 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
# You will need a real Debian machine to perform cross debootstrap | |
# Debian on WSL does not work | |
# Enter root mode | |
sudo -i | |
# Install dependency | |
apt update && apt install -y btrfs-progs dosfstools qemu-user-static debootstrap | |
# Set up partition table and file systems | |
dd if=/dev/zero of=/dev/mmcblk0 bs=1M count=8 | |
(echo g; echo n; echo ''; echo ''; echo '+512M'; echo t; echo 1; echo n; echo ''; echo ''; echo ''; echo w) | fdisk /dev/mmcblk0 | |
mkfs.fat -F32 /dev/mmcblk0p1 | |
mkfs.btrfs -f /dev/mmcblk0p2 | |
# Create subvolumes | |
mount -o compress=zstd /dev/mmcblk0p2 /mnt | |
btrfs subvolume create /mnt/@ | |
btrfs subvolume create /mnt/@home | |
btrfs subvolume create /mnt/@root | |
umount /mnt | |
# Mount partitions | |
mount -o compress=zstd,subvol=@ /dev/mmcblk0p2 /mnt | |
mkdir -p /mnt/home | |
mount -o compress=zstd,subvol=@home /dev/mmcblk0p2 /mnt/home | |
mkdir -p /mnt/root | |
mount -o compress=zstd,subvol=@root /dev/mmcblk0p2 /mnt/root | |
mkdir -p /mnt/boot/efi | |
mount /dev/mmcblk0p1 /mnt/boot/efi | |
# First stage debootstrap | |
# Using Tsinghua University's mirror, which can be change to any valid Debian mirrors or leave as empty | |
debootstrap --arch=arm64 --foreign --components=main,non-free,contrib --include=locales,makedev bullseye /mnt https://mirrors.tuna.tsinghua.edu.cn/debian | |
# Set up fstab | |
echo "UUID=$(blkid -s UUID -o value /dev/mmcblk0p2) / btrfs defaults,subvol=@,compress=zstd 0 0" >> /mnt/etc/fstab | |
echo "UUID=$(blkid -s UUID -o value /dev/mmcblk0p2) /home btrfs defaults,subvol=@home,compress=zstd 0 0" >> /mnt/etc/fstab | |
echo "UUID=$(blkid -s UUID -o value /dev/mmcblk0p2) /root btrfs defaults,subvol=@root,compress=zstd 0 0" >> /mnt/etc/fstab | |
echo "UUID=$(blkid -s UUID -o value /dev/mmcblk0p1) /boot/efi vfat defaults 1 2" >> /mnt/etc/fstab | |
echo "proc /proc proc defaults 0 0" >> /mnt/etc/fstab | |
# Enter chroot | |
cp /usr/bin/qemu-aarch64-static /mnt/usr/bin/ | |
LANG=C.UTF-8 chroot /mnt /usr/bin/qemu-aarch64-static /bin/bash | |
# Second stage debootstrap | |
/debootstrap/debootstrap --second-stage | |
# Create device files | |
mount none /proc -t proc | |
cd /dev | |
MAKEDEV | |
MAKEDEV update | |
# Configure locale | |
dpkg-reconfigure locales | |
# Configure timezone | |
dpkg-reconfigure tzdata | |
# Change root password | |
passwd | |
# Create new user for SSH login | |
useradd -m -s /bin/bash user | |
passwd user | |
usermod -a -G sudo user | |
# Add additional repos | |
nano /etc/apt/sources.list | |
# Add kernel hook for copying dtbs, which is required for U-Boot to boot grub | |
mkdir -p /boot/efi/dtb | |
cat <<'EOF' >> /etc/kernel/postinst.d/copy-dtb | |
#!/bin/sh | |
set -e | |
version="$1" | |
echo Copying current dtb files to /boot/efi/dtb.... | |
cp -r /usr/lib/linux-image-${version}/* /boot/efi/dtb/ | |
EOF | |
chmod +x /etc/kernel/postinst.d/copy-dtb | |
# Configure network | |
cat <<'EOF' >> /etc/network/interfaces | |
auto lo | |
iface lo inet loopback | |
auto eth0 | |
iface eth0 inet manual | |
auto wan | |
iface wan inet dhcp | |
pre-up ip link set eth0 up | |
EOF | |
# Install additional packages | |
# At minimum linux-image-arm64 and grub-efi are required | |
apt update && apt install -y openssh-server sudo linux-image-arm64 grub-efi haveged zram-tools tmux bash-completion | |
printf "SIZE=512\nPRIORITY=100\nALGO=zstd\n" >> /etc/default/zramswap | |
systemctl enable ssh haveged zramswap | |
# Exit and remount devices for grub | |
exit | |
for i in /dev /dev/pts /proc /sys /run; do mount -B $i /mnt$i; done | |
LANG=en_US.UTF-8 chroot /mnt /usr/bin/qemu-aarch64-static /bin/bash | |
# Install grub | |
grub-install --target=arm64-efi --efi-directory=/boot/efi --removable | |
sed -i "s/GRUB_CMDLINE_LINUX_DEFAULT=\"quiet\"/GRUB_CMDLINE_LINUX_DEFAULT=\"console=ttyMV0,115200 earlycon=ar3700_uart,0xd0012000 loglevel=1 usb-storage.quirks=0x2537:0x1066:u,0x2537:0x1068:u mtdparts=spi0.0:1536k(uboot),64k(uboot-environment),-(reserved)\"/" /etc/default/grub | |
GRUB_DISABLE_OS_PROBER=true update-grub | |
# Clean up | |
apt-get clean | |
# Exit chroot | |
exit | |
rm /mnt/usr/bin/qemu-aarch64-static | |
umount /mnt/boot/efi | |
umount /mnt | |
sync | |
# After the installation, you need to upgrade your U-Boot to the latest mainline, | |
# which can be extracted from Armbian package linux-u-boot-espressobin-edge. | |
# Once you flash the U-Boot, you need to backup your mac address, | |
# and then run `env default -f -a` to clear preexisting congfiguration. | |
# If you do not backup your mac address you will get a random new one on every boot. | |
# See Final steps in https://marcin.juszkiewicz.com.pl/2021/02/15/ebbr-on-espressobin/ | |
# Then you will need to add an entry to boot grubaa64.efi as a workaround, | |
# since the default bootaa64.efi cannot boot the device. | |
# Something like (check your existing bootcmd first with `env print bootcmd): | |
# env set grub_bootcmd "load mmc 0:1 ${fdt_addr_r} /dtb/marvell/armada-3720-espressobin.dtb;load mmc 0:1 ${kernel_addr_r} /efi/boot/grubaa64.efi;bootefi ${kernel_addr_r} ${fdt_addr_r};" | |
# env set bootcmd "un grub_bootcmd;run distro_bootcmd" | |
# env save | |
# For more info on U-Boot please visit: https://www.armbian.com/espressobin/ | |
# In some cases your U-Boot will enter a reset loop, with the final output like this: | |
# BootOrder not defined | |
# EFI boot manager: Cannot load any image | |
# 856064 bytes read in 44 ms (18.6 MiB/s) | |
# Booting /efi\boot\bootaa64.efi | |
# Reset System | |
# resetting ... | |
# In this case you have to boot your board manually: | |
# load mmc 0:1 ${kernel_addr_r} /EFI/BOOT/grubaa64.efi | |
# bootefi ${kernel_addr_r} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment