Dualbooting Android with Ubuntu is possbile due to Ubuntu phone architecture puting system files to a separate image file on device.
If you don't choose to clean you data partition in recovery Ubuntu Touch should not be removed when installing Cyanogenmod. Therefore you can either first install Android and then Ubuntu Toich or vice versa.
Do a regular Ubports installation for MX4. Ubuntu is always installed in /data/system.img and /data/ubuntu.img which allows it to easily coexist with Android on one device.
Please note that Ubports guide for MX4 is not precise and there is no way to reboot to recovery from fastboot. You will first need to install the recovery and then reboot to it and use this command to install Ubports:
sudo ubuntu-device-flash --server=http://system-image.ubports.com touch --device=arale --channel=16.04/stable --recovery-image=recovery-arale.imgYou can choose a channel you like (but please note for regular use stable is possibly the best choice): stable, rc, devel
Once the installation is complete the device will automatically reboot itself and boot to Ubports.
Flash recovery: twrp-184.108.40.206-mx4.img
Install the latest available CM13 build for MX4: cm-13.0-20160820-UNOFFICIAL-mx4.zip
After you install CM and exit recovery the device will automatically boot to CM only.
Don't forget to update any of the below scripts with the new filenames and paths actually used.
The script is using the following partition to write the data: "BOOTPART=/dev/mmcblk0p7", but this may differ on various devices so please see below on how to find the correct partition nubmer.
In order to utilise both systems on your device you will have to have custom recovery installed (eg. the twrp one linked above) and boot it everytime you want to switch to a different os. In addition you will have to install one of the following archives in that recovery each time you want to switch to a different os:
Save those eg. to /sdcard/Download for easy access in recovery.A better way: (allows for Ubuntu OTA updates)
However, if you want to be able to upgrade Ubports using regular OTA system updates here is another and much easier-faster way to switch OSses.
You'll need to have this recovery image installed for OTA updates to work
The simplest way is to install this app, extract boot.img from this archive: mx4_switch_to_ubports.zip and flash it using this app everytime you want to boot Ubuntu. This app remembers the last flashed file so you can do this really fast once you do it the first time.
On Ubuntu I've found it easiest to use this script (be careful, this si MX4 only and the boot partition may deiffer on various MX4 versions, check this command: "cat /proc/emmc"): boot-android.sh Update the script to match the path of the Android boot.img file you need to extract from from this archive: mx4_switch_to_cyan.zip and save the boot.img to Download folder on your Android filesystem named as "boot-cyan.img". As for the script itself it is ideal to save it on your Ubuntu filesystem for easy access.
Updated on: 28-10-2018, Created on: 18-09-2017