Data partition extension to end of sd card


I would like to runtime extend data partition when board if first time booted. I have a case where SD cards have size 4 or 8GB. Mender image with app is ~2,5G and rest should be used for data. As I don’t want to extend size of sdimg (also not possible to have different SD card sizes). I was thinking about creating some systemd service which will do the trick but then realized that /data and /uboot are added to /etc/fstab and in this case systemd mount it. Was thinking about disabling autom ounting and add systemd mount scripts (based on label like e.g.)

Description=Mount data partition mountpoint



Then I can add dependent service file which will extend data partition to the end of sd card. Does anyone else have already some solution, ideas? Thanks.

1 Like

It should be pretty safe to do a resize while it is mounted as you are adding space and if you are using ext4 filesystem it supports “live resizing”.

Examples doing this (these are typically for root part but can be easily modified to resize data part)

We are also thinking about adding something to meta-mender to simplify this as it is a pretty common use-case,


I use this with Raspbian images created with mender-convert.

Description=Expand data filesystem

ExecStart=/sbin/resize2fs /dev/mmcblk0p4

1 Like

@tuupola thanks for sharing :+1: and welcome