sunnuntai 13. syyskuuta 2015

Creating a new btrfs for the jolla phone

Okay so this is just a mind dump in case i need to do this later. I wiped my factory setup when doing this. Be warned, No warranty.

I assume you 1. have a backup of atleast the files you want your jolla btrfs to have (i had a clone of the emmc) and 2. the btrfs on the jolla is borked.

Making a blank btrfs image (because no mkfs.btrfs in the recovery mode):
1. sparse file: (if you plan on loop mounting this dont do sparse)
dd if=/dev/zero bs=1k count=0 seek=14415855 of=blank-btrfs.bin
2. make a btrfs on it with no extensions (jolla: old kernel)
mkfs.btrfs -L sailfish -O ^extref,^skinny-metadata blank-btrfs.bin
2.5. note the UUID in the output
3. make a tiny file out of it (2x gzip because gzip isnt _that_ good at compressing zeroes... result:40k)
gzip -9 blank-btrfs.bin
gzip -9 < blank-btrfs.bin.gz > blank-btrfs.bin.gz.gz

Write the blank btrfs image to the jolla:
1. boot in recovery mode and telnet there and open the shell (4)
on the jolla:
nc -l -p 1234 | gunzip | gunzip | dd of=/dev/mmcblk0p28 bs=16k
on the pc:
nc -c 10.42.66.66 1234 < blank-btrfs.bin.gz.gz

Mount the blank btrfs image on the jolla
mount -o subvolid=0 /dev/mmcblk0p28 /mnt
cd /mnt
Create the @ and @home (and @swap but i think thats unused) subvolumes on the jolla
btrfs subvolume create @
btrfs subvolume create @home
btrfs subvolume create @swap # just to copy what i had on the jolla

Mount the backup btrfs on the PC with -o subvolid=0 or have identical file tree somewhere, example:
losetup -P -f mmc.bin
mount -o subvolid=0,ro /dev/loop?p28 mount-point

Copy the files from the PC to the new jolla fs - on the jolla:
nc -l -p 1234 | tar xz
On the pc:
cd mount-point
tar -cz @ @home | nc -c 10.42.66.66 1234

This will take a while - you can take a second telnet connection to the jolla to look at df -h to see how much has been written etc

When this has been done, on the jolla, we need to fix the fstab since the new btrfs has a new UUID (you noted that above, did you. worry not, btrfs filesystem show -d or -m does show the fs with uuid)
On the jolla:
vi @/etc/fstab
and modify the two lines with UUID= to have the new UUID

Then we need to finish up the btrfs setup and make the phone behave as if the new filesystem is the factory filesystem (kernel etc stuff i dont know that much of yet.) - on the jolla:

btrfs subvolume snapshot @ factory-@
btrfs subvolume snapshot @home factory-@home
btrfs subvolume list # note ID for the @ subvolume
btrfs subvolume set-default <ID-OF-@> .

cd ..
umount mnt
Then return to the menu (reboot to recovery or exit, i cant remember) and use the factory reset option and the recovery shell will do some magic to make sure you have the correct stuff elsewhere.

Then the phone will reboot and it should work. If it doesnt you can try to debug
by booting back to the shell, mounting the fs, and setting
@/etc/systemd/journald.conf Storage=persistent
and trying to boot again (preferably try to turn it off with power button after giving it a moment)
and returning to recovery shell and chroot:ing to the @ subvolume and using journalctl
to read the logs recorded.

Ei kommentteja:

Lähetä kommentti