xt894 and xt912: Safestrap 3.75 for the unused partitions /preinstall & /webtop

The Motorola Droid 4 xt894 and the Motorola Droid Razr xt912 have a lot of memory space unused splitted in two partitions:

  • /preinstall : 600 Mb
  • /webtop : 1,4 Gb

/preinstall is the partition where are stored the preinstalled apps and /webtop is an abandoned partition that under Gingerbread was used for the webtop but since ICS has been abandoned.

Safestrap is a great recovery for devices with a locked bootloader that uses the kexec for load a kernel and that can install a rom replacing the stock rom or in one of the four virtual slots that can be created in the internal memory. The use of the virtual slots is a great mode to untach the main system and to avoid to brick the phone but the virtual slots are slower than the real partitions of the main system,  they can't be trimmed and they take important space.

This version of SafeStrap is based on SafeStrap 3.75 but has a lot of differences with it:

  • there is not more the splashscreen during the boot, to enter in Safestrap you have to select BP Tools in the Boot Mode Selection Menu(VolUp&&VolDown+PowerOn)
  • has been added a Safe Rom slot that uses the unused partitions:
    • /preinstall for /system
    • /webtop for /data
    • /cache is shared with the Stock Rom slot
  • in this version you have 6 slots: the Stock Rom slot, the Safe Rom slot and the four virtual slots
  • the Safe Rom slot is faster than any virtual slot and safer than the Stock Rom slot

If you are using the original Safestrap you can simply install this new version over it and you will still have your roms in the virtual slots.
This version of Safestrap works like any other version of Safestrap and you can use the Stock Rom slot and the four virtual slots as you are usually do, the only thing that is a bit complicated is to install an aosp rom in the new Safe Rom slot that i provided in it.

 

How to use the Safe Rom slot with an AOSP rom:

Unfortunately the aosp roms available for the droid 4 and for the droid razr are hardcoded on the safestrap's virtual slots and on the Stock Rom slot and this causes a bootloop on a black screen after the standard kexec vibration with these roms in the new Safe Rom slot.
The problem is in the roms' ramdisks and precisely in their fixboot.sh.
In the roms for SafeStrap the ramdisk is located at the path /system/etc/kexec/ramdisk.img and in the ramdisk.img there is the /sbin/fixboot.sh that only boots the rom from the Stock Rom slot or from a virtual slot so we have to edit the fixboot.sh to boot a rom also from the new Safe Rom slot.
Following are the original fixboot.sh from the cm11, cm12, cm13 and their possible revisions to support the Safe Rom slot.
 
Original fixboot.sh from cm11:
#!/sbin/bbx sh

# remount root as rw
/sbin/bbx mount -o remount,rw rootfs
/sbin/bbx mkdir /ss
/sbin/bbx chmod 777 /ss

# mount safestrap partition
/sbin/bbx mount -t vfat -o uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020 /dev/block/emstorage /ss

SLOT_LOC=$(/sbin/bbx cat /ss/safestrap/active_slot)

if [ "$SLOT_LOC" != "stock" ]; then
# create SS loopdevs
/sbin/bbx mknod -m600 /dev/block/loop-system b 7 99
/sbin/bbx mknod -m600 /dev/block/loop-userdata b 7 98
/sbin/bbx mknod -m600 /dev/block/loop-cache b 7 97

# setup loopbacks
/sbin/bbx losetup /dev/block/loop-system /ss/safestrap/$SLOT_LOC/system.img
/sbin/bbx losetup /dev/block/loop-userdata /ss/safestrap/$SLOT_LOC/userdata.img
/sbin/bbx losetup /dev/block/loop-cache /ss/safestrap/$SLOT_LOC/cache.img

# move real partitions out of the way
/sbin/bbx mv /dev/block/system /dev/block/systemorig
/sbin/bbx mv /dev/block/userdata /dev/block/userdataorig
/sbin/bbx mv /dev/block/cache /dev/block/cacheorig

# change symlinks
/sbin/bbx ln -s /dev/block/preinstall /dev/block/system
/sbin/bbx ln -s /dev/block/webtop /dev/block/userdata
/sbin/bbx ln -s /dev/block/loop-cache /dev/block/cache
else
/sbin/bbx umount /ss
fi

/sbin/bbx touch /.safestrapped
Edited fixboot.sh for cm11:
#!/sbin/bbx sh

