androidbashmountcd-rom

How to mount Android as CD-ROM?


I have Galaxy S4 with custom ROM and kernel. I need to mount ISO image from sdcard to Windows/Linux PC as CD-ROM.
There's a "DriveDroid" app that works fine, but I need to do it manually (as a study). Windows 8 writes that "Device needs to be formatted".
code (bash script)

# Disable USB
echo 0 > /sys/class/android_usb/android0/enable

# Set Vendor and Product IDs
echo 0x04e8 > /sys/class/android_usb/android0/idVendor
echo 0x6860 > /sys/class/android_usb/android0/idProduct

# Set mass_storage mode
echo mass_storage > /sys/class/android_usb/android0/functions

# Enable CD-ROM and make read-only (ERROR HERE!)
echo 1 > /sys/class/android_usb/android0/f_mass_storage/lun0/cdrom
echo 1 > /sys/class/android_usb/android0/f_mass_storage/lun0/ro

# Set path to ISO
echo /mnt/shell/emulated/0/obraz.iso > /sys/class/android_usb/android0/f_mass_storage/lun0/file

# Enable USB
echo 1 > /sys/class/android_usb/android0/enable

However, both cdrom and ro files are still set to 0. What else should I do to make them "1" ?


Solution

  • Before writing 1 to "cdrom" and "ro" I had to empty "file" file. Thanks @FrozenCOW (Developer of DriveDroid) for help!

    # Clear path to ISO
    echo "" > /sys/class/android_usb/android0/f_mass_storage/lun0/file
    
    # Enable CD-ROM and make read-only (ERROR HERE!)
    echo 1 > /sys/class/android_usb/android0/f_mass_storage/lun0/cdrom
    echo 1 > /sys/class/android_usb/android0/f_mass_storage/lun0/ro
    
    # Set path to ISO
    echo /mnt/shell/emulated/0/obraz.iso > /sys/class/android_usb/android0/f_mass_storage/lun0/file