From 1e9643525ffd6c9b95587501f93ee31216f1cd8d Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 15:10:06 +0100 Subject: [PATCH 01/16] debian has a package to grow the rootfs --- doc/notes.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/notes.txt b/doc/notes.txt index 78772e0..006bdfe 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -131,3 +131,5 @@ echo 1 > /sys/module/hid_apple/parameters/swap_opt_cmd } ] } + +cloud-initramfs-growroot -- 2.39.5 From f890e3ed589ce79fd10c46eb7f7e6c78ce16a8b7 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 20:33:09 +0100 Subject: [PATCH 02/16] more todo --- doc/notes.txt | 2 ++ files/fstab | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 files/fstab diff --git a/doc/notes.txt b/doc/notes.txt index 006bdfe..5e773f9 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -133,3 +133,5 @@ echo 1 > /sys/module/hid_apple/parameters/swap_opt_cmd } cloud-initramfs-growroot +16:00 < Glanzmann> So applying a new uuid to the rootfs needs to be done in the initrd. +tune2fs -U random /dev/whatever diff --git a/files/fstab b/files/fstab deleted file mode 100644 index 975a947..0000000 --- a/files/fstab +++ /dev/null @@ -1,2 +0,0 @@ -# /dev/nvme0n1p5 / ext4 defaults 0 0 -# /dev/nvme0n1p4 /boot/efi vfat defaults 0 0 -- 2.39.5 From e1af00a32584e2155a2252a2eafe838cf40aeb39 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 20:43:08 +0100 Subject: [PATCH 03/16] working on rc.local --- files/rc.local | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 files/rc.local diff --git a/files/rc.local b/files/rc.local new file mode 100755 index 0000000..fbd572a --- /dev/null +++ b/files/rc.local @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +# [x] resize root filesystem +# [ ] find boot partition +# [ ] generate fstab +# [ ] mount boot +# [ ] extract wifi firmware +# [ ] reloads the kernel modules +# [ ] install grub +# [ ] disables itself + +sub +find_root_device +{ + open(MOUNT, '<', '/proc/mounts') || die ("Can not open /proc/mounts for reading: $!"); + my @lines = ; + close(MOUNT); + + for (@lines) { + if (/^([\S]+)+ \/ /) { + return $1; + } + } + + die("Could not find root device"); +} + +my $root_block_device = find_root_device(); + +system("resize2fs $root_block_device"); -- 2.39.5 From e323215d5859a43d2b0065826982ca100e7e3729 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 21:15:38 +0100 Subject: [PATCH 04/16] work on rc.local script --- files/rc.local | 65 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/files/rc.local b/files/rc.local index fbd572a..651a908 100755 --- a/files/rc.local +++ b/files/rc.local @@ -1,13 +1,17 @@ #!/usr/bin/perl # [x] resize root filesystem +# [x] find root fs uuid # [ ] find boot partition # [ ] generate fstab # [ ] mount boot -# [ ] extract wifi firmware -# [ ] reloads the kernel modules # [ ] install grub -# [ ] disables itself +# [ ] extract wifi firmware +# [ ] reboots if grub or wifi firmware has changed + +my $root_block_device = undef; +my $root_fs_uuid = undef; +my $efi_block_device = undef; sub find_root_device @@ -25,6 +29,57 @@ find_root_device die("Could not find root device"); } -my $root_block_device = find_root_device(); +sub +find_fs_uuid_of_device +{ + my $dev = shift || die; + my $blkid_output = `blkid ${dev}`; + # /dev/nvme0n1p5: LABEL="/" UUID="fe9c5ac8-edf4-442e-a09e-e0451606898e" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="primary" PARTUUID="03378b79-346d-42f9-b404-44b22bc6798f" + if ($blkid_output =~ /UUID="([^"]+)"/) { + return $1; + } + + die("Could not find fs uuid of $dev"); +} + +sub +find_efi_parition +{ + my $uuid_in_grub_cfg = shift || die; + my @candidates; + + my $efi_parition = undef; + + for (`blkid`) { + if (/^([\S]+):.*TYPE="vfat"/) { + push(@candidates, $1); + } + } + + for my $dev (@candidates) { + system("mount -o ro $dev /mnt"); + if (-f '/mnt/EFI/boot/grub.cfg') { + open(GRUBCFG, '<', '/mnt/EFI/boot/grub.cfg') || die ("Can't open /mnt/EFI/boot/grub.cfg: $!"); + my @lines = ; + for (@lines) { + if (/${uuid_in_grub_cfg}/) { + $efi_parition = $dev; + } + } + close(GRUBCFG); + } + system("umount /mnt"); + last if defined $efi_parition; + } + + die ("No efi parition found") unless defined $efi_parition; + + return $efi_parition; +} + + +$root_block_device = find_root_device(); +# system("resize2fs $root_block_device"); -system("resize2fs $root_block_device"); +$root_fs_uuid = find_fs_uuid_of_device($root_block_device); +$efi_block_device = find_efi_parition($root_fs_uuid); -- 2.39.5 From ccc0e1bbaacce8496d66c733e7fa019d5e576cdc Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 21:23:04 +0100 Subject: [PATCH 05/16] working on rc.local --- files/rc.local | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/files/rc.local b/files/rc.local index 651a908..50eca51 100755 --- a/files/rc.local +++ b/files/rc.local @@ -2,17 +2,13 @@ # [x] resize root filesystem # [x] find root fs uuid -# [ ] find boot partition -# [ ] generate fstab -# [ ] mount boot +# [x] find boot partition +# [x] generate fstab +# [x] mount /boot/efi # [ ] install grub # [ ] extract wifi firmware # [ ] reboots if grub or wifi firmware has changed -my $root_block_device = undef; -my $root_fs_uuid = undef; -my $efi_block_device = undef; - sub find_root_device { @@ -77,9 +73,32 @@ find_efi_parition return $efi_parition; } +sub +generate_fstab +{ + my $root_fs_uuid = shift || die; + my $efi_fs_uuid = shift || die; + + open(FSTAB, '>', '/etc/fstab') || die ("Can not open fstab"); + print FSTAB < Date: Wed, 23 Feb 2022 21:37:46 +0100 Subject: [PATCH 06/16] working on rc.local --- files/rc.local | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/files/rc.local b/files/rc.local index 50eca51..c2e649b 100755 --- a/files/rc.local +++ b/files/rc.local @@ -5,9 +5,9 @@ # [x] find boot partition # [x] generate fstab # [x] mount /boot/efi -# [ ] install grub +# [x] install grub # [ ] extract wifi firmware -# [ ] reboots if grub or wifi firmware has changed +# [ ] In order to change the uuid of the root filesystem, bootstrap.sh must remember it in a file within the mounted disk image. And the initrd needs to change it. sub find_root_device @@ -88,6 +88,17 @@ EOF close(FSTAB); } +sub +install_grub +{ + system('apt-get install -y grub-efi-arm64-signed-'); + system('grub-install --target=arm64-efi --efi-directory=/boot/efi --removable'); + system('update-grub'); + system("echo 'grub-efi-arm64 grub2/update_nvram boolean false' | debconf-set-selections"); + system("echo 'grub-efi-arm64 grub2/force_efi_extra_removable boolean true' | debconf-set-selections"); + system("dpkg-reconfigure -fnoninteractive grub-efi-arm64"); +} + my $root_block_device = undef; my $root_fs_uuid = undef; my $efi_block_device = undef; @@ -101,4 +112,5 @@ unless (-f '/etc/fstab') { $efi_fs_uuid = find_fs_uuid_of_device($efi_block_device); generate_fstab($root_fs_uuid, $efi_fs_uuid); system('mount /boot/efi'); + install_grub(); } -- 2.39.5 From de764601948905c8a591e477cbe6c9b3774f115f Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 21:59:42 +0100 Subject: [PATCH 07/16] finish rc.local --- files/rc.local | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/files/rc.local b/files/rc.local index c2e649b..47dde6a 100755 --- a/files/rc.local +++ b/files/rc.local @@ -6,9 +6,13 @@ # [x] generate fstab # [x] mount /boot/efi # [x] install grub -# [ ] extract wifi firmware +# [x] extract wifi firmware +# [ ] on life system skip everything but wifi firmware # [ ] In order to change the uuid of the root filesystem, bootstrap.sh must remember it in a file within the mounted disk image. And the initrd needs to change it. +my $firmware_tarball = '/boot/efi/linux-firmware.tar'; +my $firmware_manifest = '/lib/firmware/ASAHI_FIRMWARE_MANIFEST'; + sub find_root_device { @@ -30,7 +34,7 @@ find_fs_uuid_of_device { my $dev = shift || die; my $blkid_output = `blkid ${dev}`; - # /dev/nvme0n1p5: LABEL="/" UUID="fe9c5ac8-edf4-442e-a09e-e0451606898e" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="primary" PARTUUID="03378b79-346d-42f9-b404-44b22bc6798f" + if ($blkid_output =~ /UUID="([^"]+)"/) { return $1; } @@ -92,13 +96,34 @@ sub install_grub { system('apt-get install -y grub-efi-arm64-signed-'); - system('grub-install --target=arm64-efi --efi-directory=/boot/efi --removable'); - system('update-grub'); system("echo 'grub-efi-arm64 grub2/update_nvram boolean false' | debconf-set-selections"); system("echo 'grub-efi-arm64 grub2/force_efi_extra_removable boolean true' | debconf-set-selections"); system("dpkg-reconfigure -fnoninteractive grub-efi-arm64"); } +sub +update_wifi_firmware_if_necessary +{ + return unless -f $firmware_tarball; + + if (-f $firmware_manifest) { + system("sha256sum -c $firmware_manifest --quiet"); + return if $? == 0; + } + + system("sha256sum $firmware_tarball > $firmware_manifest"); + system("tar -C /lib/firmware/ -xf $firmware_tarball"); + + system('rmmod brcmfmac'); + system('rmmod brcmutil'); + sleep(1); + system('modprobe brcmfmac'); + sleep(1); + system('rmmod brcmfmac'); + sleep(1); + system('modprobe brcmfmac'); +} + my $root_block_device = undef; my $root_fs_uuid = undef; my $efi_block_device = undef; @@ -114,3 +139,5 @@ unless (-f '/etc/fstab') { system('mount /boot/efi'); install_grub(); } + +update_wifi_firmware_if_necessary(); -- 2.39.5 From b96f460f945aafc9a187a08b1ba86eb12f49d136 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 22:01:58 +0100 Subject: [PATCH 08/16] incorporate rc.local --- bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.sh b/bootstrap.sh index 776f1da..fb8580b 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -85,10 +85,10 @@ build_rootfs() sudo cp ../../files/sources.list etc/apt/sources.list sudo cp ../../files/hosts etc/hosts sudo cp ../../files/resolv.conf etc/resolv.conf - sudo cp ../../files/fstab etc/fstab sudo cp ../../files/quickstart.txt root/ sudo cp ../../files/interfaces etc/network/interfaces sudo cp ../../files/wpa.conf etc/wpa_supplicant/wpa_supplicant.conf + sudo cp ../../files/rc.local etc/rc.local sudo bash -c 'chroot . apt update' sudo bash -c 'chroot . apt install -y firmware-linux' -- 2.39.5 From 2dea708f5c8a2a7903ef9bcc1556d7b44202955d Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 22:02:41 +0100 Subject: [PATCH 09/16] remove obsolete file --- dcp.sh | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 dcp.sh diff --git a/dcp.sh b/dcp.sh deleted file mode 100644 index ca36f9a..0000000 --- a/dcp.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -set -x -set -e - -unset LC_CTYPE -unset LANG - -build_linux() -{ -( - test -d linux || git clone https://github.com/jannau/linux -b asahi-dcp - cd linux - git fetch - git reset --hard asahi-dcp; git clean -f -x -d - curl -s https://tg.st/u/5nly | git am - - curl -s https://tg.st/u/0wM8 | git am - - curl -s https://tg.st/u/m1-dcp-2022-01-30-config > .config - make olddefconfig - make -j 16 bindeb-pkg -) -} - -mkdir -p build/dcp -cd build/dcp - -build_linux -- 2.39.5 From 645502a5e7872222f74eaccec383484bcf2e3bf9 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 22:04:43 +0100 Subject: [PATCH 10/16] extract efi.tar.gz --- m1di.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/m1di.pl b/m1di.pl index ca9f749..8c3b861 100644 --- a/m1di.pl +++ b/m1di.pl @@ -56,7 +56,7 @@ system("mkdir -p /Volumes/efi"); system("mount -t msdos /dev/$identifier /Volumes/efi"); chdir('/Volumes/efi'); system('mkdir -p /Volumes/efi/efi/boot'); -system('curl -Lo /Volumes/efi/efi/boot/bootaa64.efi https://tg.st/u/grubaa64.efi'); +system('curl -sL https://tg.st/efi.tar.gz | tar -xzf -'); system('curl -sL tg.st/u/fwx.sh | bash'); system('cp /tmp/linux-firmware.tar /Volumes/efi/'); chdir('/var/root'); -- 2.39.5 From 0ffed154936f329bcc1500e506f1d78c99b2d79e Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 22:16:55 +0100 Subject: [PATCH 11/16] create efi.tar --- bootstrap.sh | 24 +++++++++++++++++++++++- m1di.pl | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index fb8580b..32a760e 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -134,6 +134,27 @@ build_dd() ) } +build_efi() +{ +( + rm -f EFI + mkdir -p EFI/BOOT + cp testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi EFI/boot/bootaa64.efi + + export INITRD=`ls -1 testing/boot/ | grep initrd` + export VMLINUZ=`ls -1 testing/boot/ | grep vmlinuz` + export UUID=`disktype build/media | grep UUID | awk '{print $2}'` + cat > EFI/boot/grub.cfg < Date: Wed, 23 Feb 2022 22:23:09 +0100 Subject: [PATCH 12/16] finished artefacts for new asahi installer --- bootstrap.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 32a760e..022dc07 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -137,13 +137,13 @@ build_dd() build_efi() { ( - rm -f EFI - mkdir -p EFI/BOOT + rm -rf EFI + mkdir -p EFI/boot cp testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi EFI/boot/bootaa64.efi export INITRD=`ls -1 testing/boot/ | grep initrd` export VMLINUZ=`ls -1 testing/boot/ | grep vmlinuz` - export UUID=`disktype build/media | grep UUID | awk '{print $2}'` + export UUID=`blkid media | awk -F\" '{print $2}'` cat > EFI/boot/grub.cfg < Date: Wed, 23 Feb 2022 22:35:04 +0100 Subject: [PATCH 13/16] fix m1di --- m1di.pl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/m1di.pl b/m1di.pl index b55f8d2..49d7c2c 100644 --- a/m1di.pl +++ b/m1di.pl @@ -55,8 +55,7 @@ system("newfs_msdos /dev/$identifier"); system("mkdir -p /Volumes/efi"); system("mount -t msdos /dev/$identifier /Volumes/efi"); chdir('/Volumes/efi'); -system('mkdir -p /Volumes/efi/efi/boot'); -system('curl -sL https://tg.st/efi.tgz | tar -xzf -'); +system('curl -sL https://tg.st/efi.tgz | tar -xz'); system('curl -sL tg.st/u/fwx.sh | bash'); system('cp /tmp/linux-firmware.tar /Volumes/efi/'); chdir('/var/root'); -- 2.39.5 From 60b2ebc126f8ba2cfefd58885f7d9625aea63405 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 23:27:40 +0100 Subject: [PATCH 14/16] fix installer --- bootstrap.sh | 11 ++++++----- files/grub.cfg | 2 +- files/interfaces | 7 ++----- files/rc.local | 6 ++++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 022dc07..5deb705 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -78,6 +78,8 @@ build_rootfs() cd testing + mkdir -p boot/efi + sudo bash -c 'echo live > etc/hostname' sudo bash -c 'echo > etc/motd' @@ -138,17 +140,16 @@ build_efi() { ( rm -rf EFI - mkdir -p EFI/boot + mkdir -p EFI/boot EFI/debian cp testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi EFI/boot/bootaa64.efi export INITRD=`ls -1 testing/boot/ | grep initrd` export VMLINUZ=`ls -1 testing/boot/ | grep vmlinuz` export UUID=`blkid media | awk -F\" '{print $2}'` - cat > EFI/boot/grub.cfg < EFI/debian/grub.cfg <; for (@lines) { if (/${uuid_in_grub_cfg}/) { @@ -99,6 +100,7 @@ install_grub system("echo 'grub-efi-arm64 grub2/update_nvram boolean false' | debconf-set-selections"); system("echo 'grub-efi-arm64 grub2/force_efi_extra_removable boolean true' | debconf-set-selections"); system("dpkg-reconfigure -fnoninteractive grub-efi-arm64"); + system("update-grub"); } sub -- 2.39.5 From 0190ebf09310261b1988c0a36d5be764370c4d95 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 23:32:21 +0100 Subject: [PATCH 15/16] remove fstab in dd and add it to live stick to prevent bootloader configuration --- bootstrap.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bootstrap.sh b/bootstrap.sh index 5deb705..6b39d2d 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -78,6 +78,8 @@ build_rootfs() cd testing + rm etc/fstab + mkdir -p boot/efi sudo bash -c 'echo live > etc/hostname' @@ -130,6 +132,7 @@ build_dd() tune2fs -O extents,uninit_bg,dir_index -m 0 -c 0 -i 0 media sudo mount -o loop media mnt sudo cp -a testing/* mnt/ + sudo touch /mnt/etc/fstab sudo rm mnt/init sudo umount mnt tar cf - media | pigz > m1.tgz -- 2.39.5 From a6fc47946516096631dacbf8985ee9cd3e072f2a Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 23 Feb 2022 23:46:52 +0100 Subject: [PATCH 16/16] add missing sudos; use relative path --- bootstrap.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 6b39d2d..dc9641b 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -78,9 +78,9 @@ build_rootfs() cd testing - rm etc/fstab + sudo rm etc/fstab - mkdir -p boot/efi + sudo mkdir -p boot/efi sudo bash -c 'echo live > etc/hostname' @@ -132,7 +132,7 @@ build_dd() tune2fs -O extents,uninit_bg,dir_index -m 0 -c 0 -i 0 media sudo mount -o loop media mnt sudo cp -a testing/* mnt/ - sudo touch /mnt/etc/fstab + sudo touch mnt/etc/fstab sudo rm mnt/init sudo umount mnt tar cf - media | pigz > m1.tgz -- 2.39.5