Skip to content

Instantly share code, notes, and snippets.

@zhiyue
Forked from sxiii/resize-sdcard-partitions.md
Created December 5, 2022 10:48
Show Gist options
  • Save zhiyue/a5452be339b7bd87b9f4e403777a9836 to your computer and use it in GitHub Desktop.
Save zhiyue/a5452be339b7bd87b9f4e403777a9836 to your computer and use it in GitHub Desktop.
Resize linux partition that was written by DD or similar instrument to use all available space

Please run the following commands to resize a partition.
IMPORTANT NOTE: Don't forget to change partition address from /dev/sdb2 to your actual partition!
CHANGES ARE DONE IN TWO OR THREE PLACES.
Example below are for /dev/sdb2 partition which is called like "/dev/sdb 2" for growpart
and like "/dev/sdb2" for resize2fs & e2fsck.
Requirements: * growpart; * resize2fs; * e2fsck if disk requires checking.
Install growpart in arch/manjaro: pikaur -S growpart (resize2fs and e2fsck are usually bundled with OS)

sudo growpart /dev/sdb 2
sudo resize2fs /dev/sdb2

Also run as a oneliner is possible:

sudo growpart /dev/sdb 2 && sudo resize2fs /dev/sdb2

If it asks for checking partition errors, use this:

sudo e2fsck -f /dev/sdb2

Or, as a oneliner:

sudo growpart /dev/sdb 2 && sudo e2fsck -f /dev/sdb2 && sudo resize2fs /dev/sdb2

NOTE: The following works for EXT4 parition. If your parition is F2FS, please use:

resize.f2fs /dev/sdb2

After issuing this command you might want also to run sudo gparted and check if your partition is now filled in full.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment