9

I have microSD card with Ubuntu 20.10 for RaspberryPi 4. The microSD card is 32GB in size, however only about 2GB in total is being occupied on it. I would like to clone it onto 16GB microSD card and while I know how to successfully do it using GUI tools, I struggle with CLI.

The steps that I came up with so far are:

  1. Power Off raspberry Pi
  2. Remove SD card and insert into a computer running Ubuntu 20 (appears as /dev/sdb)
  3. Check partitions using parted -l which shows that the partition I want to shrink has number 2.
  4. As partitions on this microSD card were automatically mounted on this OS, I unmount them all with umount /dev/sdb1 and umount /dev/sdb2
  5. I run file system check and let it complete using e2fsck -f /dev/sdb2
  6. I shrink filesystem using resize2fs /dev/sdb2 10G
  7. I shrink the partition using parted /dev/sdb resizepart 2 10G

At this point I open GParted just to visually verify my work and I am greeted with this error on partition /dev/sdb2 : link

If I now insert this microSD card to my RaspberryPi 4 it fails to boot and gets stuck on this screen: link

I am just playing around here so I'm not afraid to lose any data, I just want to learn how to properly shrink a partition of RaspberryPi microSD using CLI.

ProTofik
  • 469

1 Answers1

7

I just figured it out myself. After step 7, there is a need for one more step:

  1. After shrinking partition, extend filesystem to the limits of new partition by again running resize2fs /dev/sdb2 without specifying new size.
ProTofik
  • 469