From bdca1beefc8cc510c0252b657983302dad1033d9 Mon Sep 17 00:00:00 2001 From: Max Krummenacher Date: Mon, 24 Jun 2013 09:36:23 +0200 Subject: fs-init: add recipe to extend rootfs partition on eMMC - on Colbri/Apalis T30 the rootfs is downloaded in a minimum size. On first boot this filesystem is resized to fill its full partion. This slows down IO responsivness during the first 5 minutes. --- recipes-core/fs-init/files/COPYING | 5 +++ recipes-core/fs-init/files/resizefs.service | 9 ++++++ recipes-core/fs-init/files/resizefs.sh | 49 +++++++++++++++++++++++++++++ recipes-core/fs-init/fs-init.bb | 25 +++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 recipes-core/fs-init/files/COPYING create mode 100644 recipes-core/fs-init/files/resizefs.service create mode 100755 recipes-core/fs-init/files/resizefs.sh create mode 100644 recipes-core/fs-init/fs-init.bb (limited to 'recipes-core') diff --git a/recipes-core/fs-init/files/COPYING b/recipes-core/fs-init/files/COPYING new file mode 100644 index 0000000..040e990 --- /dev/null +++ b/recipes-core/fs-init/files/COPYING @@ -0,0 +1,5 @@ +This piece is software is provided by Toradex AG as sample code. +There is no warranty for the program. +Toradex AG put this program in public domain, uncopyrighted. + +Renens, Swizterland, 2008-10-23 diff --git a/recipes-core/fs-init/files/resizefs.service b/recipes-core/fs-init/files/resizefs.service new file mode 100644 index 0000000..7dbbb99 --- /dev/null +++ b/recipes-core/fs-init/files/resizefs.service @@ -0,0 +1,9 @@ +[Unit] +Description=start resize script to increase rootfs to its partitions full size + +[Service] +Type=simple +ExecStart=/bin/sh -c 'sleep 5 ; /usr/sbin/resizefs.sh' + +[Install] +WantedBy=graphical.target diff --git a/recipes-core/fs-init/files/resizefs.sh b/recipes-core/fs-init/files/resizefs.sh new file mode 100755 index 0000000..24ea1fd --- /dev/null +++ b/recipes-core/fs-init/files/resizefs.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# resize the rootfs ext filesystem size to its full partition size +# usually used on first boot in a postinstall script +# or set in an autostart file from a postinstall script + +DISK="mmcblk0" +PART="mmcblk0p1" + +logger "resizing $PART to fill its full partition size" +# get the disk total size +DISK_SIZE=`cat /sys/block/$DISK/size` + +# get partition start and size +PART_OFF=`cat /sys/block/$DISK/$PART/start` +PART_SIZE=`cat /sys/block/$DISK/$PART/size` + +# calculate size after the partition to the end of disk +SPARE=`expr $DISK_SIZE - $PART_OFF - $PART_SIZE` + +# new filesystem size, it must not overlap the secondary gpt header +# assume 1024kB as GPT size (is 34 sectors) +if [ $SPARE -lt 2048 ] +then + FSSIZE=`expr $PART_SIZE - 2048` +else + FSSIZE=$PART_SIZE +fi + +# resize now + +#reduce I/O load by doing this in 32M increments +#idea stolen from here: +#https://codereview.chromium.org/551127 + +NEXTSIZE=`expr 320 \* 1024 \* 2` +while [ $NEXTSIZE -lt $FSSIZE ]; do + FSSIZEMEG=`expr $NEXTSIZE / 2 / 1024`"M" + resize2fs /dev/$PART $FSSIZEMEG + sleep 1 + NEXTSIZE=`expr $NEXTSIZE + 32 \* 1024 \* 2` +done +FSSIZEMEG=`expr $FSSIZE / 2 / 1024`"M" +resize2fs /dev/$PART $FSSIZEMEG + +#job done, remove it from systemd services +systemctl disable resizefs.service + +logger "resizing $PART finished, new size is $FSSIZEMEG" + diff --git a/recipes-core/fs-init/fs-init.bb b/recipes-core/fs-init/fs-init.bb new file mode 100644 index 0000000..b2b61a8 --- /dev/null +++ b/recipes-core/fs-init/fs-init.bb @@ -0,0 +1,25 @@ +DESCRIPTION = "Script to expand the rootfs to the full size of its partion, started as a systemd service which removes itself once finished" +LICENSE = "Public Domain" +PR = "r3" + +SRC_URI = " \ + file://resizefs.sh \ + file://resizefs.service \ + file://COPYING \ +" + +LIC_FILES_CHKSUM = "file://${WORKDIR}/COPYING;md5=1c3a7fb45253c11c74434676d84fe7dd" + +do_compile () { +} + +do_install () { + install -d ${D}/${sbindir} + install -m 0755 ${WORKDIR}/*.sh ${D}/${sbindir} +} + +NATIVE_SYSTEMD_SUPPORT = "1" +SYSTEMD_PACKAGES = "${PN}" +SYSTEMD_SERVICE_${PN} = "resizefs.service" + +inherit allarch systemd -- cgit v1.2.3