refactor ramdisk code to reduce duplications