Shrink /home/ on Sailfish OS

For some reason, Sailfish OS on a Gemini PDA has a very small / but an overly large /home/.

This post describes how to reclaim space from /home/.

Shrink overly large /home

Thanks to the power of LVM, this is a no brainer, just need to stop the user session.

To be able to stop said user session, ssh in directly as root.

user@workstation ~ $ ssh root@sailfishx
[root@Sailfish ~]# systemctl stop user@100000.service
[root@Sailfish ~]# lvresize -L 32G --resizefs --autobackup y sailfish/home
  /dev/mmcblk0rpmb: read failed after 0 of 4096 at 0: Input/output error
Do you want to unmount "/home" ? [Y|n] y
fsck from util-linux 2.31

home: 795/3528000 files (2.3% non-contiguous), 243792/14438400 blocks
resize2fs 1.43.1 (08-Jun-2016)
Resizing the filesystem on /dev/mapper/sailfish-home to 8388608 (4k) blocks.
The filesystem on /dev/mapper/sailfish-home is now 8388608 (4k) blocks long.

  Size of logical volume sailfish/home changed from <55.08 GiB (14100 extents) to 32.00 GiB (8192 extents).
  Logical volume sailfish/home successfully resized.

This gives you some 23 GiB to allocate later.

[root@Sailfish ~]# vgs
  /dev/mmcblk0rpmb: read failed after 0 of 4096 at 0: Input/output error
  VG       #PV #LV #SN Attr   VSize   VFree  
  sailfish   1   2   0 wz--n- <57.52g <23.08g

Since you killed the user session, either restart it or just reboot the phone. Since I wanted to verify that it comes up cleanly after the change, I just rebooted.

[root@Sailfish ~]# systemctl reboot

Grow Any Mounted Filesystem

Since your volume group (VG) now has free physical extends (PE), you can grow any logical volume (LV) and it’s filesystem at runtime with

[root@Sailfish ~]# lvextend -L +…G --resizefs <VG>/<LV>

Example

Here’s an example of on-line growing / by 1 GiB: (you can ignore the read errors as long as they are not on /dev/mmcblk0p29. Ideally, Jolla would blacklist mmcblk0rpmb)

[root@Sailfish ~]# vgs
  /dev/mmcblk0rpmb: read failed after 0 of 4096 at 0: Input/output error
  /dev/mmcblk0rpmb: read failed after 0 of 4096 at 4128768: Input/output error
  /dev/mmcblk0rpmb: read failed after 0 of 4096 at 4186112: Input/output error
  /dev/mmcblk0rpmb: read failed after 0 of 4096 at 4096: Input/output error
  VG       #PV #LV #SN Attr   VSize   VFree  
  sailfish   1   2   0 wz--n- <57.52g <23.08g
[root@Sailfish ~]# lvs
  /dev/mmcblk0rpmb: read failed after 0 of 4096 at 0: Input/output error
  LV   VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home sailfish -wi-ao---- 32.00g                                                    
  root sailfish -wi-ao----  2.44g                                                    
[root@Sailfish ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
rootfs                2.4G  1.3G  1.1G  56% /
/dev/sailfish/root    2.4G  1.3G  1.1G  56% /
/dev/sailfish/home     32G   57M   32G   1% /home
[...]
[root@Sailfish ~]# lvextend -L +1G --resizefs sailfish/root
  /dev/mmcblk0rpmb: read failed after 0 of 4096 at 0: Input/output error
  Size of logical volume sailfish/root changed from 2.44 GiB (625 extents) to 3.44 GiB (881 extents).
  Logical volume sailfish/root successfully resized.
resize2fs 1.43.1 (08-Jun-2016)
Filesystem at /dev/mapper/sailfish-root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/sailfish-root is now 902144 (4k) blocks long.

[root@Sailfish ~]# df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/sailfish/root    3.4G  1.3G  2.1G  39% /