Skip to content

Instantly share code, notes, and snippets.

@1stcall
Forked from yayuniversal/raspi-reset
Created October 30, 2023 08:00
Show Gist options
  • Select an option

  • Save 1stcall/2cf8aec0c8d42dc4c1bf9369b5556ced to your computer and use it in GitHub Desktop.

Select an option

Save 1stcall/2cf8aec0c8d42dc4c1bf9369b5556ced to your computer and use it in GitHub Desktop.
raspi-reset
#!/bin/bash
BS=64M
DISK_ID=0x7788c428
ROOT_DEV=/dev/mmcblk0
BOOTFS_BACKUP=${ROOT_DEV}p3
BOOTFS_TARGET=${ROOT_DEV}p1
ROOTFS_BACKUP=${ROOT_DEV}p2
ROOTFS_TARGET=${ROOT_DEV}p4
if [ $EUID -ne 0 ]; then
echo Must be run as root 1>&2
exit 1
fi
echo Remounting disks read-only...
echo 1 > /proc/sys/kernel/sysrq
echo u > /proc/sysrq-trigger
echo Overwritting bootfs...
dd if=$BOOTFS_BACKUP of=$BOOTFS_TARGET bs=$BS status=progress
echo Overwritting rootfs...
dd if=$ROOTFS_BACKUP of=$ROOTFS_TARGET bs=$BS status=progress
echo Restoring original disk id...
sfdisk --disk-id $ROOT_DEV $DISK_ID
# echo Checking and resizing filesystem...
# e2fsck -f $ROOTFS_TARGET
# resize2fs $ROOTFS_TARGET
echo Done! Rebooting
sleep 1
echo b > /proc/sysrq-trigger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment