git » linux-armlfs.git » commit f6819b2

untested: new chromebook install-hook

author Urja (ARMLFS builder)
2025-06-18 22:29:52 UTC
committer Urja (ARMLFS builder)
2025-06-18 22:29:52 UTC
parent 5b17705d2f872bdfdebdbfe13a37bd069bc30ece

untested: new chromebook install-hook

pacman hooks cannot ask for input these days
so, we must have a robust-enough hook that
will _just do it_ (or fail LOUDLY). But
also one that wont wipe a random filesystem.

Man the chromeos kernel partition idea is a bit of
an issue exactly _because its a partition_.
And if you dd into the wrong partition, the user
will be very unhappy...

chromebook.install +20 -11

diff --git a/chromebook.install b/chromebook.install
index 02e0846..48bfddb 100644
--- a/chromebook.install
+++ b/chromebook.install
@@ -1,19 +1,28 @@
 flash_kernel() {
   major=$(mountpoint -d / | cut -f 1 -d ':')
-  minor=$(mountpoint -d / | cut -f 2 -d ':')
-  device=$(cat /proc/partitions | awk {'if ($1 == "'${major}'" && $2 == "'${minor}'") print $4 '})
-  device="/dev/${device/%2/1}"
+  root_minor=$(mountpoint -d / | cut -f 2 -d ':')
+  krnl_minor=$(expr $root_minor - 1)
+  device=$(cat /proc/partitions | awk {'if ($1 == "'${major}'" && $2 == "'${krnl_minor}'") print $4 '})
+  device="/dev/$device"
+  if [ ! -b "${device}" ]; then
+    echo "Kernel partition not found. Cannot write kernel."
+    echo "WRITE THE KERNEL TO THE APPROPRIATE PARTITION MANUALLY."
+    echo "# dd if=/boot/vmlinux.kpart of=${device}"
+    return
+  fi
 
-  echo "A new kernel version needs to be flashed onto ${device}."
-  echo "Do you want to do this now? [y|N]"
-  read -r shouldwe
-  if [[ $shouldwe =~ ^([yY][eE][sS]|[yY])$ ]]; then
-    dd if=/boot/vmlinux.kpart of=${device}
-    sync
-  else
-    echo "You can do this later by running:"
+  kpart_size=$(cat /sys/dev/block/$major:$krnl_minor/size)
+  if [ "$kpart_size" != "32768" ]; then
+    echo "Unexpected kernel partition size. Aborting kernel write."
+    echo "WRITE THE KERNEL TO THE APPROPRIATE PARTITION MANUALLY."
     echo "# dd if=/boot/vmlinux.kpart of=${device}"
+    return
   fi
+
+  echo "Writing new kernel onto ${device}."
+  dd bs=1M if=/boot/vmlinux.kpart of=${device}
+  sync
+  echo "Done."
 }
 
 post_install () {