# remount root as rw
/sbin/bbx mount -o remount,rw rootfs
/sbin/bbx mkdir /ss
/sbin/bbx chmod 777 /ss

# mount safestrap partition
/sbin/bbx mount -t vfat -o uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020 /dev/block/emstorage /ss

SLOT_LOC=$(/sbin/bbx cat /ss/safestrap/active_slot)

if [ "$SLOT_LOC" = "stock" ]; then
/sbin/bbx umount /ss
elif [ "$SLOT_LOC" = "safe" ]; then
/sbin/bbx mv /dev/block/system /dev/block/systemorig
/sbin/bbx mv /dev/block/userdata /dev/block/userdataorig

/sbin/bbx ln -s /dev/block/preinstall /dev/block/system
/sbin/bbx ln -s /dev/block/webtop /dev/block/userdata

/sbin/bbx umount /ss
else
# create SS loopdevs
/sbin/bbx mknod -m600 /dev/block/loop-system b 7 99
/sbin/bbx mknod -m600 /dev/block/loop-userdata b 7 98
/sbin/bbx mknod -m600 /dev/block/loop-cache b 7 97

# setup loopbacks
/sbin/bbx losetup /dev/block/loop-system /ss/safestrap/$SLOT_LOC/system.img
/sbin/bbx losetup /dev/block/loop-userdata /ss/safestrap/$SLOT_LOC/userdata.img
/sbin/bbx losetup /dev/block/loop-cache /ss/safestrap/$SLOT_LOC/cache.img

# move real partitions out of the way
/sbin/bbx mv /dev/block/system /dev/block/systemorig
/sbin/bbx mv /dev/block/userdata /dev/block/userdataorig
/sbin/bbx mv /dev/block/cache /dev/block/cacheorig

# change symlinks
/sbin/bbx ln -s /dev/block/loop-system /dev/block/system
/sbin/bbx ln -s /dev/block/loop-userdata /dev/block/userdata
/sbin/bbx ln -s /dev/block/loop-cache /dev/block/cache
fi

/sbin/bbx touch /.safestrapped
 
Original fixboot.sh from cm12:
#!/sbin/bbx sh

exec 1<&-
exec 2<&-
exec 1<>/dev/kmsg
exec 2>&1

# remount root as rw
/sbin/bbx mount -o remount,rw rootfs
/sbin/bbx mkdir /ss
/sbin/bbx chmod 777 /ss

# mount safestrap partition
/sbin/bbx mount -t vfat -o uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020 /dev/block/emstorage /ss

SLOT_LOC=$(/sbin/bbx cat /ss/safestrap/active_slot)

if [ "$SLOT_LOC" != "stock" ]; then
# create SS loopdevs
/sbin/bbx mknod -m600 /dev/block/loop-system b 7 99
/sbin/bbx mknod -m600 /dev/block/loop-userdata b 7 98
/sbin/bbx mknod -m600 /dev/block/loop-cache b 7 97

# setup loopbacks
/sbin/bbx losetup /dev/block/loop-system /ss/safestrap/$SLOT_LOC/system.img
/sbin/bbx losetup /dev/block/loop-userdata /ss/safestrap/$SLOT_LOC/userdata.img
/sbin/bbx losetup /dev/block/loop-cache /ss/safestrap/$SLOT_LOC/cache.img

# move real partitions out of the way
/sbin/bbx mv /dev/block/system /dev/block/systemorig
/sbin/bbx mv /dev/block/userdata /dev/block/userdataorig
/sbin/bbx mv /dev/block/cache /dev/block/cacheorig

# change symlinks
/sbin/bbx ln -s /dev/block/preinstall /dev/block/system
/sbin/bbx ln -s /dev/block/webtop /dev/block/userdata
/sbin/bbx ln -s /dev/block/loop-cache /dev/block/cache
else
/sbin/bbx umount /ss
fi
Edited fixboot.sh for cm12:
#!/sbin/bbx sh

exec 1<&-
exec 2<&-
exec 1<>/dev/kmsg
exec 2>&1

# remount root as rw
/sbin/bbx mount -o remount,rw rootfs
/sbin/bbx mkdir /ss
/sbin/bbx chmod 777 /ss

# mount safestrap partition
/sbin/bbx mount -t vfat -o uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020 /dev/block/emstorage /ss

SLOT_LOC=$(/sbin/bbx cat /ss/safestrap/active_slot)

