PinePhone Pro/Create a multi-distribution image using rk2aw
This article explains how to install megi's rk2aw loader, U-Boot to SPI and a multi-distribution image to the microSD card and eMMC of the PinePhone Pro. Further instructions regarding rk2aw can be found on megi's website under https://xff.cz/kernels/rk2aw/rk2aw-rk3399-pinephone-pro/INSTALL. Please note that loader and userspace utility to flash it are free, but not open-source.
Multi-Distro on MicroSD Card
Flash Rk2Aw Loader to SPI
Connect PinePhone Pro to a Linux machine, start a ssh connection and download installer to flash pre-loader to the phone's SPI.
ssh <user>@<phoneip> cd ~/Downloads curl -O https://xff.cz/kernels/bootloaders/ppp.tar.gz tar -xvzf ppp.tar.gz -C ~/Downloads # scp -r ~/Downloads/ppp <user>@<phoneip>:~/Downloads # copy to phone, non needed sudo ./spinor-flash-initial-setup.sh
Build Multi-Distro on SD Card
Get the compressed distribution images from PinePhone Pro Software Releases, decompress them and mount both partitions "/boot", "/root" from each distro.
lsblk # show /loop, /sd references ├─loop0p1 /media/xxx/BOOT_MNJRO └─loop0p2 /media/xxx/ROOT_MNJRO ├─loop1p1 /media/xxx/boot └─loop1p2 /media/xxx/rootfs ├─loop2p1 /media/xxx/52CA-6165 └─loop2p2 /media/xxx/3d99072c-9fd6-4316-8526-9192e192c441 └─sdb disk (after each dd command you'll see the partition id name to adjust into scripts.) blkid # show UUID for the partition
If necessary erase SD card
sudo dd if=/dev/zero of=/dev/sdb count=945728 bs=32768 status=progress # quick way i.e. # 32GB SDcard (30989615104bytes/32768dim=945728volte) sudo dd if=/dev/zero of=/dev/sdb count=1 bs=32768 status=progress # slow way i.e. # 32GB SDcard (30989615104bytes/32768dim=1volta)
Partition the MicroSD Card
sudo sfdisk /dev/sdb --wipe always <<EOF label: gpt first-lba: 64 table-length: 8 start=64, size=32704, type=D7B1F817-AA75-2F4F-830D-84818A145370, name="loader", attrs=RequiredPartition size=11G, name="ALARM", attrs="RequiredPartition,LegacyBIOSBootable" size=11G, name="MANJARO", attrs="RequiredPartition,LegacyBIOSBootable" size=11G, name="MOBIAN", attrs="RequiredPartition,LegacyBIOSBootable" size=11G, name="PMOS", attrs="RequiredPartition,LegacyBIOSBootable" size=11G, name="UT", attrs="RequiredPartition,LegacyBIOSBootable" size=+, name="extra", attrs="RequiredPartition,LegacyBIOSBootable" EOF
Checking that no-one is using this disk right now ... OK Disk /dev/sdb: 58.25 GiB, 62550179840 bytes, 122168320 sectors Disk model: SD Card Reader Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: C44BE2FC-34D6-4DD8-99FC-7FFB75602A79 Old situation: >>> Script header accepted. >>> Created a new GPT disklabel (GUID: F71BFBA6-D2C3-4C20-8079-1401B10C724C). The maximal number of partitions is 8 (default is 128). /dev/sdb1: Created a new partition 1 of type 'unknown' and of size 16 MiB. /dev/sdb2: Created a new partition 2 of type 'Linux filesystem' and of size 11 GiB. /dev/sdb3: Created a new partition 3 of type 'Linux filesystem' and of size 11 GiB. /dev/sdb4: Created a new partition 4 of type 'Linux filesystem' and of size 11 GiB. /dev/sdb5: Created a new partition 5 of type 'Linux filesystem' and of size 11 GiB. /dev/sdb6: Created a new partition 6 of type 'Linux filesystem' and of size 11 GiB. /dev/sdb7: Created a new partition 7 of type 'Linux filesystem' and of size 3.2 GiB. /dev/sdb8: Done. New situation: Disklabel type: gpt Disk identifier: F71BFBA6-D2C3-4C20-8079-1401B10C724C Device Start End Sectors Size Type /dev/sdb1 64 32767 32704 16M unknown /dev/sdb2 32768 23101439 23068672 11G Linux filesystem /dev/sdb3 23101440 46170111 23068672 11G Linux filesystem /dev/sdb4 46170112 69238783 23068672 11G Linux filesystem /dev/sdb5 69238784 92307455 23068672 11G Linux filesystem /dev/sdb6 92307456 115376127 23068672 11G Linux filesystem /dev/sdb7 115376128 122167295 6791168 3.2G Linux filesystem The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
Get Image Files for the Distros
Enter to Directory
cd ~/Downloads
Download your chosen image from wiki.pine64.org/wiki/PinePhone_Pro_Software_Releases
wget https://github.com/dreemurrs-embedded/Pine64-Arch/releases/download/20230203/archlinux-pinephone-pro-sxmo-20230203.img.xz wget https://github.com/manjaro-pinephone/plasma-mobile/releases/download/beta15-rc4/Manjaro-ARM-plasma-mobile-pinephonepro-beta15-rc4.img.xz wget https://images.mobian.org/pinephonepro/weekly/mobian-pinephonepro-phosh-20230903.img.xz wget https://images.postmarketos.org/bpo/v23.06/pine64-pinephonepro/phosh/20230904-0846/20230904-0846-postmarketOS-v23.06-phosh-22.2-pine64-pinephonepro.img.xz # to do (postmarketOS-edge-phosh via BootStrap) wget https://gitlab.com/ook37/pinephone-pro-debos/-/jobs/4961858606/artifacts/file/ubuntu-touch-pinephone-unified.img.xz
Extract the Compressed Files
xz -v -d -k archlinux-pinephone-pro-sxmo-20230203.img.xz xz -v -d -k Manjaro-ARM-plasma-mobile-pinephonepro-beta15-rc4.img.xz xz -v -d -k mobian-pinephonepro-phosh-20230903.img.xz xz -v -d -k 20230904-0846-postmarketOS-v23.06-phosh-22.2-pine64-pinephonepro.img.xz xz -v -d -k ubuntu-touch-pinephone-unified.img.xz
Mount the Images
sudo su # login with your psw losetup -P /dev/loop1 archlinux-pinephone-pro-sxmo-20230203.img && losetup -P /dev/loop2 Manjaro-ARM-plasma-mobile-pinephonepro-beta15-rc4.img && losetup -P /dev/loop3 mobian-pinephonepro-phosh-20230903.img && losetup -P /dev/loop4 20230904-0846-postmarketOS-v23.06-phosh-22.2-pine64-pinephonepro.img && losetup -P /dev/loop5 ubuntu-touch-pinephone-unified.img
ls -l /mnt/
mkdir /mnt/archlinux /mnt/archlinux/boot /mnt/archlinux/root && mkdir /mnt/manjaro /mnt/manjaro/boot /mnt/manjaro/root && mkdir /mnt/mobian /mnt/mobian/boot /mnt/mobian/root && mkdir /mnt/postmarketos /mnt/postmarketos/boot /mnt/postmarketos/root && mkdir /mnt/ubuntutouch /mnt/ubuntutouch/boot /mnt/ubuntutouch/root
mkdir /mnt/archlinuxsd && mkdir /mnt/manjarosd && mkdir /mnt/mobiansd && mkdir /mnt/postmarketossd && mkdir /mnt/ubuntutouchsd
mount /dev/loop1p1 /mnt/archlinux/boot/ && mount /dev/loop1p2 /mnt/archlinux/root/ && mount /dev/loop2p1 /mnt/manjaro/boot/ && mount /dev/loop2p2 /mnt/manjaro/root/ && mount /dev/loop3p1 /mnt/mobian/boot/ && mount /dev/loop3p2 /mnt/mobian/root/ && mount /dev/loop4p1 /mnt/postmarketos/boot/ && mount /dev/loop4p2 /mnt/postmarketos/root/ && mount /dev/loop5p1 /mnt/ubuntutouch/boot/ && mount /dev/loop5p2 /mnt/ubuntutouch/root/
Check Mounted Images
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop1 7:1 0 3.5G 0 loop ├─loop1p1 259:0 0 122M 0 part /mnt/archlinux/boot └─loop1p2 259:1 0 3.4G 0 part /mnt/archlinux/root loop2 7:2 0 6.3G 0 loop ├─loop2p1 259:2 0 457.8M 0 part /mnt/manjaro/boot └─loop2p2 259:3 0 5.8G 0 part /mnt/manjaro/root loop3 7:3 0 5.6G 0 loop ├─loop3p1 259:4 0 511M 0 part /mnt/mobian/boot └─loop3p2 259:5 0 5.1G 0 part /mnt/mobian/root loop4 7:4 0 2.3G 0 loop ├─loop4p1 259:6 0 243M 0 part /mnt/postmarketos/boot └─loop4p2 259:7 0 2.1G 0 part /mnt/postmarketos/root loop5 7:5 0 3.7G 0 loop ├─loop5p1 259:10 0 380.5M 0 part /mnt/ubuntutouch/boot └─loop5p2 259:11 0 3.4G 0 part /mnt/ubuntutouch/root sdb 8:16 1 58.3G 0 disk ├─sdb1 8:17 1 16M 0 part ├─sdb2 8:18 1 11G 0 part ├─sdb3 8:19 1 11G 0 part ├─sdb4 8:20 1 11G 0 part ├─sdb5 8:21 1 11G 0 part ├─sdb6 8:22 1 11G 0 part └─sdb7 8:23 1 3.2G 0 part
Build Archlinux Partition
Login as root, copy rootfs and bootfs to the partition. You need also to make some changes on some files.
sudo dd if=/dev/loop1p2 of=/dev/sdb2 bs=1M status=progress conv=fsync sudo mount /dev/sdb2 /mnt/archlinuxsd/ sudo scp -r /mnt/archlinux/boot/* /mnt/archlinuxsd/boot sudo mv /mnt/archlinuxsd/boot/boot.scr /mnt/archlinuxsd/boot/boot.scrORIG
sudo su cat << EOF > /mnt/archlinuxsd/etc/fstab # Static information about the filesystems. # See fstab(5) for details. # <file system> <dir> <type> <options> <dump> <pass> # UUID=fd049b8e-615f-4efd-bc96-622c4d40e6cb / ext4 rw,relatime 0 1 # UUID=841C-F9DD /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2 PARTLABEL=ALARM / ext4 rw,relatime 0 1 EOF
mkdir /mnt/archlinuxsd/boot/extlinux
sudo su cat << EOF > /mnt/archlinuxsd/boot/extlinux/extlinux.conf #/boot/extlinux/extlinux.conf MENU TITLE Pinephone Pro Boot Menu LABEL l0 MENU LABEL ALARM FDT /boot/dtbs/rockchip/rk3399-pinephone-pro.dtb KERNEL /boot/Image INITRD /boot/initramfs-linux.img APPEND root=PARTLABEL=ALARM console=ttyS2,115200 console=tty0 loglevel=4 rw rootwait EOF
Build Manjaro Partition
As for previous step proceed for next partition.
sudo dd if=/dev/loop2p2 of=/dev/sdb3 bs=1M status=progress conv=fsync sudo mount /dev/sdb3 /mnt/manjarosd/ sudo scp -r /mnt/manjaro/boot/* /mnt/manjarosd/boot sudo mv /mnt/manjarosd/boot/boot.scr /mnt/manjarosd/boot/boot.scrORIG
sudo su cat << EOF > /mnt/manjarosd/etc/fstab # Static information about the filesystems. # See fstab(5) for details. # <file system> <dir> <type> <options> <dump> <pass> # PARTUUID=362866dc-95cf-4069-9bb8-623aa3cdcb5d / ext4 defaults 0 1 PARTLABEL=MANJARO / ext4 defaults 0 1 EOF
mkdir /mnt/manjarosd/boot/extlinux
sudo su cat << EOF > /mnt/manjarosd/boot/extlinux/extlinux.conf #/boot/extlinux/extlinux.conf MENU TITLE Pinephone Pro Boot Menu LABEL l0 MENU LABEL MANJARO FDT /boot/dtbs/rockchip/rk3399-pinephone-pro.dtb KERNEL /boot/Image INITRD /boot/initramfs-linux.img APPEND root=PARTLABEL=MANJARO console=ttyS2,115200 console=tty0 loglevel=4 rw rootwait EOF
Copy Files for Mobian
As for previous step proceed for next partition.
dd if=/dev/loop1p2 of=/dev/sdb4 bs=1M status=progress conv=fsync mount /dev/sdb4 /media/xxx/rootfs1/ scp -r /media/xxx/boot/* /media/xxx/rootfs1/boot nano /media/xxx/rootfs1/etc/fstab # replace UUID=xxx with PARTLABEL=MOBIAN and delete UUID=xxx from second line. Delete /boot line cat << EOF > /media/xxx/rootfs1/boot/extlinux/extlinux.conf #/boot/extlinux/extlinux.conf default l0 menu title Pinephone Pro Boot Menu prompt 0 timeout 10 label l0 menu label Mobian 63 linux /boot/vmlinuz-6.3-rockchip initrd /boot/initrd.img-6.3-rockchip fdtdir /usr/lib/linux-image-6.3-rockchip/ append root=PARTLABEL=MOBIAN console=ttyS2,115200 console=tty0 loglevel=4 rw rootwait label l1 menu label Mobian 61 linux /boot/vmlinuz-6.1-rockchip initrd /boot/initrd.img-6.1-rockchip fdtdir /usr/lib/linux-image-6.1-rockchip/ append root=PARTLABEL=MOBIAN console=ttyS2,115200 console=tty0 loglevel=4 rw rootwait EOF
Multi-Distro on eMMC
Make sure you boot from the microSD card in your PinePhone Pro as we are going to overwrite the eMMC. Note that below, Arch is booted from the microSD card and the microSD card is listed as the device /dev/mmcblk1.
Flash Rk2Aw Loader to SPI
Same as above. Note this installs rk2aw and a bootloader to SPI NOR flash. Resulting SPI status is as follows:
# ./rk2aw-spi-flasher Machine: Pine64 PinePhonePro (pine64,pinephone-pro) SPI NOR Flash: - Total size: 16384 KiB - Erase block size: 4 KiB - Write size: 1 - Manufacturer: gigadevice - Part name: gd25lq128e - JEDEC ID: 257018
Bootable images currently present in SPI NOR flash: Idx Header Off 1 Size 1 Off 2 Size 2 Notes/content ------------------------------------------------------------------------------- 0 0 2048 6144 0 0 (padded) 0='rk2aw' 5 131072 133120 67584 200704 124928 0='U-Boot TPL' 1='U-Boot SPL' 7 524288 526336 147456 673792 124928 0='ddrbin' 1='U-Boot SPL'
Auto-calculated layout for rk2aw dual bootloader scheme: Area Offset Size --------------------------------------------------- rk2aw primary 0 65536 rk2aw backup 65536 65536 spl fallback 131072 393216 spl primary 524288 389120 itb fallback 913408 2097152 itb primary 3010560 2097152
Build Multi-Distro eMMC
In this example we are going to build 2 partitions on the eMMC, the first with Arch/Phosh and the second with Arch/sxmo. We have already downloaded the images from Danct12 and decompressed them.
Mount the Images
cd ~/Downloads # enter to directory sudo su # login with your psw losetup -P /dev/loop0 archlinux-pinephone-pro-phosh-20230203.img losetup -P /dev/loop1 archlinux-pinephone-pro-sxmo-20230203.img ls -l /mnt/ mkdir /mnt/phosh mkdir /mnt/sxmo mkdir /mnt/phosh/boot mkdir /mnt/phosh/root mkdir /mnt/sxmo/boot mkdir /mnt/sxmo/root mkdir /mnt/ephosh # e for the partition on the eMMC mkdir /mnt/esxmo # e for the partition on the eMMC mount /dev/loop0p1 /mnt/phosh/boot/ mount /dev/loop0p2 /mnt/phosh/root/ mount /dev/loop1p1 /mnt/sxmo/boot/ mount /dev/loop1p2 /mnt/sxmo/root/
lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 5G 0 loop ├─loop0p1 259:0 0 122M 0 part /mnt/phosh/boot └─loop0p2 259:1 0 4.9G 0 part /mnt/phosh/root loop1 7:1 0 3.5G 0 loop ├─loop1p1 259:2 0 122M 0 part /mnt/sxmo/boot └─loop1p2 259:3 0 3.4G 0 part /mnt/sxmo/root mmcblk2 179:0 0 115.2G 0 disk ├─mmcblk2p1 179:1 0 122M 0 part └─mmcblk2p2 179:2 0 115.1G 0 part mmcblk2boot0 179:32 0 4M 1 disk mmcblk2boot1 179:64 0 4M 1 disk mmcblk1 179:96 0 59.6G 0 disk ├─mmcblk1p1 179:97 0 122M 0 part /boot └─mmcblk1p2 179:98 0 59.5G 0 part / zram0 254:0 0 1.5G 0 disk [SWAP]
Prepare eMMC
dd if=/dev/zero of=/dev/mmcblk2 count=32768 bs=32768 status=progress # overwrite the front to clear any bootloaders
sfdisk /dev/mmcblk2 << EOF label: gpt first-lba: 64 table-length: 8 size=32G, name="PHOSH", attrs="RequiredPartition,LegacyBIOSBootable" size=+, name="SXMO", attrs="RequiredPartition,LegacyBIOSBootable" EOF
Checking that no-one is using this disk right now ... OK Disk /dev/mmcblk2: 115.23 GiB, 123731968000 bytes, 241664000 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes >>> Script header accepted. >>> Created a new GPT disklabel (GUID: 7EB4B1E0-5F49-4F30-9F1E-E9E1F305D461). The maximal number of partitions is 8 (default is 128). /dev/mmcblk2p1: Created a new partition 1 of type 'Linux filesystem' and of size 32 GiB. /dev/mmcblk2p2: Created a new partition 2 of type 'Linux filesystem' and of size 83.2 GiB. /dev/mmcblk2p3: Done.
New situation: Disklabel type: gpt Disk identifier: 7EB4B1E0-5F49-4F30-9F1E-E9E1F305D461 Device Start End Sectors Size Type /dev/mmcblk2p1 2048 67110911 67108864 32G Linux filesystem /dev/mmcblk2p2 67110912 241661951 174551040 83.2G Linux filesystem The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 5G 0 loop ├─loop0p1 259:0 0 122M 0 part /mnt/phosh/boot └─loop0p2 259:1 0 4.9G 0 part /mnt/phosh/root loop1 7:1 0 3.5G 0 loop ├─loop1p1 259:2 0 122M 0 part /mnt/sxmo/boot └─loop1p2 259:3 0 3.4G 0 part /mnt/sxmo/root mmcblk2 179:0 0 115.2G 0 disk ├─mmcblk2p1 179:1 0 32G 0 part └─mmcblk2p2 179:2 0 83.2G 0 part mmcblk2boot0 179:32 0 4M 1 disk mmcblk2boot1 179:64 0 4M 1 disk mmcblk1 179:96 0 59.6G 0 disk ├─mmcblk1p1 179:97 0 122M 0 part /boot └─mmcblk1p2 179:98 0 59.5G 0 part / zram0 254:0 0 1.5G 0 disk [SWAP]
Build Phosh Partition
dd if=/dev/loop0p2 of=/dev/mmcblk2p1 bs=1M status=progress conv=fsync mount /dev/mmcblk2p1 /mnt/ephosh/ scp -r /mnt/phosh/boot/* /mnt/ephosh/boot mv /mnt/ephosh/boot/boot.scr /mnt/ephosh/boot/boot.scrORIG cat << EOF > /mnt/ephosh/etc/fstab #/boot/extlinux/extlinux.conf #Static information about the filesystems. #See fstab(5) for details. #<file system> <dir> <type> <options> <dump> <pass> PARTLABEL=PHOSH / ext4 rw,relatime 0 1 # UUID=52CA-6165 /boot vf rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2 mkdir /mnt/ephosh/boot/extlinux cat << EOF > /mnt/ephosh/boot/extlinux/extlinux.conf #/boot/extlinux/extlinux.conf MENU TITLE Pinephone Pro Boot Menu LABEL l0 MENU LABEL phosh FDT /boot/dtbs/rockchip/rk3399-pinephone-pro.dtb KERNEL /boot/Image INITRD /boot/initramfs-linux.img APPEND root=PARTLABEL=PHOSH console=ttyS2,115200 console=tty0 loglevel=4 rw rootwait EOF
Build SXMO Partition
We have unmounted all the Phosh devices, so
lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 5G 0 loop ├─loop0p1 259:0 0 122M 0 part └─loop0p2 259:1 0 4.9G 0 part loop1 7:1 0 3.5G 0 loop ├─loop1p1 259:2 0 122M 0 part /mnt/sxmo/boot └─loop1p2 259:3 0 3.4G 0 part /mnt/sxmo/root mmcblk2 179:0 0 115.2G 0 disk ├─mmcblk2p1 179:1 0 32G 0 part └─mmcblk2p2 179:2 0 83.2G 0 part mmcblk2boot0 179:32 0 4M 1 disk mmcblk2boot1 179:64 0 4M 1 disk mmcblk1 179:96 0 59.6G 0 disk ├─mmcblk1p1 179:97 0 122M 0 part /boot └─mmcblk1p2 179:98 0 59.5G 0 part / zram0 254:0 0 1.5G 0 disk [SWAP] dd if=/dev/loop1p2 of=/dev/mmcblk2p2 bs=1M status=progress conv=fsync mount /dev/mmcblk2p2 /mnt/esxmo/ scp -r /mnt/sxmo/boot/* /mnt/esxmo/boot mv /mnt/esxmo/boot/boot.scr /mnt/esxmo/boot/boot.scrORIG cat << EOF > /mnt/esxmo/etc/fstab # Static information about the filesystems. # See fstab(5) for details. # <file system> <dir> <type> <options> <dump> <pass> PARTLABEL=SXMO / ext4 rw,relatime 0 1 # UUID=841C-F9DD /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2 EOF mkdir /mnt/esxmo/boot/extlinux cat << EOF > /mnt/esxmo/boot/extlinux/extlinux.conf #/boot/extlinux/extlinux.conf MENU TITLE Pinephone Pro Boot Menu LABEL l0 MENU LABEL sxmo FDT /boot/dtbs/rockchip/rk3399-pinephone-pro.dtb KERNEL /boot/Image INITRD /boot/initramfs-linux.img APPEND root=PARTLABEL=SXMO console=ttyS2,115200 console=tty0 loglevel=4 rw rootwait EOF
Follow-Up Comments
- On first boot neither Phosh nor sxmo resized their partition - sudo resize2fs sorted that.
- Any time an update rebuilds the initramfs it is necessary to delete /boot/boot.scr again to keep the rk2aw menu clean.