Reduce duplication between ramdisk and disk image codepaths.

Change-Id: Ie9e2d60ffe94f971953d52b7b5bce9c1a86fb1b5
Merge "Reduce duplication between ramdisk and disk image codepaths."