How to find the size of an unmounted partition on Linux?
The command is:
blockdev --getsize64 /dev/mmcblk0p1
It gives the result in bytes, as a 64-bit integer. It queries the byte size of a block device, as the kernel see its size.
The reason, why fdisk -l /dev/mmcblk0p1
didn't work, was that fdisk
does some total different thing: it reads in the partition table (= first sector) of the block device, and prints what it found. It doesn't check anything, only says what is in the partition table.
It doesn't even bother if the partition table is damaged, or the block device doesn't have one: it will print a warning that the checksum is not okay, but it still prints what is finds, even if the values are clearly non-sense.
This is what happened in your case: /dev/mmcblk0p1
does not have a partition table. As the name of the device shows, it is already the first partition of the physical disk /dev/mmcblk0
. This disk contains a partition table, had you queried it with fdisk -l /dev/mmcblk0
, it had worked (assuming it had an msdos partition table).
Try lsblk
, it doesn't even require root:
$ lsblk -b
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 34359738368 0 disk
├─xvda1 202:1 0 1676673024 0 part [SWAP]
└─xvda2 202:2 0 32682016768 0 part /var/spool
The -b
parameter tells it to output the size in bytes.
To get the exact value of total size of the partition run:
awk '{print $1*512}' /sys/class/block/mmcblk0p1/size