first_boot_rootfs_resizer: New Package.
PATCH 1/2 first_boot_rootfs_resizer: New Package.
this new package will resize the root fs to the max possible when booting an image for the first time.
--- 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
package/Config.in +1 -0
@@ -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"
package/first_boot_rootfs_resizer/Config.in new file +17 -0
@@ -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)
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +23 -0
@@ -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))
package/first_boot_rootfs_resizer/resize_fs.sh new file +44 -0
44 lines not on this page · raw message
package/first_boot_rootfs_resizer/resizing new file +11 -0
@@ -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 $?
Signature · 1 line
2.11.0
PATCH 2/2 odroidc2: use first boot fs resize pkg.
remove the hardcode limitation of the created rootfs parition size and use the newly added first boot fs resize pkg to extend the fs to the max possible.
--- board/hardkernel/odroidc2/genimage.cfg | 1 - configs/odroidc2_defconfig | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-)
board/hardkernel/odroidc2/genimage.cfg +0 -1
@@ -22,6 +22,5 @@ image sdcard.img { partition rootfs { partition-type = 0x83 image = "rootfs.ext4" - size = 512M } }
configs/odroidc2_defconfig +2 -0
@@ -7,6 +7,8 @@ BR2_TARGET_ROOTFS_EXT2=y BR2_TARGET_ROOTFS_EXT2_4=y BR2_ROOTFS_POST_IMAGE_SCRIPT="board/hardkernel/odroidc2/post-image.sh" BR2_PACKAGE_ODROID_SCRIPTS=y +BR2_PACKAGE_FIRST_BOOT_ROOTFS_RESIZER=y +BR2_PACKAGE_FIRST_BOOT_ROOTFS_RESIZER_SYSV_PRIORITY=3 BR2_GCC_VERSION_4_9_X=y # Kernel
Signature · 1 line
2.11.0
PATCH 2/2 odroidc2: use first boot fs resize pkg.
Hello,
Quoted 5 lines · Dagg Stompler
remove the hardcode limitation of the created rootfs parition size and use the newly added first boot fs resize pkg to extend the fs to the max possible.
Signed-off-by Dagg Stompler <[email protected]>
I think we want to decide if we want to do this globally for all defconfig for which it makes sense. Having that just for one defconfig, but not all the other is a bit weird. Being consistent is quite important.
Thanks,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 2/2 odroidc2: use first boot fs resize pkg.
Greetings,
Quoted 7 lines
Hello,
Quoted 4 lines · Dagg Stompler
remove the hardcode limitation of the created rootfs parition size and use the newly added first boot fs resize pkg to extend the fs to the max possible.
Quoted 6 lines
Quoted 1 line
Signed-off-by Dagg Stompler <[email protected]>I think we want to decide if we want to do this globally for all defconfig for which it makes sense. Having that just for one defconfig, but not all the other is a bit weird. Being consistent is quite important.
imho the first stage should be for the original board it was indented to, then extend it. as I don't have other measures to test it, I didn't want to set it globally.
Dagg.
Quoted 9 lines
Thanks,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 1/2 first_boot_rootfs_resizer: New Package.
In reply to Dagg StomplerHello,
Quoted 4 lines · Dagg Stompler
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 <[email protected]>
I think this is still way too use-case specific, and I'll explain below why your implementation only works in your specific case, but will fail in many other cases.
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 7
Quoted 13 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +7
-0@@ -0,0 +1,23 @@ +################################################################################ +# +# first_boot_rootfs_resizer +# +################################################################################ + +FIRST_BOOT_ROOTFS_RESIZER_LICENSE = unclear
We clearly shouldn't have an "unclear" license for such a package.
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 9
Quoted 1 line
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +1
-0+FIRST_BOOT_ROOTFS_RESIZER_PRIO = $(shell printf "%02u" $(BR2_PACKAGE_FIRST_BOOT_ROOTFS_RESIZER_SYSV_PRIORITY))
Don't make the priority configurable.
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 9
Quoted 11 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +10
-0+++ 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
Not needed in Buildroot init scripts.
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 10
Quoted 1 line
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +1
-0+PATH=/sbin:/usr/sbin:/bin:/usr/bin
Not needed.
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 11
Quoted 1 line
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +1
-0+ROOT=$(cat /proc/cmdline | tr ' ' '\n' | grep root= | cut -f 2 -d =)
This will fail badly if you have a GPT partition table and root= is using the partition UUID, like:
root=UUID=xyz
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 12
Quoted 1 line
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +1
-0+DEV=$(echo ${ROOT} | sed 's/p[0-9]\+$//g')
This only works for mmcblkXpY case, but not for sdXY
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 17
Quoted 5 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +5
-0+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}'`
This will not work with the Busybox fdisk, which is the default in Buildroot:
Disk /dev/sda: 256.0 GB, 256060514304 bytes
255 heads, 63 sectors/track, 31130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sda1 * 1 3648 29295616 83 Linux /dev/sda2 3648 4644 8000512 82 Linux swap /dev/sda3 4644 31131 212761600 83 Linux
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 30
Quoted 13 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +13
-0+ + fdisk ${DEV} <<EOF +p +d +2 +n +p +2 +$p2_start +$p2_finish +p +w +EOF
Using sfdisk is probably more appropriate here, as it's meant to be used for scripting.
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 35
Quoted 5 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +5
-0+ rm -fr /.first_boot + sync + reboot +else + resize2fs ${ROOT} && rm -fr $0
This only works if the root filesystem is ext2/ext3/ext4. Perhaps your package should depend on BR2_TARGET_ROOTFS_EXT2. Or the script should check if the filesystem is really ext2, ext3 or ext4 before proceeding.
Also, this logic doesn't work if the root filesystem is mounted read-only, since you expect to be able to remove .first_boot, and remove the script itself.
Quoted 6 lines
package/first_boot_rootfs_resizer/resizing new file +0
-0
package/first_boot_rootfs_resizer/resizing line 9
Quoted 9 lines
package/first_boot_rootfs_resizer/resizing new file +9
-0@@ -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
Why wouldn't the S00resizefs script directly do the resizing work?
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 1/2 first_boot_rootfs_resizer: New Package.
Greetings,
Quoted 12 lines
Hello,
Quoted 4 lines · Dagg Stompler
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 <[email protected]>I think this is still way too use-case specific, and I'll explain below why your implementation only works in your specific case, but will fail in many other cases.
Quoted 15 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 7
Quoted 13 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +7
-0@@ -0,0 +1,23 @@ +################################################################################ +# +# first_boot_rootfs_resizer +# +################################################################################ + +FIRST_BOOT_ROOTFS_RESIZER_LICENSE = unclearWe clearly shouldn't have an "unclear" license for such a package.
the file is ported from the odroidc2 buildroot, I've marked it unclear because it doesn't states it's license anywhere.
Quoted 4 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 9
Quoted 2 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +1
-0+FIRST_BOOT_ROOTFS_RESIZER_PRIO = $(shell printf "%02u" $(BR2_PACKAGE_FIRST_BOOT_ROOTFS_RESIZER_SYSV_PRIORITY))Don't make the priority configurable.
ok.
Quoted 15 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 9
Quoted 12 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +10
-0+++ 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 INFONot needed in Buildroot init scripts.
Quoted 3 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 10
Quoted 1 line
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +1
-0+PATH=/sbin:/usr/sbin:/bin:/usr/binNot needed.
will remove.
Quoted 8 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 11
Quoted 2 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +1
-0+ROOT=$(cat /proc/cmdline | tr ' ' '\n' | grep root= | cut -f 2 -d =)This will fail badly if you have a GPT partition table and root= is using the partition UUID, like:
root=UUID=xyz
I see, that should be the proper way to detect the rootfs file system?
Quoted 3 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 12
Quoted 1 line
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +1
-0+DEV=$(echo ${ROOT} | sed 's/p[0-9]\+$//g')This only works for mmcblkXpY case, but not for sdXY
correct, will see how I can generalize it more.
Quoted 10 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 17
Quoted 6 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +5
-0+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}'`This will not work with the Busybox fdisk, which is the default in Buildroot:
Quoted 8 lines
Disk
/dev/sda: 256.0 GB, 256060514304 bytes
255 heads, 63 sectors/track, 31130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System /dev/sda1 * 1 3648 29295616 83 Linux /dev/sda2 3648 4644 8000512 82 Linux swap /dev/sda3 4644 31131 212761600 83 Linux
I'm pretty sure I've tested it with busybox's fdisk.
Quoted 17 lines
Quoted 4 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +3
-0+ + fdisk ${DEV} <<EOF +ppackage/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 30
Quoted 10 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +10
-0+d +2 +n +p +2 +$p2_start +$p2_finish +p +w +EOFUsing sfdisk is probably more appropriate here, as it's meant to be used for scripting.
ok, will check.
Quoted 10 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk line 35
Quoted 6 lines
package/first_boot_rootfs_resizer/first_boot_rootfs_resizer.mk new file +5
-0+ rm -fr /.first_boot + sync + reboot +else + resize2fs ${ROOT} && rm -fr $0This only works if the root filesystem is ext2/ext3/ext4. Perhaps your package should depend on
BR2_TARGET_ROOTFS_EXT2. Or the script should check if the filesystem is really ext2, ext3 or ext4 before proceeding.
ok, I think it is better for now to limit it to ext2.
Quoted 4 lines
Also, this logic doesn't work if the root filesystem is mounted read-only, since you expect to be able to remove .first_boot, and remove the script itself.
so essentally, if the fs is read only, there is no way to remove it.
so the right way is to check every boot if the fs is maxed out to the boot dev and resize it if not. am I correct?
Quoted 10 lines
Quoted 10 lines
package/first_boot_rootfs_resizer/resizing new file +3
-0@@ -0,0 +1,11 @@ +#!/bin/sh + +case "$1" in
Quoted 8 lines
package/first_boot_rootfs_resizer/resizing line 9
Quoted 6 lines
package/first_boot_rootfs_resizer/resizing new file +6
-0+ start) + if [ -f /usr/sbin/resize_fs.sh ]; then /usr/sbin/resize_fs.sh; fi + ;; + *) + ;; +esacWhy wouldn't the S00resizefs script directly do the resizing work?
as said above, I've ported it from the odroidc2 buildroot, so I didn't tried to change it too much.
Quoted 9 lines
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 1/2 first_boot_rootfs_resizer: New Package.
Hello,
Quoted 2 lines · daggs
Quoted 1 line
We clearly shouldn't have an "unclear" license for such a package.
the file is ported from the odroidc2 buildroot, I've marked it unclear because it doesn't states it's license anywhere.
Would be good to get a clarified license, especially when the source code is inside Buildroot itself.
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
+ROOT=$(cat
/proc/cmdline| tr ' ' '\n' | grep root= | cut -f 2 -d =)This will fail badly if you have a GPT partition table and root= is using the partition UUID, like:
root=UUID=xyz
I see, that should be the proper way to detect the rootfs file system?
One way would be to use the Busybox "rdev" applet, but it's not enabled in our default configuration. You could run "stat /" where the "Device" fields tells you the block device that was mounted as the root filesystem. But not that trivial to go from this (major/minor) to the actual /dev/.
I'm not sure there's a good and simple way to achieve that I'm afraid.
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
+DEV=$(echo ${ROOT} | sed 's/p[0-9]\+$//g')
This only works for mmcblkXpY case, but not for sdXY
correct, will see how I can generalize it more.
It's actually not that easy to generalize, except of course if you restrict yourself to sdXY and mmcblkXpY.
Quoted 13 lines
Quoted 13 lines
package/first_boot_rootfs_resizer/resize_fs.sh line 25
Quoted 5 lines
package/first_boot_rootfs_resizer/resize_fs.sh new file +5
-0+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}'`This will not work with the Busybox fdisk, which is the default in Buildroot:
Disk
/dev/sda: 256.0 GB, 256060514304 bytes
255 heads, 63 sectors/track, 31130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Quoted 5 lines
Quoted 4 lines
Device Boot Start End Blocks Id System /dev/sda1 * 1 3648 29295616 83 Linux /dev/sda2 3648 4644 8000512 82 Linux swap /dev/sda3 4644 31131 212761600 83 LinuxI'm pretty sure I've tested it with busybox's fdisk.
Well, to find the size of the block device, you grep for "sectors". The only line matching with Busybox fdisk is:
255 heads, 63 sectors/track, 31130 cylinders
Which doesn't contain the size (at least not the size in sectors)
Quoted 3 lines
Quoted 2 lines
Using sfdisk is probably more appropriate here, as it's meant to be used for scripting.
ok, will check.
But sfdisk is not in Busybox, so make sure to select the right package.
Quoted 6 lines
Quoted 3 lines
Also, this logic doesn't work if the root filesystem is mounted read-only, since you expect to be able to remove .first_boot, and remove the script itself.
so essentally, if the fs is read only, there is no way to remove it.
so the right way is to check every boot if the fs is maxed out to the boot dev and resize it if not. am I correct?
Well, what if you're read-only but the root filesystem doesn't take the whole space? Perhaps you can check in 'mount | grep " / "' whether it's mounted read-only or not?
Quoted 2 lines
Quoted 1 line
Why wouldn't the S00resizefs script directly do the resizing work?
as said above, I've ported it from the odroidc2 buildroot, so I didn't tried to change it too much.
Since the source code is part of Buildroot and we don't intend to resync with the odroidc2 stuff, please make it more Buildroot-ish.
Thanks a lot!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 1/2 first_boot_rootfs_resizer: New Package.
Greetings,
Quoted 10 lines
Hello,
Quoted 2 lines · daggs
Quoted 1 line
We clearly shouldn't have an "unclear" license for such a package.
the file is ported from the odroidc2 buildroot, I've marked it unclear because it doesn't states it's license anywhere.
Would be good to get a clarified license, especially when the source code is inside Buildroot itself.
maybe I'll rewrite it from scratch not depending on this, thus license is irrelevant.
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
+ROOT=$(cat
/proc/cmdline| tr ' ' '\n' | grep root= | cut -f 2 -d =)This will fail badly if you have a GPT partition table and root= is using the partition UUID, like:
root=UUID=xyz
I see, that should be the proper way to detect the rootfs file system?
Quoted 7 lines
One way would be to use the Busybox "rdev" applet, but it's not enabled in our default configuration. You could run "stat /" where the "Device" fields tells you the block device that was mounted as the root filesystem. But not that trivial to go from this (major/minor) to the actual
/dev/.I'm not sure there's a good and simple way to achieve that I'm afraid.
I'll test the possibilities.
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
+DEV=$(echo ${ROOT} | sed 's/p[0-9]\+$//g')
This only works for mmcblkXpY case, but not for sdXY
correct, will see how I can generalize it more.
It's actually not that easy to generalize, except of course if you restrict yourself to sdXY and mmcblkXpY.
beside sdXY, mmcblkXpY and hdaXY, are there any other possibilities?
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
package/first_boot_rootfs_resizer/resize_fs.sh line 25
Quoted 6 lines
package/first_boot_rootfs_resizer/resize_fs.sh new file +5
-0+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}'`This will not work with the Busybox fdisk, which is the default in Buildroot:
Disk
/dev/sda: 256.0 GB, 256060514304 bytes
255 heads, 63 sectors/track, 31130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytesQuoted 5 lines
Quoted 4 lines
Device Boot Start End Blocks Id System /dev/sda1 * 1 3648 29295616 83 Linux /dev/sda2 3648 4644 8000512 82 Linux swap /dev/sda3 4644 31131 212761600 83 LinuxI'm pretty sure I've tested it with busybox's fdisk.
Well, to find the size of the block device, you grep for "sectors". The only line matching with Busybox fdisk is:
255 heads, 63 sectors/track, 31130 cylinders
Quoted 7 lines
Which doesn't contain the size (at least not the size in sectors)
Quoted 3 lines
Quoted 2 lines
Using sfdisk is probably more appropriate here, as it's meant to be used for scripting.
ok, will check.
But sfdisk is not in Busybox, so make sure to select the right package.
will see what I can do.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Also, this logic doesn't work if the root filesystem is mounted read-only, since you expect to be able to remove .first_boot, and remove the script itself.
so essentally, if the fs is read only, there is no way to remove it.
so the right way is to check every boot if the fs is maxed out to the boot dev and resize it if not. am I correct?Well, what if you're read-only but the root filesystem doesn't take the whole space? Perhaps you can check in 'mount | grep " / "' whether it's mounted read-only or not?
not sure I follow, can you please elaborate more?
Quoted 10 lines
Quoted 3 lines
Quoted 2 lines
Why wouldn't the S00resizefs script directly do the resizing work?
as said above, I've ported it from the odroidc2 buildroot, so I didn't tried to change it too much.
Since the source code is part of Buildroot and we don't intend to resync with the odroidc2 stuff, please make it more Buildroot-ish.
Thanks a lot!
Thomas
Dagg.
PATCH 1/2 first_boot_rootfs_resizer: New Package.
In reply to Dagg StomplerHello,
On Friday 02 December 2016 12:10:27 daggs wrote:
[...]
Quoted 5 lines
package/first_boot_rootfs_resizer/resize_fs.sh new file +5
-0+ p2_start=`fdisk -l ${DEV} | grep ${PART} | awk '{print $2}'` + p2_finish=`fdisk -l ${DEV} | grep sectors | awk '{printf $5}'` + + fdisk ${DEV} <<EOF +p
package/first_boot_rootfs_resizer/resize_fs.sh line 38
Quoted 10 lines
package/first_boot_rootfs_resizer/resize_fs.sh new file +10
-0+d +2 +n +p +2 +$p2_start +$p2_finish +p +w +EOF
This script always resize 2nd partition, isn't? Is it the expected behavior? I think it should resize last partition.
For information, I wrote a similar script for a customer some time ago:
for part in 4 3 2 1; do
for file in ${device}${part} ${device}p${part}; do
if [ -e $file ]; then
echo ',+,' | sfdisk -q -L -D -uM -N $part $device
[ $? -eq 0 ] || exit 1
resize2fs -p $file
[ $? -eq 0 ] || exit 1
e2fsck -f $file
[ $? -le 1 ] || exit 1
exit 0
fi
donedone
Also note, we did use this script during flash procedure, not during first boot. Therefore, we do not need to detect first boot (and I think it is safer).
BR,
Signature · 3 lines
J?r?me Pouiller, Sysmic Embedded Linux specialist http://www.sysmic.fr
PATCH 1/2 first_boot_rootfs_resizer: New Package.
Greetings,
Quoted 37 lines
Hello,
On Friday 02 December 2016 12:10:27 daggs wrote:
[...]Quoted 5 lines
package/first_boot_rootfs_resizer/resize_fs.sh new file +5
-0+ p2_start=`fdisk -l ${DEV} | grep ${PART} | awk '{print $2}'` + p2_finish=`fdisk -l ${DEV} | grep sectors | awk '{printf $5}'` + + fdisk ${DEV} <<EOF +ppackage/first_boot_rootfs_resizer/resize_fs.sh line 38
Quoted 10 lines
package/first_boot_rootfs_resizer/resize_fs.sh new file +10
-0+d +2 +n +p +2 +$p2_start +$p2_finish +p +w +EOFThis script always resize 2nd partition, isn't? Is it the expected behavior? I think it should resize last partition.
For information, I wrote a similar script for a customer some time ago:
for part in 4 3 2 1; do
for file in ${device}${part} ${device}p${part}; do if [ -e $file ]; then echo ',+,' | sfdisk -q -L -D -uM -N $part $device [ $? -eq 0 ] || exit 1 resize2fs -p $file [ $? -eq 0 ] || exit 1 e2fsck -f $file [ $? -le 1 ] || exit 1 exit 0 fi done
Quoted 8 lines
done
Also note, we did use this script during flash procedure, not during first boot. Therefore, we do not need to detect first boot (and I think it is safer).
BR,
Thanks, will take that into account on later stage.
Dagg.