if [ "$SLOT_LOC" = "stock" ]; then
/sbin/bbx umount /ss
elif [ "$SLOT_LOC" = "safe" ]; then
/sbin/bbx mv /dev/block/system /dev/block/systemorig
/sbin/bbx mv /dev/block/userdata /dev/block/userdataorig

/sbin/bbx ln -s /dev/block/preinstall /dev/block/system
/sbin/bbx ln -s /dev/block/webtop /dev/block/userdata

/sbin/bbx umount /ss
else
# create SS loopdevs
/sbin/bbx mknod -m600 /dev/block/loop-system b 7 99
/sbin/bbx mknod -m600 /dev/block/loop-userdata b 7 98
/sbin/bbx mknod -m600 /dev/block/loop-cache b 7 97

# setup loopbacks
/sbin/bbx losetup /dev/block/loop-system /ss/safestrap/$SLOT_LOC/system.img
/sbin/bbx losetup /dev/block/loop-userdata /ss/safestrap/$SLOT_LOC/userdata.img
/sbin/bbx losetup /dev/block/loop-cache /ss/safestrap/$SLOT_LOC/cache.img

# move real partitions out of the way
/sbin/bbx mv /dev/block/system /dev/block/systemorig
/sbin/bbx mv /dev/block/userdata /dev/block/userdataorig
/sbin/bbx mv /dev/block/cache /dev/block/cacheorig

# change symlinks
/sbin/bbx ln -s /dev/block/loop-system /dev/block/system
/sbin/bbx ln -s /dev/block/loop-userdata /dev/block/userdata
/sbin/bbx ln -s /dev/block/loop-cache /dev/block/cache
fi
 
Original fixboot.sh from cm13:
#!/sbin/bbx sh

exec 1<&-
exec 2<&-
exec 1<>/dev/kmsg
exec 2>&1

# mount safestrap partition
/sbin/bbx mount -t vfat -o uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020 /dev/block/emstorage /ss

SLOT_LOC=$(/sbin/bbx cat /ss/safestrap/active_slot)

if [ "$SLOT_LOC" != "stock" ]; then
# setup loopbacks
/sbin/bbx losetup /dev/block/loop-system /ss/safestrap/$SLOT_LOC/system.img
/sbin/bbx losetup /dev/block/loop-userdata /ss/safestrap/$SLOT_LOC/userdata.img
/sbin/bbx losetup /dev/block/loop-cache /ss/safestrap/$SLOT_LOC/cache.img

# move real partitions out of the way
/sbin/bbx mv /dev/block/system /dev/block/systemorig
/sbin/bbx mv /dev/block/userdata /dev/block/userdataorig
/sbin/bbx mv /dev/block/cache /dev/block/cacheorig

# change symlinks
/sbin/bbx ln -s /dev/block/loop-system /dev/block/system
/sbin/bbx ln -s /dev/block/loop-userdata /dev/block/userdata
/sbin/bbx ln -s /dev/block/loop-cache /dev/block/cache
else
/sbin/bbx umount /ss
fi
Edited fixboot.sh for cm13:
#!/sbin/bbx sh

exec 1<&-
exec 2<&-
exec 1<>/dev/kmsg
exec 2>&1

# mount safestrap partition
/sbin/bbx mount -t vfat -o uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020 /dev/block/emstorage /ss

SLOT_LOC=$(/sbin/bbx cat /ss/safestrap/active_slot)

if [ "$SLOT_LOC" = "stock" ]; then
/sbin/bbx umount /ss
elif [ "$SLOT_LOC" = "safe" ]; then
/sbin/bbx mv /dev/block/system /dev/block/systemorig
/sbin/bbx mv /dev/block/userdata /dev/block/userdataorig

/sbin/bbx ln -s /dev/block/preinstall /dev/block/system
/sbin/bbx ln -s /dev/block/webtop /dev/block/userdata

/sbin/bbx umount /ss
else
# setup loopbacks
/sbin/bbx losetup /dev/block/loop-system /ss/safestrap/$SLOT_LOC/system.img
/sbin/bbx losetup /dev/block/loop-userdata /ss/safestrap/$SLOT_LOC/userdata.img
/sbin/bbx losetup /dev/block/loop-cache /ss/safestrap/$SLOT_LOC/cache.img

# move real partitions out of the way
/sbin/bbx mv /dev/block/system /dev/block/systemorig
/sbin/bbx mv /dev/block/userdata /dev/block/userdataorig
/sbin/bbx mv /dev/block/cache /dev/block/cacheorig

