ext4 sdcard - adrian-bl-yuga/device-sony-c6603 GitHub Wiki

Version 5.1.1-p1 and later includes support for ext4 formatted SD Cards. Please note that you can not simply plugin an SD Card in your phone and reformat it using ext4: This will not work due to AOSP limitations and SE-Linux.

This small guide will show you how to correctly reformat and SD Card for use with the AOSP Build for Yuga.

Step 1: Formatting the SD Card

This step requires a Linux PC (or an OSX or Windows Computer with e2fsprogs installed). Please note that you can not format the SD Card on your phone as the included mke2fs binary lacks LFS support and will therefore fail to format anything bigger than 2GB.

So, the first step is to change the first partition of your SD Card to type 83 via fdisk, cfdisk or whatever you like to use.

Example using fdisk

# fdisk /dev/sdz   # <-- change this to your sd-card blockdev
Welcome to fdisk (util-linux 2.21.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): t             <--- switches into partition edit mode
Selected partition 1                <--- selects first partition
Hex code (type L to list codes): 83 <--- changes it to 83 = linux

Command (m for help): w             <--- writes changes to disk
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

The partition type has now been correcred: You can now format the card using mkfs.ext4:

# mkfs.ext4 -m 0 /dev/sde1 

Note the -m 0 parameter: This will instruct mkfs.ext4 to not include any space reservation: Doing this would be a waste on the SD Card

Step 2: SE-Linux relabeling

Your SD Card does now contain a valid ext4 filesystem. The next step will be to correct the posix and SE-Linux permissions of the freshly formatted device.

  • Turn of your phone and insert the new SD Card
  • Connect to your phone via adb and verify that the card was mounted:
root@c6603:/ # grep sdcard1 /proc/mounts                                     
/dev/block/vold/179:33 /mnt/media_rw/sdcard1 ext4 rw,dirsync,seclabel,nosuid,nodev,noexec,noatime,data=ordered 0 0
/dev/fuse /storage/sdcard1 fuse rw,nosuid,nodev,noexec,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
  • Correct the permissions of the filesystem by running these commands via adb on your phone:
root@c6603:/ # restorecon -r /mnt/media_rw/sdcard1
root@c6603:/ # chmod 0770 /mnt/media_rw/sdcard1
root@c6603:/ # chown 1023:1023 /mnt/media_rw/sdcard1
  • Verify that the filesystem is now accessible (you should see a lost+found folder)
root@c6603:/ # ls -l /storage/sdcard1/
drwxrwx--- root     sdcard_r          2015-05-14 20:20 lost+found