Data partition extension to end of sd card

Hi,

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

[Unit]
Description=Mount data partition mountpoint

[Mount]
What=/dev/disk/by-label/data
Where=/mnt/data
Type=ext4

[Install]
WantedBy=multi-user.target

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)

http://git.toradex.com/cgit/meta-toradex-bsp-common.git/tree/recipes-core/fs-init/files?h=rocko

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

https://tracker.mender.io/browse/MEN-2337

2 Likes

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

[Unit]
Description=Expand data filesystem
ConditionPathExists=/dev/mmcblk0p4

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/resize2fs /dev/mmcblk0p4

[Install]
WantedBy=multi-user.target
1 Like

@tuupola thanks for sharing :+1: and welcome