Mounting Android encrypted storage on the Galaxy S2

Because I like to understand how things work before they break, I wanted to be able to mount the encrypted storage of my Galaxy S2 phone from the ADB shell.

My understanding of the Android encryption system is that there is a metadata file stored in /efs at least for phones that have an efs partition. This metadata file contains the normal LUKS headers and encryption keys.

The following works for me in the ADB shell, it mounts the efs partition and then requests that vold unlocks the storage.

mkdir /efs
mount /dev/block/mmcblk0p1 /efs
setprop ro.crypto.state encrypted
vdc cryptfs checkpw 'your passphrase here'
mount -o ro /dev/block/dm-0 /data