Dual Booting/WiP

From postmarketOS Wiki


To dual boot pmOS you need a boot method and a way to store data. After selecting both and following the guide, you will have a working device with dual boot.

For a lot of the methods, you will need pmbootstrap

How to boot pmOS on an Android phone

Booting with a computer

This is the simplest option, but you will need a computer to boot pmOS. If used with an SD card to store data, then nothing is going to be modified on the phone.

After entering fastboot mode on your phone, run pmbootstrap flasher boot to start pmOS.

Recovery partition

Icon WARNING: Doing this will make you lose the android recovery mode, and will overwrite any recovery OS/software installed on the recovery partition(e.g. TWRP)

If the pmOS kernel is written to the recovery partition, then your device will boot into pmOS when you enter recovery mode. You can get the image of the kernel by running pmbootstrap export. And fastboot flash recovery /tmp/postmarketOS-export/boot.img to flash it to recovery.

Under this method , you would require to find a way to stone pmOS because userdata is used by Android (However you can shared userdata between pmOS and android with #Stowaway}.

A/B slots

On phones that have A/B slots, you can flash pmOS to system partition of slot B, and leave slot A and userdata for Android. If you want a bigger partition for pmOS , Please refer to #Custom partition.

Switching slots can be done with a computer using fastboot --set-active=[a/b] while the phone is in fastboot mode.

Alternatively, you can use Switch My Slot on Android to switch to pmOS.

On pmOS you can use qbootctl to switch back to Android.

U-boot

U-Boot_porting#Implement_multiboot_involving_Android_in_a_device_aport

On the Nokia N900 and other devices that use U-boot (like MangoPi MQ-Pro (mangopi-mq-pro), Xunlong Orange Pi 3 (xunlong-orangepi3)), U-boot provides a mechanism to select the OS. See Nokia N900#Installation and bootmenu on U-boot doc

On some Amlogic devices with U-boot, there is a multi-boot mode: Amlogic#Boot process

lk2nd/lk1st

lk2nd/lk1st

On devices with lk2nd the boot image is loaded from an ext2 boot partition either on eMMC or SD card. Since lk2nd keeps backwards compatibility with Android boot images, you can flash your Android boot.img via lk2nd and it will boot that image unless an SD card with postmarketOS is inserted.

Where to store pmOS

Stowaway

Some devices (like the Pixel 3) use metadata/FBE encryption to encrypt the data partition. This is not supported in pmOS, and will cause failure. Devices launched with Android 9 or higher have their metadata /FBE encrypted. To check if your phone has it, run dmctl table userdata. If it outputs an error, then you can use stowaways.

It is possible to disable the encryption Multidisabler (for Samsung device) or [1]

Read everything before doing anything. This only works on edge.

The end result is going to be that a folder(.stowaway/pmos/) in a partition will be used for root. This is useful for Android devices where modifying the partition table is a crime and sharing userdata with Android (That may not a good idea considering Android might destroy pmOS' filesystem permissions).

Preparation

To use this method, you will need to put files from root into a .stowaway/pmos/ on your phone. To transfer these files, we will use tar. And to boot with this method, you need to force pmOS to boot the partition which comtains the stowaway.

Here is a simple script that will make a pmos.tar and force booting to userdata.

pmbootstrap init

# Modify deviceinfo to force booting on userdata
pmbootstrap install --split
pmbootstrap shutdown
cd ~/.local/var/pmbootstrap/chroot_rootfs_*/
# Change userdata if you want to use a different partition
echo "deviceinfo_kernel_cmdline_append=\"pmos.stowaway pmos_root=/dev/disk/by-partlabel/userdata\"" | sudo tee -a etc/deviceinfo
sudo sed -i '3,0s/^/#/' etc/fstab # don't mount /boot
pmbootstrap install --split

# Make pmos.tar
pmbootstrap export
mkdir /tmp/PMOS_ROOT
sudo mount -o loop /tmp/postmarketOS-export/*-root.img /tmp/PMOS_ROOT
sudo mount -o loop /tmp/postmarketOS-export/*-boot.img /tmp/PMOS_ROOT/boot/
cd /tmp/PMOS_ROOT
sudo tar -cf ../pmos.tar *
cd /tmp
sudo umount /tmp/PMOS_ROOT/boot/
sudo umount /tmp/PMOS_ROOT

#fastboot flash boot /tmp/postmarketOS-export/boot.img

Flash command is commented out because, I don't want to override someone's android install

Unpacking pmos.tar on your phone

Now move /tmp/pmos.tar to your phone, using the command adb push /tmp/pmos.tar /sdcard

You will need root or TWRP for this part, run mkdir /data/.stowaways/pmos and mv /sdcard/pmos.tar /data/.stowaways/pmos. This will make a directory and move our tar into it. To unpack it, we need to run cd /data/.stowaways/pmos and tar -xf pmos.tar. Now we can remove pmos.tar with rm pmos.tar.

mkdir -p /data/.stowaways/pmos
mv /sdcard/pmos.tar /data/.stowaways/pmos
cd /data/.stowaways/pmos
tar -xf pmos.tar
rm pmos.tar

SD card

You can flash the file system to a SD card. Then pmOS will be able to use it.

pmbootstrap install
pmbootstrap export
# flash /tmp/postmarketOS-export/[device].img to SD card

Custom Partition

Icon WARNING: THIS PROCESS CAN BRICK YOUR PHONE IF DONE INCORRECTLY! IF YOU DON'T FEEL COMFORTABLE RECOVERING YOUR PHONE VIA DEEP FLASHING, DO NOT ATTEMPT THIS

On certain device , it may be possible to do custom partition.

Shrink Userdata

Icon WARNING: THIS PROCESS WILL DESTROY YOUR PHONE DATA.


First, you need to shrink the userdata partition to free up space for custom partition for pmOS.

1. Shrink userdata in the partition table

2. Boot up to TWRP to format userdata

Then depending on partition scheme, you may need to follow #Creating Custom Partition for "Subpartitions" partition scheme or #Creating Custom Partition for "Use the whole storage device" partition scheme to create a custom partition for pmOS.

Creating Custom Partition for "Subpartitions" partition scheme

Note Under the Subpartitions partition scheme,pmOS would looking for Subpartitions in partation that is labelled as userdata or system* (any partition that has system prefix in the name) in the partition table thus the partition have to have a system prefix in the label.However In order to not confuse the bootloader.DO NOT LABEL THE PARTITION WITH NAME LIKE system_a system_b system_c userdata.For example systempmos is a perfect name that would work.

1. Create a Partition that named as systempmos in the partition table.

Creating Custom Partition for "Use the whole storage device" partition scheme

Note Under the Use the whole storage device" partition scheme,pmOS_boot and pmOS_root has to be labelled in the file system. The postmarketOS initramfs checks those partiton label via file system, not the partition table. However It is recommended to label those partition in the partition table if you want them to be flashable in fastboot.(It doesn't matter what you have labelled them in partition table.As long as fastboot is able to read those label.)
Note The disk image the generated by pmbootstrap has already been labelled

1 . Create a new boot partition that labelled as pmOS_boot in the file system

2 . Create a new root partition that labelled as pmOS_root in the file system

See also