Dual Booting/WiP

Category:guide
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 ==
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 store pmOS because userdata is used by Android (However, you can share 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 .
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 not recommended.
=== 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 contains 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 ==
On certain device, it may be possible to do custom partition.
====Shrink Userdata====
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====
1. Create a partition that named as systempmos in the partition table.
====Creating Custom Partition for "Use the whole storage device" partition scheme====
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 =
* On UEFI / BIOS based devices, grub can be used for dual booting (see Dual boot with Windows on arch wiki)
* FBE encryption
* Metadata Encryption
* FAQ Entry.
* Dual booting PMOS and netbsd demo video
* Some UEFI Implementations for Android smartphones like (efidroid,Renegade Project) can be used together with postmarketOS (see Guides for dual booting pmOS on OnePlus 6/6T, but some part of it can be reused on some other devices.)