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

Add new comment