0

I have an SD card with a particular image on it that I wanted to back up before modifying anything in case I broke something. I inserted the card into my (Windows) PC and attempted to use Win32 Disk Imager, but the disk was offline because it had a signature collision, according to diskpart. Google said the solution was to change the unique ID of the disk in diskpart, which I did without writing down the original ID. It still wouldn't come online until I rebooted the PC (which I probably should have done first). Now my PC thinks the card is fine, but when I put it in the Pi and turn it on, it begins the boot sequence but won't progress any further after recognizing storage.

The last few lines of the boot sequence are:

[  1.325488] mmc1: new high speed SDIO card at address 0001
[  1.325968] mmc0: host does not support reading read-only switch, assuming write-enable
[  1.348842] mmc0: new high speed SDHC card at address 5048
[  1.347130] mmcblk0: mmc0:5048 SD8GB 7.47 GiB
[  1.354989]  mmcblk0: p1 p2

After that the cursor just stays blinking. Double space on the last line is not a typo.

Edit: after about 7 minutes another line shows:

[422.231548] random: crng init done

Is there a way to get the disk working again without wiping/reformatting etc? The whole point was trying to back it up because I don't have another copy of the image.

  • It MAY be possible if you have a Linux computer (which can be a Pi with a working OS & SD Card reader). From your question it is not possible to guess what damage Windows has done. – Milliways Mar 01 '22 at 21:39
  • @Milliways I do have another working Pi and an external SD card reader; what were you thinking might be possible? – Isaac Middlemiss Mar 01 '22 at 22:29

1 Answers1

1

If you setup a Pi with SD reader you can use the following script to check consistency of a Raspbian/Raspberry Pi OS SD Card image in the reader.

#! /bin/bash
# 2021-02-10
# Check consistency of Partition ID on mounted SD Card

BOOT_MOUNT='/mnt/SDA1' ROOT_MOUNT='/mnt/SDA2'

Check/create Mount Points

if [ ! -e $BOOT_MOUNT ]; then mkdir $BOOT_MOUNT fi if [ ! -e $ROOT_MOUNT ]; then mkdir $ROOT_MOUNT fi echo "mounts " $BOOT_MOUNT $ROOT_MOUNT if [ -e /dev/sda ]; then SD1='/dev/sda1' SD2='/dev/sda2' SD='/dev/sda' else SD1='/dev/sdb1' SD2='/dev/sdb2' SD='/dev/sdb' fi echo $SD

Mount Partitions

if ! $(mountpoint -q $BOOT_MOUNT); then sudo mount $SD1 $BOOT_MOUNT # mount partition containing boot files fi if ! $(mountpoint -q $ROOT_MOUNT); then sudo mount $SD2 $ROOT_MOUNT # mount root partition containing OS files fi

Determine Disk identifier of SD Card

DISKID=$(sudo fdisk -l $SD | awk '/Disk identifier/ {print $3};' | sed 's/0x//')

Use sed to delete all BEFORE PARTUUID= and all AFTER -0 in $BOOT_MOUNT/cmdline.txt

ROOTPART=$(sed -e 's/^.PARTUUID=//' -e 's/-0.$'// $BOOT_MOUNT/cmdline.txt)

echo -e "Disk ID\t\t"$DISKID echo -e "root PARTUUID\t"$ROOTPART

find first PARTUUID ext4 in $ROOT_MOUNT/etc/fstab

EXISTFSTABPART=$(awk '/PARTUUID.ext4/ {print $1; exit};' $ROOT_MOUNT/etc/fstab | sed -e 's/^.PARTUUID=//' -e 's/-0.*$'//)

echo -e "Existing fstab\t"$EXISTFSTABPART

if [ $DISKID = $EXISTFSTABPART ]; then echo "Looks OK!" else echo "Partition ID mismatch!" # Edit cmdline.txt & fstab to new DISKID & create new temporary files sed -e "s/$ROOTPART/$DISKID/" $BOOT_MOUNT/cmdline.txt > cmdline.txt.new sed -e "s/$ROOTPART/$DISKID/" $ROOT_MOUNT/etc/fstab > fstab.new echo -n "Set DiskID to ${DISKID} on $SD (y/n)? " while read -r -n 1 -s answer; do if [[ "${answer}" = [yY] ]]; then echo "Change" sudo cp -v cmdline.txt.new $BOOT_MOUNT/cmdline.txt sudo cp -v fstab.new $ROOT_MOUNT/etc/fstab break else echo "Aborted" exit fi done fi

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • I'm a little confused - how would this help me to diagnose my non-working SD card? – Isaac Middlemiss Mar 02 '22 at 03:00
  • This starts "If you do setup a Pi" and my comment "Pi with a working OS & SD Card reader"- have you done so? – Milliways Mar 02 '22 at 03:02
  • Perhaps my original question was poorly worded - the Pi is fine, and I can easily enough make a generic SD card with a Pi OS on it, but I'm specifically interested in repairing the unique image on my now-not-booting SD card. I'm not entirely sure what problem your answer is meant to solve. – Isaac Middlemiss Mar 02 '22 at 03:07
  • If you put the old SD Card in a reader and run the above it will diagnose & offer to fix. There is nothing in the script that a knowledgeable user can't do manually. – Milliways Mar 02 '22 at 03:10
  • Ah I see, my bad - I'll try this tomorrow :) – Isaac Middlemiss Mar 02 '22 at 03:20
  • It's a clever & useful script. My only comment is that it might not be entirely clear to some that you're talking about mounting the suspect SD card in a USB (or similar) adapter. There's a picture here that might provide a visual clue :) – Seamus Mar 03 '22 at 08:18
  • Ended up finding a copy of the image buried on my hard drive, but will remember this – Isaac Middlemiss Mar 06 '22 at 22:15