1

I'm trying to follow RomanG's instructions in this thread: http://www.raspberrypi.org/forums/viewtopic.php?f=91&t=19468 on the Raspberry Pi Forums in order to shrink a Raspbian Image to fit on a smaller SD card.

I've already uninstalled a bunch of stuff and shrunk the partition using GParted. All that is good and I've created an image using dd that I've mounted using losetup.

When I run fdisk -l on /dev/loop0 I get the following which also all looks good.

$ sudo fdisk -l /dev/loop0

Disk /dev/loop0: 4124 MB, 4124049408 bytes
255 heads, 63 sectors/track, 501 cylinders, total 8054784 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b5098

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1            8192      122879       57344    6  FAT16
/dev/loop0p2          122880     3706879     1792000   83  Linux

I want to shrink the image to match that used by the actual partitions in the image, but when I run f2resize I get the following error:

$ sudo resize2fs -p /dev/loop0p2 3706880
resize2fs 1.42 (29-Nov-2011)
The containing partition (or device) is only 448000 (4k) blocks.
You requested a new size of 3706880 blocks.

dan@danDevU:~/Desktop$ sudo resize2fs -p /dev/loop0 3706880
resize2fs 1.42 (29-Nov-2011)
resize2fs: Bad magic number in super-block while trying to open /dev/loop0
Couldn't find valid filesystem superblock.

Checking the image for errors gives what looks like a similar error:

$ sudo e2fsck -f /dev/loop0
e2fsck 1.42 (29-Nov-2011)
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/loop0

The superblock could not be read or does not describe a correct ext2
filesystem.  If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device&gt;

Any ideas how I can sort this?

I need to create an image that will fit on a 2GB SD card, and I've managed to squeeze everything down to do that - other than the image itself.

(Note: I am trying to shrink the image on a Ubuntu 12.04 box. This is the same box that I used to dd the image off the SD card)

Fat Monk
  • 119
  • 1
  • 5

1 Answers1

2

Well, about 8 years later, I stumbled across a similar problem, so I'm posting the solution for anyone out there.

You are running resize2fs on the loop block device, you're supposed to run it on the partition.

resize2fs /dev/loop0p2 3706880

I know that the -p flag supposedly allows supplying a device but I'm not sure if it's some kind of bug or not how this option is supposed to be used, anyway for me it worked by running it on the partition itself.

php_nub_qq
  • 257
  • 2
  • 12
  • Your answer is totally correct, but the last paragraph seems out of place: the -p option to resize2fs is not anything to do with "allows supplying a device" (see man resize2fs). – goldilocks Aug 07 '22 at 20:14