Skip to content

Instantly share code, notes, and snippets.

@koumaza
Last active December 12, 2020 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koumaza/141fb61d4834b419c71faaa99cef6290 to your computer and use it in GitHub Desktop.
Save koumaza/141fb61d4834b419c71faaa99cef6290 to your computer and use it in GitHub Desktop.
Calculate Partition Size

Step 1 - Run fdisk

fdisk -l /dev/YOURDEVICE
## Or
fdisk -l /dev/block/YOURDEVICE
## Or
fdisk -l /dev/block/by-name/YOURDEVICEPARTTIONNAME

# Which is my device
df -a # Outputs mount-points

Step 2 - Calculate

There are four things to watch here.

  • Sector Size
  • Start (sector)
  • End (sector)
  • Name
Run this
# Posix Shell
echo $(( ( Start - End ) * SectorSize ))
# Fish
math "( Start - End ) * SectorSize )"
outputs as byte

byte*10^-6=megabyte

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