Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to shrink a partition on a 64GB SD Card down so that I can fit it on a 32GB USB thumb drive, but I'm not having any success. I have the SD card plugged into a USB adapter, which is plugged into a Raspberry Pi running Raspbian.

Here is the output of fdisk -l:

Disk /dev/mmcblk0: 7948 MB, 7948206080 bytes
4 heads, 16 sectors/track, 242560 cylinders, total 15523840 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: 0x0002c262

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880    15523839     7700480   83  Linux

Disk /dev/sda: 63.9 GB, 63864569856 bytes
4 heads, 32 sectors/track, 974496 cylinders, total 124735488 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: 0x000798a3

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            4096      147455       71680    c  W95 FAT32 (LBA)
/dev/sda2          151552   124735487    62291968   83  Linux

It's /dev/sda2 that I want to shrink, but when I try resize2fs /dev/sda2 20G I get:

resize2fs 1.42.5 (29-Jul-2012)
resize2fs: Bad magic number in super-block while trying to open /dev/sda2
Couldn't find valid filesystem superblock.

I also tried shrinking the partition first via fdisk and then running resize2fs, but it failed with the same error message.

How can I shrink my partition?

PS. I have already imaged the card so I can restore should anything go wrong.

share|improve this question
    
Obviously it's not an ext[234] partition. Mount it and have a look at the output of mount. –  Hauke Laging Feb 20 at 8:18
    
It's f2fs, which helps explain why I was so confused because Raspbian doesn't seem to support it out of the box (if at all). I switched to booting into RaspBMC and can now mount. –  me-- Feb 20 at 9:21

1 Answer 1

up vote 1 down vote accepted

I don't understand the problem.

If the motivation for shrinking the partition is that you want to move it to another physical storage then the "shrinking magic" is:

  1. create the partition on the target storage

  2. format the new partition

  3. mount the partition (and the source partition)

  4. cp -a /path/to/source/. /path/to/target

Much faster, much easier, less dangerous, clean filesystem.

share|improve this answer
    
Thanks. I guess I was just over/under thinking it. I'm not very proficient in linux and just assumed imaging would be the safest way to ensure one takes a "perfect" backup. –  me-- Feb 20 at 10:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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