Last active
April 26, 2021 02:17
-
-
Save GavinPacini/99e30904b039a34acefce0195d34c9cd to your computer and use it in GitHub Desktop.
Getting Debian to boot on Mac M1 - first principles
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
# Note, this is WIP. A proper tutorial will be published soon. | |
# This mainly serves as hosting the script so the Whonix forum members can review it. | |
# From within another Debian VM | |
sudo KERNEL='none' NOKERNEL='true' UPGRADE_SYSTEM='no' GRUB_INSTALL='no' grml-debootstrap \ | |
--debopt "--verbose --include=initramfs-tools,eatmydata,apt-transport-tor,python3.7,gpg,gpg-agent" \ | |
--arch arm64 \ | |
--filesystem ext4 \ | |
--force \ | |
--hostname host \ | |
--password=changeme \ | |
--release buster \ | |
--keep_src_list \ | |
--verbose \ | |
--vmfile \ | |
--vmsize 15G \ | |
--packages ./grml_packages \ | |
--target ./debian.raw | |
sudo mkdir -p "/mnt/debootstrap.grub" | |
sudo kpartx -asv ./debian.raw | |
sudo mount -o rw,suid,dev "/dev/mapper/loop0p1" "/mnt/debootstrap.grub" | |
sudo chroot /mnt/debootstrap.grub apt-get --yes --no-install-recommends install linux-image-arm64 linux-headers-arm64 | |
sudo truncate -s 2048M ./debian.grub.img | |
sudo losetup "/dev/loop1" ./debian.grub.img | |
sudo parted /dev/loop1 --script mktable gpt | |
sudo parted /dev/loop1 --script mkpart EFI fat16 1MiB 10MiB | |
sudo parted /dev/loop1 --script set 1 boot on | |
sudo parted /dev/loop1 --script mkpart LINUX ext4 10MiB 100% | |
sudo parted /dev/loop1 --script print | |
sudo mkfs.vfat -n EFI /dev/loop1p1 | |
sudo mkfs.ext4 -F -L LINUX /dev/loop1p2 | |
sudo mkdir -p "/mnt/debootstrap.os" | |
sudo mount "/dev/loop1p2" "/mnt/debootstrap.os" | |
sudo cp -a -v /mnt/debootstrap.grub/* /mnt/debootstrap.os | |
sudo mkdir -p "/mnt/debootstrap.os/boot/efi" | |
sudo mount "/dev/loop1p1" "/mnt/debootstrap.os/boot/efi" | |
sudo mount --bind /dev /mnt/debootstrap.os/dev | |
sudo mount -t devpts /dev/pts /mnt/debootstrap.os/dev/pts | |
sudo mount -t proc proc /mnt/debootstrap.os/proc | |
sudo mount -t sysfs sysfs /mnt/debootstrap.os/sys | |
sudo mount -t tmpfs tmpfs /mnt/debootstrap.os/tmp | |
sudo chroot /mnt/debootstrap.os apt-get --yes --no-install-recommends install grub2-common grub-efi-arm64 | |
sudo chroot /mnt/debootstrap.os grub-install --target=arm64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck --no-nvram --removable | |
sudo chroot /mnt/debootstrap.os update-grub | |
sudo sync | |
sudo umount /mnt/debootstrap.os/dev/pts | |
sudo umount /mnt/debootstrap.os/dev | |
sudo umount /mnt/debootstrap.os/proc | |
sudo umount /mnt/debootstrap.os/sys | |
sudo umount /mnt/debootstrap.os/tmp | |
sudo umount /mnt/debootstrap.os/boot/efi | |
sudo umount /mnt/debootstrap.os | |
sudo losetup -d /dev/loop1 | |
sudo rmdir /mnt/debootstrap.os | |
sudo umount /mnt/debootstrap.grub | |
sudo kpartx -d ./debian.raw | |
sudo kpartx -d /dev/loop0 >/dev/null | |
sudo rmdir /mnt/debootstrap.grub | |
tar -czvf debian.grub.tar.gz ./debian.grub.img | |
# Get that tar into your host Mac machine somehow (e.g. Google Drive) | |
# Now, back on your host Mac | |
qemu-system-aarch64 \ | |
-machine virt,accel=hvf,highmem=off \ | |
-cpu cortex-a72 -smp 8 -m 4G \ | |
-device intel-hda -device hda-output \ | |
-device virtio-gpu-pci \ | |
-device usb-ehci \ | |
-device usb-kbd \ | |
-device usb-tablet \ | |
-device virtio-net-pci,netdev=net \ | |
-netdev user,id=net,ipv6=off \ | |
-display cocoa \ | |
-drive "if=pflash,format=raw,file=./edk2-aarch64-code.fd,readonly=on" \ | |
-drive "if=pflash,format=raw,file=./edk2-vars-debian.fd,discard=on" \ | |
-drive "if=virtio,format=raw,file=./debian.grub.img,discard=on" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment