Raspberry Raspbian Reinstall In-place

Method 1 (download image, modify in another pc, install remotely)

Download decompress image

curl -L https://downloads.raspberrypi.org/raspios_oldstable_lite_armhf/images/raspios_oldstable_lite_armhf-2023-05-03/2023-05-03-raspios-buster-armhf-lite.img.xz | xz --decompress -c > 2023-05-03-raspios-buster-armhf-lite.img

Mount image

fdisk -l 2023-05-03-raspios-buster-armhf-lite.img
532480*512bytes
sudo mount -o loop,offset=272629760 ~/2023-05-03-raspios-buster-armhf-lite.img /mnt
8192*512bytes
524288*512bytes
sudo mount -o loop,offset=4194304,sizelimit=268435456 ~/2023-05-03-raspios-buster-armhf-lite.img /mnt/boot

Modify wireless configuration (copy from existing), enable ssh

sudo cp /mnt/etc/wpa_supplicant/wpa_supplicant.conf .
sudo touch /boot/ssh

Remote install (image from another pc)

ssh user@linuxpc "dd if=2023-05-03-raspios-buster-armhf-lite.img bs=4M" | pv | dd bs=4M of=/dev/mmcblk0

Restart

echo 1 > /proc/sys/kernel/sysrq

Method 2 (Direct install from image)

curl -L https://downloads.raspberrypi.org/raspios_oldstable_lite_armhf/images/raspios_oldstable_lite_armhf-2023-05-03/2023-05-03-raspios-buster-armhf-lite.img.xz | xz --decompress -c | dd bs=4M of=/dev/mmcblk0

Restart

echo b > /proc/sysrq-trigger