]> git.zerfleddert.de Git - m1-debian/blobdiff - files/rc.local
working on rc.local
[m1-debian] / files / rc.local
index 651a9086464a78047e6806c3b92391553cf7e6a5..c2e649b39ea808361684fd22061ce2cb021af9d4 100755 (executable)
@@ -2,16 +2,12 @@
 
 # [x] resize root filesystem
 # [x] find root fs uuid
-# [ ] find boot partition
-# [ ] generate fstab
-# [ ] mount boot
-# [ ] install grub
+# [x] find boot partition
+# [x] generate fstab
+# [x] mount /boot/efi
+# [x] 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;
+# [ ] 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
@@ -77,9 +73,44 @@ 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 <<EOF;
+
+UUID="$root_fs_uuid" /         ext4 defaults 0 0
+UUID="$efi_fs_uuid"  /boot/efi vfat defaults 0 0
+EOF
+        close(FSTAB);
+}
 
-$root_block_device = find_root_device();
-# system("resize2fs $root_block_device");
+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");
+}
 
-$root_fs_uuid = find_fs_uuid_of_device($root_block_device);
-$efi_block_device = find_efi_parition($root_fs_uuid);
+my $root_block_device = undef;
+my $root_fs_uuid = undef;
+my $efi_block_device = undef;
+my $efi_fs_uuid = undef;
+
+unless (-f '/etc/fstab') {
+        $root_block_device = find_root_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);
+        $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();
+}
Impressum, Datenschutz