Android - How can I mount an ext4-formatted SD card with correct permissions (with root)?

This was supposedly fixed several months ago, but people are still reporting problems. I can read items on the card, but do not have write permission. To fix it, I combined strategies from a few sources.

  1. Partition card with MS-DOS partition table and ext4 filesystem. I used GParted on my (Linux) desktop computer.
  2. Insert the card into your phone. (You will probably not have write access now.)
  3. Open the terminal emulator, installed by default in Cyanogenmod.
  4. Type in the following (I recommend WiFi Keyboard for large blocks of text). Give the emulator root privileges when it requests them.

The $ and # indicate prompts, so don't type them in.

$ su
# chown media_rw:media_rw /mnt/media_rw/sdcard1
# chmod g+w /mnt/media_rw/sdcard1

This changes the SD card's permissions. The owner and group change from system to media_rw, and it also gives the group write access.