Shrink /home/ on Sailfish OS

Table of Contents

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/.

NOTE: at the end of this post you will fine the same procedure in short form as run on my SONY Xperia X F5121 that’s also running SFOS.

Shrink overly large /home on Gemini

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. You’ll have to drop in your ssh pubkey. If you do not know how to do that, then you should not attempt this dangerous procedure.

user@workstation ~ $ ssh root@gemini
[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% /

on the SONY Xperia X F5121

user@workstation ~ $ ssh root@sailfishx
[...]
[root@Sailfish ~]# df -h -x tmpfs -x devtmpfs
Filesystem            Size  Used Avail Use% Mounted on
rootfs                2.4G  1.5G  891M  63% /
/dev/sailfish/root    2.4G  1.5G  891M  63% /
/dev/sailfish/home     18G  695M   18G   4% /home
/dev/mmcblk0p13        12M  3.7M  7.8M  32% /dsp
/dev/mmcblk0p28       376M  165M  204M  45% /odm
/dev/mmcblk0p25        28M  244K   27M   1% /persist
/dev/mmcblk0p52       596M  590M     0 100% /fimage
/dev/mmcblk0p3         84M   62M   23M  74% /firmware
/dev/sailfish/home     18G  695M   18G   4% /opt/alien/data
/dev/sailfish/root    2.4G  1.5G  891M  63% /opt/alien/bin
/dev/sailfish/root    2.4G  1.5G  891M  63% /opt/alien/sbin
/dev/sailfish/root    2.4G  1.5G  891M  63% /opt/alien/lib
/dev/sailfish/root    2.4G  1.5G  891M  63% /opt/alien/usr
/dev/sailfish/root    2.4G  1.5G  891M  63% /opt/alien/var
/dev/sailfish/root    2.4G  1.5G  891M  63% /opt/alien/etc
/dev/sailfish/home     18G  695M   18G   4% /opt/alien/home
/dev/sailfish/root    2.4G  1.5G  891M  63% /opt/alien/media
/dev/sailfish/root    2.4G  1.5G  891M  63% /opt/alien/vendor
/dev/mmcblk0p28       376M  165M  204M  45% /opt/alien/odm
/dev/sailfish/root    2.4G  1.5G  891M  63% /opt/alien/system_jolla
/dev/sailfish/root    2.4G  1.5G  891M  63% /opt/alien/data_jolla
/dev/fuse              18G  695M   18G   4% /opt/alien/storage/sdcard0
[root@Sailfish ~]# systemctl stop user@100000.service
[root@Sailfish ~]# pvs
  /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
  PV              VG       Fmt  Attr PSize   PFree
  /dev/mmcblk0p51 sailfish lvm2 a--  <20.70g    0 
[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---- 18.25g                                                    
  root sailfish -wi-ao----  2.44g                                                    
[root@Sailfish ~]# df -h /home/
Filesystem            Size  Used Avail Use% Mounted on
/dev/sailfish/home     18G  695M   18G   4% /home
[root@Sailfish ~]# umount /opt/alien/data
[root@Sailfish ~]# umount /opt/alien/home
[root@Sailfish ~]# umount /home
[root@Sailfish ~]# df -h|grep home
[root@Sailfish ~]# lvresize -L 6G --resizefs --autobackup y sailfish/home
  /dev/mmcblk0rpmb: read failed after 0 of 4096 at 0: Input/output error
fsck from util-linux 2.31
home: clean, 11383/1077216 files, 249653/4785152 blocks
resize2fs 1.43.1 (08-Jun-2016)
Resizing the filesystem on /dev/mapper/sailfish-home to 1572864 (4k) blocks.
The filesystem on /dev/mapper/sailfish-home is now 1572864 (4k) blocks long.

  Size of logical volume sailfish/home changed from 18.25 GiB (4673 extents) to 6.00 GiB (1536 extents).
  Logical volume sailfish/home successfully resized.
[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- <20.70g 12.25g
[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 ~]# systemctl reboot
pcfe@karhu ~ $ ssh root@sailfishx
[...]
[root@Sailfish ~]# df -h -x tmpfs -x devtmpfs
Filesystem            Size  Used Avail Use% Mounted on
rootfs                3.4G  1.5G  1.9G  45% /
/dev/sailfish/root    3.4G  1.5G  1.9G  45% /
/dev/sailfish/home    6.0G  696M  5.2G  12% /home
/dev/mmcblk0p3         84M   62M   23M  74% /firmware
/dev/mmcblk0p28       376M  165M  204M  45% /odm
/dev/mmcblk0p13        12M  3.7M  7.8M  32% /dsp
/dev/mmcblk0p25        28M  244K   27M   1% /persist
/dev/mmcblk0p52       596M  590M     0 100% /fimage
/dev/sailfish/home    6.0G  696M  5.2G  12% /opt/alien/data
/dev/sailfish/root    3.4G  1.5G  1.9G  45% /opt/alien/bin
/dev/sailfish/root    3.4G  1.5G  1.9G  45% /opt/alien/sbin
/dev/sailfish/root    3.4G  1.5G  1.9G  45% /opt/alien/lib
/dev/sailfish/root    3.4G  1.5G  1.9G  45% /opt/alien/usr
/dev/sailfish/root    3.4G  1.5G  1.9G  45% /opt/alien/var
/dev/sailfish/root    3.4G  1.5G  1.9G  45% /opt/alien/etc
/dev/sailfish/home    6.0G  696M  5.2G  12% /opt/alien/home
/dev/sailfish/root    3.4G  1.5G  1.9G  45% /opt/alien/media
/dev/sailfish/root    3.4G  1.5G  1.9G  45% /opt/alien/vendor
/dev/mmcblk0p28       376M  165M  204M  45% /opt/alien/odm
/dev/sailfish/root    3.4G  1.5G  1.9G  45% /opt/alien/system_jolla
/dev/sailfish/root    3.4G  1.5G  1.9G  45% /opt/alien/data_jolla
/dev/fuse             6.0G  696M  5.2G  12% /opt/alien/storage/sdcard0
[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- <20.70g 11.25g