Martin Frezman
Posts: 1020
Joined: Mon Oct 31, 2016 10:05 am

HowTo: Perform a "NOOBS rescue"

Thu Aug 31, 2017 3:29 pm

HowTo: Performing a "NOOBS rescue"

Reason for posting: To share - in the hopes others may benefit - but
also to see if there is any room for improvement in my method and/or
if I left anything out.

Motivation: I have a Pi ZeroW running Jessie Full headless (yes, this
is intentional) via NOOBS (or PINN, not sure - they are equivalent
for the purposes of this discussion). However, as is often the case
with NOOBS installs, I could not resist the temptation to install other
OSes (besides Raspbian) that, of course, I never use. It being only
an 8G card, I decided I wanted to reclaim the wasted space.

Method: I did the actual work on a Pi3, with K, V, and M attached.
Working in a terminal window (as root) on the desktop GUI.

1) First, take a new 8G card, attach it to the Pi3 and run GPARTED on
it (i.e., gparted /dev/sda &). Blow away any existing partitions
(i.e., use "Build new partition table"). Then create new FAT32
partition (70M) and new ext4 partition (the rest of the card). Exit

2) Take the original (working) card and attach it to the Pi3; it will
be /dev/sdb*. All the partitions (and there were a lot of them!)
will auto-mount. Now, and this is the tricky part, you have to
figure out which 2 partitions are the "relevant ones" - the ones that
hold your original system. In a typical NOOBS setup, there will be
lots of partitions and you need to figure out which ones to copy.
You can look at the file called "installed_os.json" and figure it out
from there (if you can find that file...), but mostly, it's just
"brute force". In my case, I figured out that the relevant
partitions are /dev/mmcblk0p6 (boot) and /dev/mmcblk0p7 (root), which
were auto-mounted as /media/pi/boot and /media/pi/root0 (yeah...),

3) Next, do these commands:
# cd /mnt
# mkdir test
# mount /dev/sda1 test
# cd test
# cp -av /media/pi/boot/. .
# vi cmdline.txt
Note that this 'cp' command (unlike the next one) won't take very
long. Once it is done, you then edit the cmdline.txt, changing the
root= from whatever it currently is (in my case, it was
root=/dev/mmcblk0p7) to root=/dev/mmcblk0p2 (basically, you just
change the 7 to a 2). Use ZZ to save-and-exit from vi.

4) Next, do (continuing on from the above):
# cd ..
# umount test
# mount /dev/sda2 test
# cd test
# cp -av /media/pi/root0/. .
# vi etc/fstab
This 'cp' command will crank and crank. In my case, it took 2.5
hours to copy about 4G of stuff. This surprised me; I didn't think
it would take that long. It is copying from SD card to SD card, both
of which are connected via USB, but still, it was surprising.
Incidentally, this works out to about 0.5 Mbytes/second. So it

Anyway, you need to edit the fstab file, and change the entries for
both the /boot and / to /dev/mmcblk0p1 and 2, respectively. It's
pretty much the same change as before, but you have to do both.

5) Finally, do (continuing on from the above):
# cd ..
# umount test

6) Take the new SD card over to the target machine and try to boot
it. Amazingly, mine worked fine on the first attempt (yey!).

7) Note: I am keeping the old card around for a while, until I'm sure
that the new one is working fine, but so far, so good.
If this post appears in the wrong forums category, my apologies.

Return to “Raspbian”