-
Notifications
You must be signed in to change notification settings - Fork 3
Converting Cache and Preload to LVM
BEWARE! Here be dragons
LVM in terms of Android is an advanced feature. In terms of custom roms it's an advanced and potentially dangerous feature.
Regretably authors of custom roms, and especialy the ones adapting them to particular devices don't take into account that some might have a different vision of using or creating /preload and /cache partitions and they format or erase them happily without asking anyone's permission...
Because of the above before flashing any new rom you must carefull read it's updater script in search for surprises like mkfs.ext4 /dev/block/mmcblkp9
and correct/remove them before flashing it.
Of course immediately after flashing new rom you must flash this kernel (unless you modified its update script not to overwrite the kernel image). Otherwise the system won't see any LVM volumes after reboot.
For now LVM is not supported on anything other than KitKat (that is requiring boot.cpio.gz overlay to work).
HELP! I did as you said I should not do and it's not booting! And it ate my cat!!!
I can't help you fix it because there are many things that can go wrong (see warning above). But reverting all the changes is easy:
- Reboot into recovery (ignore any errors) and login with adb
- ensure that /efs is mounted by typing
mount
ordf
. if not, mount itmount -t ext4 /dev/block/mmcblk0p7 /efs
- Remove lvm.cpio.gz, fstab.lvm and fstab.samsungjanice
rm -f /efs/common/lvm.cpio.gz /efs/common/overlay/fstab.samsungjanice /efs/common/overlay/fstab.lvm
- Reboot into recovery once more (from advanced options)
- Recreate /cache filesystem
mkfs.ext4 /dev/block/mmcblk0p4
- Recreate /preload filesystem
mkfs.ext4 /dev/block/mmcblk0p9
There's nothing we can do for the cat though... get another...
You need to be using kernel 5.3.0 or higher
Download lvm.cpio.gz from MediaFire plugins folder and place it in /efs/common/
Copy /fstab.samsungjanice to /efs/common/overlay/ and edit it - comment out /preload and /cache lines
Create /efs/common/overlay/fstab.lvm with the following line (that's a long line - copy it!):
/dev/vg00/cache /cache ext4 noatime,nosuid,nodev,journal_async_commit,discard,data=writeback wait
Reboot into recovery. Recovery will complain about being unable to access /cache - that's ok.
Type mount
or df
and ensure that neither /preload or /cache are mounted
Remember to copy/paste all the commands to avoid typos
Create physical volumes
pvcreate /dev/block/mmcblk0p4
pvcreate /dev/block/mmcblk0p9
Create volume group
vgcreate -s 16M vg00 /dev/block/mmcblk0p4 /dev/block/mmcblk0p9
Create logical volume for cache (400M should be fine for a start) and ext4 filesystem on it (attention - lines below are long and don't wrap on github, but if you copy/paste them, you'll be fine)
lvcreate -L 400M -n cache vg00
mke2fs -t ext4 -L cache -i $((32*1024)) -b 4096 -E stride=1024,stripe_width=1024,resize=$((7500*1024/4)) -m 0 -O sparse_super,filetype,dir_index,ext_attr,has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize /dev/vg01/cache
tune2fs -c 0 -i 0 -o nobarrier,discard /dev/vg00/cache
~ # pvcreate /dev/block/mmcblk0p9
Physical volume "/dev/block/mmcblk0p9" successfully created
~ # vgcreate -s 16M vg00 /dev/block/mmcblk0p9
Volume group "vg00" successfully created
~ # mkdir /mnt/cache
~ # lvcreate -L 20M -n cache vg00
Rounding up size to full physical extent 32.00 MiB
Logical volume "cache" created
~ # cat /sys/block/mmcblk0/device/preferred_erase_size
4194304
~ # unzip /tmp/e2fsprogs-android-static-1.42.8-all.zip -d /tmp/
~ # mv /tmp/e2fsprogs-android-static-1.42.8/* /sbin/
~ # mke2fs -t ext4 -L cache -i $((32*1024)) -b 4096 -E stride=1024,stripe_width=1024,resize=$((7500*1024/4)) -m 0 -O sparse_super,filetype,dir_index,ext_attr,has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize /dev/vg01/cache
mke2fs 1.42.8 (20-Jun-2013)
Discarding device blocks: done
Filesystem label=cache
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=1024 blocks, Stripe width=1024 blocks
1024 inodes, 8192 blocks
0 blocks (0.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=8388608
1 block group
32768 blocks per group, 32768 fragments per group
1024 inodes per group
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
~ # tune2fs -c 0 -i 0 -o nobarrier,discard /dev/vg00/cache
tune2fs 1.42.8 (20-Jun-2013)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
~ # mount -t auto /dev/vg00/cache /mnt/cache/
~ # mount | grep cache
/dev/block/mmcblk0p4 on /cache type ext4 (rw,relatime,errors=panic,user_xattr,acl,barrier=1,journal_async_commit,data=ordered)
/dev/vg00/cache on /mnt/cache type ext4 (rw,relatime,user_xattr,acl,barrier=1,stripe=1024,data=ordered)
~ # find cache/ -depth -print | /system/xbin/cpio -vdp /mnt/cache/
~ # umount /cache
~ # mount /dev/vg00/cache /cache/
~ # mkdir /cache/dalvik-cache
~ # pvcreate /dev/block/mmcblk0p4
Physical volume "/dev/block/mmcblk0p4" successfully created
~ # vgextend vg00 /dev/block/mmcblk0p4
Volume group "vg00" successfully extended
~ # lvresize -L400M vg00/cache
Extending logical volume cache to 400.00 MiB
Logical volume cache successfully resized
~ # resize2fs -f /dev/vg00/cache
resize2fs 1.42.8 (20-Jun-2013)
Resizing the filesystem on /dev/vg00/cache to 102400 (4k) blocks.
The filesystem on /dev/vg00/cache is now 102400 blocks long.