Shrinking image with btrfs tools / NEED HELP

Need some help with this. I shrank the btrfs partition but missed a step or 2 and corrupted the disk.

I’m working from the potato through SSH. The sd card is 32gb and I need to shrink that as small as possible to share.

I ran the following commands to create the file system
sudo mkfs.btrfs -L data /dev/mmcblklp2
sudo mkdir -v /mmcblklp2

I made sure the correct partition showed up with df -h /data the started resizing. Once I get an error that no more space was available, I ran fdisk. I have a back up of this image and can start the process over but what went wrong? @Da_Xue


@Da_Xue , I was able to shrink down to 8gb then compress to 2.5gb with xy.

Now, when flashing the image to a new sd card, is there a way to automatically expand the file system? Now, it sets it to 8gb and the file system is maxed out. I have to use btrfs resize / fdisk OR gparted to expand it back out.

If using Raspian, sudo raspi-config has a 1 click option to expand, which just runs a bash script in FDISK. If using another OS that doesn’t have raspi-config, this is multiple steps and if we are doing devices in large batches – time consuming, requires moderate skill.

@Da_Xue with the flashing tool you are working on, can you also write a script that expands the file system to the full size of the card?

Dump the MicroSD card to a file using dd and try this:

You need to have btrfs-progs installed on a Debian machine.