-
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/mmcblk0p9
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).
Unless you know what you're doing, you're basically stuck with my kernel. If you are a bit more tech-savvy, you can look into lvm.cpio.gz archive and include it with the kernel you want to use or reimplement it using init.d scripts - there's no magic in there actially. The LVM feature itsel is supported by any Android kernel, so it's only the scripts and the lvm binary you need to worry about.
I do not recommend converting anything other than /preload and /cache to lvm. Those two partitions are disposable, so even if anything goes wrong, not much is lost. While it is possible to move /system and /data to lvm as well, the list of potential problems grows much bigger than those mentioned above and the if something goes wrong, you'll loose all data that's on lvm.
You have been warned...
"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 too 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
If you also moved /system and/or /data (warned ya...), recreate ext4 there as well and optionally flash a new rom.
There's nothing we can do for the cat though... get another...
https://www.howtoforge.com/linux_lvm
Before anything else, read those and all the stuff those posts tell you to read:
http://forum.xda-developers.com/nexus-s/general/howto-combined-emulated-storage-nexus-s-t2848752
http://forum.xda-developers.com/nexus-s/general/howto-partitioning-nexus-s-using-lvm-t1656794
http://www.xda-developers.com/android/bypass-nexus-s-storage-restrictions/
Done? Great!
Now read them again...
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 4M vg00 /dev/block/mmcblk0p4 /dev/block/mmcblk0p9
Create logical volume for cache 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 100%FREE -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/vg00/cache
tune2fs -c 0 -i 0 -o nobarrier,discard /dev/vg00/cache
mount -t ext4 /dev/vg00/cache /cache
If you want /cache to occupy less than all available space, replace 100 with a smaller number, or replace entire -l 100%FREE
part with size specification similar to -L 400M
(for a 400MB volume) - mind the capital "L" instead of small "L".
And that's it - your /cache partition can now be up to 600M (or so...) in size. Read about lvm to know how to resize it. This kernel doesn't support ext4 online resize yet, so you need to umount /cache
before calling resize2fs.
Reboot.
Having an empty 600M partition is almost equally useless as having two empty 300M partitions, so let's make some use of it.
Ensure that target directory exists:
mkdir /cache/dalvik-cache
chown system.system /cache/dalvik-cache
chmod 771 /cache/dalvik-cache
Now append (at the end!) the following line to your /efs/common/overlay/fstab.samsungjanice:
/cache/dalvik-cache /data/dalvik-cache none bind defaults
And reboot - you should now see android rebuilding dalvik cache.
When system boots, type mount | grep dalvik
. You should see something similar to this:
/dev/vg00/cache /data/dalvik-cache ext4 rw,nosuid,nodev,noatime,user_xattr,barrier=1,journal_async_commit,stripe=1024,data=writeback,discard 0 0
But there's an old dalvik-cache directory which is now covered by bind, but it's still using space. To get to it, we do another bind (only now it'll be temporary):
mkdir -p /data/local/mnt
mount -o bind /data /data/local/mnt
cd /data/local/mnt/dalvik-cache
Once you verify that those two directories are different (do df .
in this and in /data/dalvik-cache - it should report different values), you can do
df /data
rm -f /data/local/mnt/dalvik-cache/*
umount /data/local/mnt/
df /data
~ # pvcreate /dev/block/mmcblk0p9
Physical volume "/dev/block/mmcblk0p9" successfully created
~ # vgcreate -s 4M 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/vg00/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.