-1

I installed raspbian on an sd card and then booted into a pi zero to do my required configuration and setup.

I then made an .img off of this sd card which I'm planning to use in a manufacturing process.

In order to reduce burn time I made it about 3 GB using dd's count option.

Now when I burn the image to a new SD card I want to extend rootfs to the full card length, so I'm running the following commands:

# echo -e "d\n2\nw\n" | fdisk /dev/sdc
# parted -s /dev/sdc unit B mkpart primary 50331648 100%

Where 50331648 was the start of rootfs before deleting it, gotten from parted -m /dev/sdc unit B print.

Then I run

resize2fs -p /dev/sdc

And I get

resize2fs 1.46.2 (28-Feb-2021)
resize2fs: Bad magic number in super-block while trying to open /dev/sdc
Couldn't find valid filesystem superblock.

All my searches led to primarily answers about centOS or non applicable scenarios. The only relevant question I found was that one, which also has no answers..

How can I do this?

7
  • "I made it about 3 GB using dd's count option" - in other words you corrupted your image by deleting essential FS data "Bad magic number in super-block"!
    – Milliways
    Commented Jul 8, 2022 at 11:29
  • @Milliways I assumed it was safe to snip the end off as the filesystem was about 1.7G in size..
    – php_nub_qq
    Commented Jul 8, 2022 at 11:50
  • You have deleted the FS data stored at the end of the partition. There are many ways of making a reduced image but if you are planning to produce your own you should do it properly to make a custom image.
    – Milliways
    Commented Jul 8, 2022 at 12:01
  • @Milliways well it still appears to run, never knew there is essential data at the end of the partition. Is it possible to restore this lost data, as there is quite a lot of work put into this supposedly now corrupt image?
    – php_nub_qq
    Commented Jul 8, 2022 at 12:03
  • If you made an iSD Card it should still work - it is just the dd that only copied partial data.
    – Milliways
    Commented Jul 8, 2022 at 12:06

2 Answers 2

1

Have you already tried expanding rootfs via

sudo raspi-config

then first update and at last go for Expand Filesystem ?

This is the usual and simplest way of doing so.

Edit: I would suggest https://github.com/Drewsif/PiShrink for shrinking and also resizing if the pi should never be booted to prepare it.

9
  • This means I would have to boot the pi and do it on every unit. That is a production step I'm trying to skip by doing what I'm trying to do.
    – php_nub_qq
    Commented Jul 8, 2022 at 11:24
  • so you just want to run commands? try raspi-config --expand-rootfs // a i got it. you dont want to boot it up... okay. so i'd check out the raspi-config script and transfer the process
    – bitdruid
    Commented Jul 8, 2022 at 11:26
  • I'm not burning the cards on a raspberry pi, obviously. I could add this in a start-up script in the image but what I found is that raspi-config --expand-rootfs not always works and sometimes corrupts the sd card, I can't risk having broken units.
    – php_nub_qq
    Commented Jul 8, 2022 at 11:27
  • 1
    ok as mentioned maybe check out the raspi-config script (how this specifically is working) and rewrite it in your own script? also you may check out github.com/Drewsif/PiShrink for shrinking your pi-images
    – bitdruid
    Commented Jul 8, 2022 at 11:31
  • I examined /usr/bin/raspi-config and it seems to be doing just about what I'm doing. The script PiShrink also uses /usr/bin/env raspi-config --expand-rootfs in it's expanding function.
    – php_nub_qq
    Commented Jul 8, 2022 at 11:45
0

Well, as silly as it might be, thanks to this answer I found out that I'm supposed to use resize2fs on the partition, not the device...

So the commands I had to run to resize the partition successfully were as follows:

parted /dev/sdc resizepart 2 100%
e2fsck -f /dev/sdc2
resize2fs /dev/sdc2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.