Dual Booting/WiP

From postmarketOS
🚧 This page is a work-in-progress. Some information contained within may be inaccurate or incomplete.

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 android phones

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. Then running pmbootstrap flasher boot will start pmos.

Recovery partition

NOTE: doing this will make you lose the android recovery mode.

If pmos kernel is written to the recovery partition, then it will boot 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.

A/B slots

On phones that have A/B slots, you can write pmos kernel to slot B, and leave slot A for android.

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

Or 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 many device that use uboot (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 uboot doc

On some amlogic device's uboot. There is a multiboot 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 data

Stowaway

Some devices (like Pixel 3) use metadata encryption. This is not implemented in pmos. And will fail. Devices launched with Android 11 or higher have their metadata encrypted. To check if your phone has it run dmctl table userdata. If it outputs an error, then you can use stowaways.

for developers that want to fix it. There might be a way to remove it?

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.

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 partition with the stowaway.

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

# Note: This will only work on edge when !4386 is merged
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. With 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

See also