diff --git a/docker-compose.yml b/docker-compose.yml index 696b30c..921e9bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/src/helpers.sh b/src/helpers.sh index 8ed08ee..29b695c 100644 --- a/src/helpers.sh +++ b/src/helpers.sh @@ -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 diff --git a/src/install_openwrt_rootfs.sh b/src/install_openwrt_rootfs.sh index 8851311..d522290 100644 --- a/src/install_openwrt_rootfs.sh +++ b/src/install_openwrt_rootfs.sh @@ -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