Can’t mount partition copied from image file on your SD card

For example you have downloaded 32GB .img file from the Internet and you burned it to your SD card by using dd command in Linux:

dd if=pi.img bs=4M|pv|dd of=/dev/mmcblk0 bs=4M

Just to mention again, it’s good to have pv command in the middle in order to track progress of the write.

After couple of hours of wait you finally want to mount the partition to check the contents but you end up with message:

bad geometry: block count 7803392 exceeds size of device

Mounting fails, due to simple reason. Not all SD cards are the same size, so somebody created an 32GB image of SD card and ended up with file:

-rw-r--r-- 1 erol erol 32026656768 May 23  2016 /home/erol/pi.img

Notice the file size: 32026656768, now check your SD card size with fdisk:

fdisk -l /dev/mmcblk0
 Disk /dev/mmcblk0: 29.8 GiB, 32010928128 bytes, 62521344 sectors
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disklabel type: dos
 Disk identifier: 0xa97ea95a
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 * 8192 124927 116736 57M e W95 FAT16 (LBA)
/dev/mmcblk0p2 124928 62552063 62427136 29.8G 83 Linux

So it turns out that your card is 32010928128 bytes which is 15728640 bytes (15MB) smaller than the image size which is 32026656768 bytes.

In order to be able to mount the image and let it work properly you need to execute these two commands:

e2fsck -f /dev/mmcblk0p2
resize2fs /dev/mmcblk0p2

After executing these two commands, you would have made file system check on the partition and resized it to fit your SD card.

Leave a Reply

Your email address will not be published. Required fields are marked *