Skip to content

Commit 7fac47f

Browse files
committed
Add workaround for kernel bug
If we install `raspberrypi-kernel = 1:1.20230317-1` we need to patch ssh host key regeneration, otherwise it will take AGES during first boot on anything other than a Pi4, due to some issue with `/dev/hwrng` in that kernel. See also raspberrypi/linux#5390
1 parent 9d3b335 commit 7fac47f

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

scripts/02-update-boot

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,19 @@ source /common.sh
77
install_cleanup_trap
88

99
apt-get install --yes --reinstall raspberrypi-bootloader raspberrypi-kernel
10+
11+
kernel_version=$(dpkg -s raspberrypi-kernel | grep -i version | awk '{print $2}')
12+
if [ "$kernel_version" = "1:1.20230317-1" ]; then
13+
# This kernel version needs a workaround because ssh key generation is slow AF
14+
#
15+
# Patches from https://github.com/RPi-Distro/pi-gen/issues/682#issuecomment-1484119300
16+
#
17+
# Note that this is a temporary workaround, and will be removed in the future. Using
18+
# /dev/urandom instead of /dev/hwrng is less secure for key generation, however for now
19+
# it is the only way to get a working system thanks to a kernel bug in hwrng on anything
20+
# other than the Pi 4, see https://github.com/raspberrypi/linux/issues/5390
21+
pushd /
22+
patch -p1 -u -b < /files/regenerate_ssh_host_keys/regenerate_ssh_host_keys.patch
23+
patch -p1 -u -b < /files/regenerate_ssh_host_keys/firstboot.patch
24+
popd
25+
fi

scripts/80-install-user-fix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ install_cleanup_trap
1010
[ -f '/root/bin/user-fix' ] && exit 0
1111

1212
# we need to install virtualenv-tools3, so let's get pip and that
13-
apt install -y python3-pip
13+
apt-get install -y python3-pip
1414
sudo -u pi pip3 install --user virtualenv-tools3
1515

1616
cp /files/user-fix /root/bin/user-fix
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a/usr/lib/raspberrypi-sys-mods/firstboot 2022-09-15 13:46:12.000000000 +0100
2+
+++ b/usr/lib/raspberrypi-sys-mods/firstboot 2023-03-28 12:31:05.529858256 +0100
3+
@@ -63,7 +63,7 @@
4+
fix_partuuid() {
5+
mount -o remount,rw "$ROOT_PART_DEV"
6+
mount -o remount,rw "$BOOT_PART_DEV"
7+
- DISKID="$(tr -dc 'a-f0-9' < /dev/hwrng | dd bs=1 count=8 2>/dev/null)"
8+
+ DISKID="$(tr -dc 'a-f0-9' < /dev/urandom | dd bs=1 count=8 2>/dev/null)"
9+
fdisk "$ROOT_DEV" > /dev/null <<EOF
10+
x
11+
i
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a/usr/lib/raspberrypi-sys-mods/regenerate_ssh_host_keys 2022-09-01 16:22:09.000000000 +0100
2+
+++ b/usr/lib/raspberrypi-sys-mods/regenerate_ssh_host_keys 2023-03-28 12:26:26.822217883 +0100
3+
@@ -1,8 +1,5 @@
4+
#!/bin/sh -e
5+
6+
-if [ -c /dev/hwrng ]; then
7+
- dd if=/dev/hwrng of=/dev/urandom count=1 bs=4096 status=none
8+
-fi
9+
rm -f /etc/ssh/ssh_host_*_key*
10+
ssh-keygen -A > /dev/null
11+
systemctl -q disable regenerate_ssh_host_keys

0 commit comments

Comments
 (0)