3 # [x] resize root filesystem
4 # [x] find root fs uuid
5 # [x] find boot partition
9 # [x] extract wifi firmware
10 # [ ] on life system skip everything but wifi firmware
11 # [x] change uuid of ext4
13 my $firmware_tarball = '/boot/efi/linux-firmware.tar';
14 my $firmware_manifest = '/lib/firmware/ASAHI_FIRMWARE_MANIFEST';
15 my $grubcfg = '/mnt/EFI/debian/grub.cfg';
20 open(MOUNT
, '<', '/proc/mounts') || die ("Can not open /proc/mounts for reading: $!");
25 if (/^([\S]+)+ \/ /) {
30 die("Could not find root device");
34 find_fs_uuid_of_device
36 my $dev = shift || die;
37 my $blkid_output = `blkid ${dev}`;
39 if ($blkid_output =~ /UUID="([^"]+)"/) {
43 die("Could not find fs uuid of $dev");
49 my $uuid_in_grub_cfg = shift || die;
52 my $efi_parition = undef;
55 if (/^([\S]+):.*TYPE="vfat"/) {
56 push(@candidates, $1);
60 for my $dev (@candidates) {
61 system("mount -o ro $dev /mnt");
63 open(GRUBCFG
, '<', $grubcfg) || die ("Can't open $grubcfg: $!");
64 my @lines = <GRUBCFG
>;
66 if (/${uuid_in_grub_cfg}/) {
72 system("umount /mnt");
73 last if defined $efi_parition;
76 die ("No efi parition found") unless defined $efi_parition;
84 my $root_fs_uuid = shift || die;
85 my $efi_fs_uuid = shift || die;
87 open(FSTAB
, '>', '/etc/fstab') || die ("Can not open fstab");
89 UUID="$root_fs_uuid" / ext4 defaults 0 0
90 UUID="$efi_fs_uuid" /boot/efi vfat defaults 0 0
98 system('apt-get install -y grub-efi-arm64-signed-');
99 system("echo 'grub-efi-arm64 grub2/update_nvram boolean false' | debconf-set-selections");
100 system("echo 'grub-efi-arm64 grub2/force_efi_extra_removable boolean true' | debconf-set-selections");
101 system("dpkg-reconfigure -fnoninteractive grub-efi-arm64");
102 system("update-grub");
106 update_wifi_firmware_if_necessary
108 return unless -f
$firmware_tarball;
110 if (-f
$firmware_manifest) {
111 system("sha256sum -c $firmware_manifest --quiet");
115 system("sha256sum $firmware_tarball > $firmware_manifest");
116 system("tar -C /lib/firmware/ -xf $firmware_tarball");
118 system('rmmod brcmfmac');
119 system('rmmod brcmutil');
121 system('modprobe brcmfmac');
123 system('rmmod brcmfmac');
125 system('modprobe brcmfmac');
128 my $root_block_device = undef;
129 my $initial_root_fs_uuid = undef;
130 my $final_root_fs_uuid = undef;
131 my $efi_block_device = undef;
132 my $efi_fs_uuid = undef;
134 unless (-f
'/boot/grub/grub.cfg') {
135 $root_block_device = find_root_device
();
136 system("resize2fs $root_block_device");
137 $initial_root_fs_uuid = find_fs_uuid_of_device
($root_block_device);
138 $efi_block_device = find_efi_parition
($initial_root_fs_uuid);
139 $efi_fs_uuid = find_fs_uuid_of_device
($efi_block_device);
140 system("tune2fs -U random ${root_block_device}");
141 $final_root_fs_uuid = find_fs_uuid_of_device
($root_block_device);
142 generate_fstab
($final_root_fs_uuid, $efi_fs_uuid);
143 system('mount /boot/efi');
147 update_wifi_firmware_if_necessary
();