# change symlinks
/sbin/bbx ln -s /dev/block/loop-system /dev/block/system
/sbin/bbx ln -s /dev/block/loop-userdata /dev/block/userdata
/sbin/bbx ln -s /dev/block/loop-cache /dev/block/cache
fi
 
Obviously the roms built in this way will be compatible with every older version of Safestrap and with my new version.
Anyone can build by itself a ramdisk to use a rom in the Safe Rom slot with these passages as superuser:
1) unpacking the ramdisk.img with this command:
gzip -dc ../ramdisk.img | cpio -i
2) editing the file fixboot.sh
3) repacking the new ramdisk.img with this command:
find . | cpio -o -H newc | gzip > ../ramdisk.img
From the cm12 in the ramdisk.img there is also the file safestrapped.cpio before the real ramdisk so you have to split them with an hex editor (1F 8B 08) then you can extract the ramdisk, edit it, repack it and finally recreate the ramdisk.img reconcatenating with the hex editor the file safestrapped.cpio with the edited ramdisk.
The /webtop, the partition that i used for /data in my Safe Rom slot, is originally formatted as ext4 and this can cause some problem with some rom or kernel.
In case after the first boot you have the Encryption Unsuccessful message you have simple to format /data in the Safe Rom slot with a different file system. For example installing the stock rom in the Safe Rom slot you will not have any problem with the ext4 fs but installing the cm11 you have to re-format /data as ext3 otherwise you will have the Encryption Unsuccessful message.

In case Safestrap is showing 0 MB in System (or Data) in the Safe Rom slot you can try to solve the problem in this way:
  • enter in safestrap
  • enable the Safe Rom slot
  • from the wipe menu: Advanced wipe -> ✓System (or ✓Data) -> Repair or Change File System -> Repair
The only problem present in this recovery is the same problem present in the standard SafeStrap: if you create a new virtual slot and then you try to switch on the Stock Rom slot (and in this version on the Safe Rom slot) you will not be able to mount the phisical partitions but if you restart the recovery after creating the new virtual slot you will not have any problem.
Section: 

Comments

2 comments

I will reply myself after lot of experiment
As I did not know what have happened with my droid - second hand buy - I got it already with 4.1.2 Verizon stock and at the begining I was doing a lot of experiments with flashing, I decided go back . I took the rom VRZ_T894_6.5.1-16~219_1FF_01.xml.zip and tried to flash it using RSD Lite for linux - it required the linux-mfastboot which support some multi-part flashing - otherwise it was limited to 1GB . Even if the flashing failed for some partitions (probably bad enciphering key used) It flashed the webtop content and preloaded OK. Than I could reflash the VRZ_XT894_9.8.2O-72_VZW-18-8_1FF.xml.zip
which worked OK even for system and directory structures (but apparently it does not touch the webtop )
So I have had correct partitions installed stock rom and used motofail to root it, installed safestrap 3.75 with modified partitions and finally I have had it exactly as described above.

I am very desperate trying to enable the safe rom on my XT894. I have been playing with my DROID for several years (started at Safestrap 3.65 on stock }, running several CM from 10 to 14.1 Lineage but when the SS fro unused partitions appeared I was never able to get tjis working - even the Stargo's version with boot menu - nor this from BP tools. Always wgen switching to the saferom (or alt slot webtop, preinstall) I see the size of system 0 kB. And install warns me theres no system. As I was using heavilly the other slots with multiple ROMS, I decided yesterday the ultimate solution. Full flash to the stock rom.
Using VRZ_XT894_9.8.2O-7~W-18-8_CFC.xml.zip I started from the scratch (RSDLite on Linux, Saferoot on linux) , install safestrap 3.75 for unused part, install it).
But still when switching to the saferom slot it shows 0 byte for system and system may not be mounted from ss menu. I suppose I have formatted almost all partitions (also data etc). The system in saferom should be on preinstall. But it was for sure flashed as well.
What should I check - how should I format preinstall to be recognized by safestrap . Should I flash with some older ROMS - say 2.3.6 ? May ther ebe some remnants of my experients still presents after flash stock ?

In all other slots I was able to do what I wanted including stock (I have it now on CM11 from April 2017)

BTW - how the flasher (fastboot) knows what partition is preinstall or what is system ? where is the mapping from /dev/block/mmcblk1pxx to those names fastboot uses ?
No clue in xml ..

Best regards

Petr

Add new comment