Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Dagg Stompler <daggs@gmx.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 1/2] first_boot_rootfs_resizer: New Package.
Date: Fri,  2 Dec 2016 12:10:27 +0200	[thread overview]
Message-ID: <20161202101028.26736-1-daggs@gmx.com> (raw)

this new package will resize the root fs to the max possible when
booting an image for the first time.

Signed-off-by: Dagg Stompler <daggs@gmx.com>
---
 package/Config.in                                  |  1 +
 package/first_boot_rootfs_resizer/Config.in        | 17 +++++++++
 .../first_boot_rootfs_resizer.mk                   | 23 +++++++++++
 package/first_boot_rootfs_resizer/resize_fs.sh     | 44 ++++++++++++++++++++++
 package/first_boot_rootfs_resizer/resizing         | 11 ++++++
 5 files changed, 96 insertions(+)
 create mode 100644 package/first_boot_rootfs_resizer/Config.in
 create mode 100644 package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk
 create mode 100644 package/first_boot_rootfs_resizer/resize_fs.sh
 create mode 100644 package/first_boot_rootfs_resizer/resizing

diff --git a/package/Config.in b/package/Config.in
index 9ed296f2d..ed414fd3d 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -1408,6 +1408,7 @@ menu "Miscellaneous"
 	source "package/collectd/Config.in"
 	source "package/domoticz/Config.in"
 	source "package/empty/Config.in"
+	source "package/first_boot_rootfs_resizer/Config.in"
 	source "package/gnuradio/Config.in"
 	source "package/googlefontdirectory/Config.in"
 	source "package/gr-osmosdr/Config.in"
diff --git a/package/first_boot_rootfs_resizer/Config.in b/package/first_boot_rootfs_resizer/Config.in
new file mode 100644
index 000000000..cce62dd39
--- /dev/null
+++ b/package/first_boot_rootfs_resizer/Config.in
@@ -0,0 +1,17 @@
+config BR2_PACKAGE_FIRST_BOOT_ROOTFS_RESIZER
+	bool "first_boot_rootfs_resizer"
+	select BR2_PACKAGE_E2FSPROGS # for resizefs
+	select BR2_PACKAGE_E2FSPROGS_RESIZE2FS # for resizefs
+	depends on BR2_USE_WCHAR # util-linux
+
+	help
+	  installs a script that will resize the rootfs to the max possible consecutive size
+	  unused from the end of rootfs.
+
+config BR2_PACKAGE_FIRST_BOOT_ROOTFS_RESIZER_SYSV_PRIORITY
+	int "SystemV priority"
+	depends on BR2_PACKAGE_FIRST_BOOT_ROOTFS_RESIZER
+	default "0"
+
+	help
+	  set the script's priority (defualt is 00)
diff --git a/package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk b/package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk
new file mode 100644
index 000000000..8752831ea
--- /dev/null
+++ b/package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk
@@ -0,0 +1,23 @@
+################################################################################
+#
+# first_boot_rootfs_resizer
+#
+################################################################################
+
+FIRST_BOOT_ROOTFS_RESIZER_LICENSE = unclear
+
+FIRST_BOOT_ROOTFS_RESIZER_PRIO = $(shell printf "%02u" $(BR2_PACKAGE_FIRST_BOOT_ROOTFS_RESIZER_SYSV_PRIORITY))
+FIRST_BOOT_ROOTFS_RESIZER_DEPENDENCIES = e2fsprogs
+
+define FIRST_BOOT_ROOTFS_RESIZER_INSTALL_TARGET_CMDS
+	$(INSTALL) -D -m 755 package/first_boot_rootfs_resizer/resize_fs.sh \
+		$(TARGET_DIR)/usr/sbin/resize_fs.sh
+	touch $(TARGET_DIR)/.first_boot
+endef
+
+define FIRST_BOOT_ROOTFS_RESIZER_INSTALL_INIT_SYSV
+	$(INSTALL) -D -m 755 package/first_boot_rootfs_resizer/resizing \
+		$(TARGET_DIR)/etc/init.d/S$(FIRST_BOOT_ROOTFS_RESIZER_PRIO)resizing
+endef
+
+$(eval $(generic-package))
diff --git a/package/first_boot_rootfs_resizer/resize_fs.sh b/package/first_boot_rootfs_resizer/resize_fs.sh
new file mode 100644
index 000000000..be41753d8
--- /dev/null
+++ b/package/first_boot_rootfs_resizer/resize_fs.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides:          resize_fs.sh
+# Required-Start:    $remote_fs $all
+# Required-Stop:
+# Default-Start:     2 3 4 5 S
+# Default-Stop:
+# Short-Description: First boot system setup
+### END INIT INFO
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+ROOT=$(cat /proc/cmdline | tr ' ' '\n' | grep root= | cut -f 2 -d =)
+DEV=$(echo ${ROOT} | sed 's/p[0-9]\+$//g')
+PART=$(basename ${ROOT})
+
+if [ ! -z "${ROOT}" ]; then
+	echo "unable to locate root= entry in cmdline, resizing aborted"
+	exit 1
+fi
+
+if [ -f /.first_boot ]; then
+	echo "Resizing fs, please wait... upon finish the system will be restarted"
+	# ok, its the very first boot, we need to resize the disk.
+	p2_start=`fdisk -l ${DEV} | grep ${PART} | awk '{print $2}'`
+	p2_finish=`fdisk -l ${DEV} | grep sectors | awk '{printf $5}'`
+
+	fdisk ${DEV} <<EOF
+p
+d
+2
+n
+p
+2
+$p2_start
+$p2_finish
+p
+w
+EOF
+	rm -fr /.first_boot
+	sync
+	reboot
+else
+	resize2fs ${ROOT} && rm -fr $0
+fi
diff --git a/package/first_boot_rootfs_resizer/resizing b/package/first_boot_rootfs_resizer/resizing
new file mode 100644
index 000000000..4a19ce40e
--- /dev/null
+++ b/package/first_boot_rootfs_resizer/resizing
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+case "$1" in
+	start)
+		if [ -f /usr/sbin/resize_fs.sh ]; then /usr/sbin/resize_fs.sh; fi
+		;;
+	*)
+		;;
+esac
+
+exit $?
-- 
2.11.0

             reply	other threads:[~2016-12-02 10:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02 10:10 Dagg Stompler [this message]
2016-12-02 10:10 ` [Buildroot] [PATCH 2/2] odroidc2: use first boot fs resize pkg Dagg Stompler
2016-12-17 15:51   ` Thomas Petazzoni
2016-12-23 13:43     ` daggs
2016-12-17 15:50 ` [Buildroot] [PATCH 1/2] first_boot_rootfs_resizer: New Package Thomas Petazzoni
2016-12-23 13:41   ` daggs
2016-12-23 14:00     ` Thomas Petazzoni
2016-12-23 19:08       ` daggs
2017-01-03 11:39 ` [Buildroot] [1/2] " Jérôme Pouiller
2017-02-25 10:54   ` daggs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161202101028.26736-1-daggs@gmx.com \
    --to=daggs@gmx.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox