custom rom and Android file system encryption

My phone failed to encrypt after I rooted it. So this is the solution:

The problem is, that there is no space left for the encryption header. so you need to make the partition smaller in order to encrypt it.

  1. install TWRP and go into the console
  2. find out what is your data partition. it should be something like /dev/block/mmcblk0XX
    mount
    
  3. umount your data partition
    umount /data
    umount /sdcard
  4. Now display the block count of your partition (e.g. 6661115)
    tune2fs -l /dev/block/mmcblk0pXX
  5. wirte this „Block count:“ on a paper and reduce it by 8. This should be something like 32kB.
  6. check your partition before reducing it.
  7. e2fsck -f -p /dev/block/mmcblk0pXX
  8. Now you can reduce the partition size by invoking:
    resize2fs /dev/block/mmcblk0p26 6661107
  9. now you need to reorder your file system with this command:
    e2fsck -f -p /dev/block/mmcblk0p26
  10. restart and encrypt your file system.