Using command-line to boot into primary and secondary ROM of MultiROM


Question

I've a OnePlus One with unlocked bootloader, modified TWRP v2.8.6, unofficial MultiROM v32k, MultiROM Manager v1.186, Cyanogen OS 12 as primary and several Android 5.1 secondary ROMs. I don't have any non-Android secondary ROM.



I created a Android backup script in my PC which requires me to boot into a particular ROM of mine for backup to take place. This is not an XY problem and hence I need not to discuss anything about the flexibility of backup. I must boot into a particular secondary ROM (say S1).



At present, I'm using , Tasker precisely, which using time trigger launches MultiROM and uses combination of input tap commands to navigate to S1's entry and taps it to boot into it. As you may have guessed, this approach is mundane and is bound to fail should the user deliberately or inadvertently touches any soft/hard button or interacts with UI of the active app during which the series of input commands are in use.



I'm absolutely aware about AutoInput, Xposed Additions Pro apps and screen pinning of an app, where the former two allows independently disabling soft/hard keys for an active app. AutoInput can even simulate recorded touches. However, none of them can disable input from touchscreen, with touch input being the biggest cause of failure with current solution.



Being unable to find out a way to block touch input on-the-fly, I decided to figure how MultiROM Manager app causes a device to boot into a particular ROM. It was a hopeless journey to begin with, given that the keywords viz. command, multirom, adb, boot, secondary, primary ROM, are found wherever MultiROM is mentioned. Since even advanced web search didn't benefit me, I decided to peek into the output of and see whether it gives me something useful. Once again, nothing of any good use.



I found myself left with the choice to contact Vojtech Bocek (Tassadar, the original developer of MultiROM) for the solution or peek into the source code of the app. Deciding to go with the latter choice, during my exploration I stumbled upon these lines in MultiROM.java




public void bootRom(Rom rom) {
String name = (rom.type == Rom.ROM_PRIMARY) ? INTERNAL_ROM : rom.name;
Shell.SU.run("%smultirom --boot-rom='%s'", m_path, name);
}


Being through with libsuperuser already, I took an educated guess that Shell.SU.run("%s/multirom --boot-rom='%s'", m_path, name) most likely corresponds to the command run in a shell with superuser privilege.



And, this is the end of the story since I've checked all the locations under $PATH and none of them contains the binary named multirom.



So, how do I boot into a particular ROM now?


Answer

I searched for the string multirom --boot-rom and came across an interesting paste (copy) posted by an untitled guest, with these relevant lines:



<alvinmobile> How do you autoboot other rom in a secondary rom?


<alvinmobile> I mean where do you store the info?


<Tassadar> it runs "multirom --boot-rom=nameoftherom" in su shell, and MultiROM takes care of that - it loads ROM list as usual and either directly kexecs the required kernel or sets force-autoboot into rom X (which saves into multirom.ini) and reboots



I was on the right track as it seems. I suddenly realized that multirom installer zip may be the final piece of the puzzle. And it was, since it contains the multirom binary and uses extract_multirom.sh script to place the binary et al into /data/media/0/multirom (accessible with root access only).


As for finding the name of a ROM, it is what you see in the ROM list in the app or the name of the top-level directories under /data/media/0/multirom/roms.


Boot into the ROM


(Prefix adb shell in commands if you want to use adb to test them.)


The command is very simple:


su -c /data/media/0/multirom/multirom --boot-rom=ROM_NAME

Replace ROM_NAME with the name of the ROM to which you want the device to boot into. It is case-sensitive so Internal works but internal doesn't to boot into primary ROM.


I've not tested passing a ROM's name consisting of special characters but whitespace can be escaped using '' and \. E.g., the name Xenon HD can be passed as 'Xenon\ HD' and the whole command would be


su -c /data/media/0/multirom/multirom --boot-rom='Xenon\ HD'

You can create a symlink for convenience.


Trial and Error


With a bit of testing, I reached the conclusion that the ROM can be switched by editing the multirom.ini file alone, followed by an ordinary reboot instruction. Among other lines in that file, these are the most useful ones:



current_rom=COS12
auto_boot_seconds=5
auto_boot_rom=Internal
auto_boot_type=0

Here,



  • current_rom - contains the name of the currently active ROM or the last active ROM if the device powers off without an instruction to be switched into an another ROM

  • auto_boot_seconds - timeout to boot into default ROM

  • auto_boot_rom - the ROM that should be booted into after timeout

  • auto_boot_type - governs whether there should be a direct switch between ROMs or should the UI for ROM selection be shown during boot


(There are no sources to support the claims. I've reached the conclusion based on my experiment only.)


Let's assume that your active ROM is named COS12, internal ROM is named Internal and you want to switch to Xenon HD. Switch it this way:


(Requires Busybox)



su -c cp /data/media/0/multirom/multirom.ini /data/media/0/multirom/multirom.ini.orig # one time command and optional, but it is safe to make backup always
su -c sed -i 's/current_rom.*/current_rom\=ROM_NAME/g' /data/media/0/multirom/multirom.ini # for Xenon HD, ROM_NAME would be Xenon\ HD
su -c sed -i 's/auto_boot_type.*/auto_boot_type\=2/g' /data/media/0/multirom/multirom.ini # changing to `2` causes MultiROM to directly boot into the ROM mentioned in `current_rom`. The setting would later be reverted to 0 after successful boot
su -c reboot

Commands are optional here. You can use a file editor app, such as QuickEdit to edit the file.


Note: During reboot:



  • If auto_boot_type is found 1, the ROM selection UI would be shown after boot logo and it overrides auto_boot_rom which means after timeout the device would boot into whatsoever the current_rom has, automatically.



  • If auto_boot_type is found 3, device would boot straight into whatsoever the current_rom has, but, auto_boot_rom would also now be found same as the current_rom. auto_boot_type later reverts to 1 after successful boot.


    I cannot comment on whether this is a bug or a desired behavior, but this is how it is.




Further note that I wouldn't be surprised if methods mentioned in this answer fails for a non-Android ROM.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes