Add option IMAGE_SIZE_ON_INIT

This commit is contained in:
Albrecht Lohofener
2025-04-12 09:23:15 +02:00
parent dba6b1144d
commit f30ef2f49e
3 changed files with 26 additions and 2 deletions
+10
View File
@@ -93,6 +93,16 @@ services:
# If unset -> disabled (OpenWrt auto upgrade is enabled)
#DISABLE_OPENWRT_AUTO_UPGRADE: "true"
# Resizes the OpenWrt disk image when the container runs the first time.
# Notes:
# * In a additional step you need to resize the partitions inside OpenWrt
# Follow: https://openwrt.org/docs/guide-user/advanced/expand_root
# * If you want to resize the OpenWrt after the container first time run
# Follow: https://github.com/AlbrechtL/openwrt-docker/issues/34#issuecomment-2795886248
# Value: Size im MB (minimal 512)
# If unset -> no resize (OpenWrt default image size)
#IMAGE_SIZE_ON_INIT: "512"
# Enable debugging mode.
# Showing the final qemu command and OpenWrt bootlog
# If unset -> disabled
+1
View File
@@ -19,5 +19,6 @@ trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR
: "${LUCI_WEB_BUTTON_JSON:=""}" # Adapt the "OpenWrt LuCI web interface" button to your needs.
: "${OPENWRT_AFTER_BOOT_CMD:=""}" # User command or script to run after OpenWrt is booted
: "${DISABLE_OPENWRT_AUTO_UPGRADE:=""}" # Disables the OpenWrt upgrade check every container startup
: "${IMAGE_SIZE_ON_INIT:=""}" # New OpenWrt disk image size
: "${IS_U_OS_APP:=""}" # By default this container is not a u-OS app
: "${DEBUG:=""}" # Disable debugging
+15 -2
View File
@@ -11,11 +11,24 @@ FILE=/storage/squashfs-combined-${OPENWRT_IMAGE_ID}.img
if [[ ($DISABLE_OPENWRT_AUTO_UPGRADE != "true") || (! -f /storage/current_version) ]]; then
if [ -f "$FILE" ]; then
info "$FILE exists. Nothing to do."
else
else
info "$FILE does not exist. Copying squashfs-combined-${OPENWRT_VERSION}.img to storage ..."
cp /var/vm/squashfs-combined-${OPENWRT_VERSION}.img.gz /storage/squashfs-combined-${OPENWRT_IMAGE_ID}.img.gz
gzip -d /storage/squashfs-combined-${OPENWRT_IMAGE_ID}.img.gz
# Check if IMAGE_SIZE_ON_INIT is set
if [[ -n "$IMAGE_SIZE_ON_INIT" ]]; then
# Check if IMAGE_SIZE_ON_INIT is greater than 511
if [[ "$IMAGE_SIZE_ON_INIT" -gt 511 ]]; then
info "Resize OpenWrt to $IMAGE_SIZE_ON_INIT MB"
dd if=/dev/zero of="/storage/squashfs-combined-${OPENWRT_IMAGE_ID}.img" seek="$IMAGE_SIZE_ON_INIT" obs=1MB count=0
else
error "Error: IMAGE_SIZE_ON_INIT must be greater than 511."
rm /storage/squashfs-combined-${OPENWRT_IMAGE_ID}.img
exit 1
fi
fi
if [ -f "/storage/current_version" ]; then
mv /storage/current_version /storage/old_version
fi