├── docker ├── .dockerignore ├── .env.example ├── docker-compose.yml ├── ci-workflow-example.yml ├── auto-resources.sh ├── Dockerfile ├── README.md ├── README-prebuilt.md ├── build-container-image.sh ├── build-onefilelinux.sh └── entrypoint.sh ├── .gitignore ├── LICENSE ├── docs ├── BUILD_DOCS.md └── USER_GUIDE.md ├── TODO.md ├── README.md └── .github └── workflows └── docker-build.yml /docker/.dockerignore: -------------------------------------------------------------------------------- 1 | # Exclude Docker-specific files 2 | README*.md 3 | .env 4 | .env.example 5 | docker-compose.yml 6 | auto-resources.sh 7 | build-onefilelinux.sh 8 | build-container-image.sh 9 | .git* 10 | 11 | # Exclude unnecessary files when building prebuilt container 12 | !../build/*.sh 13 | !../build/tools/ 14 | !../build/zfiles/ 15 | !../build/kernel-configs/ -------------------------------------------------------------------------------- /docker/.env.example: -------------------------------------------------------------------------------- 1 | # OneFileLinux Docker Build Configuration 2 | # Copy this file to .env and modify as needed 3 | 4 | # Build arguments to pass to the build.sh script 5 | # Examples: 6 | # BUILD_ARGS=--minimal 7 | # BUILD_ARGS=--full 8 | # BUILD_ARGS=--with-zfs --with-btrfs --with-recovery-tools 9 | BUILD_ARGS=--with-zfs --with-recovery-tools --with-network-tools --use-cache 10 | 11 | # User ID and Group ID mapping (defaults to current user) 12 | # This ensures files created in the container have the correct ownership 13 | # HOST_UID=1000 14 | # HOST_GID=1000 15 | 16 | # Docker resource limits (uncomment to enable) 17 | # DOCKER_MEMORY=4g 18 | # DOCKER_CPUS=4 19 | 20 | # Advanced Docker configuration 21 | # DOCKER_NETWORK=host 22 | # DOCKER_EXTRA_HOSTS=somehost:127.0.0.1 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | FoxBuild/linux-* 2 | FoxBuild/linux 3 | FoxBuild/zfs* 4 | FoxBuild/alpine-minirootfs/ 5 | FoxBuild/*.tar.* 6 | OneFileLinux.efi 7 | FUTURE_IMPROVEMENTS.md 8 | .DS_Store 9 | CLAUDE.md 10 | 11 | # Build artifacts 12 | build/.build_progress 13 | build/alpine-minirootfs* 14 | build/build_error.log 15 | build/build_timing.log 16 | build/linux-6* 17 | build/linux/ 18 | build/linux 19 | build/zfs-* 20 | build/zfs/ 21 | build/zfs 22 | build/.extraction_complete 23 | build/*/.extraction_complete 24 | build/onerecovery-password.txt 25 | build/onefilelinux-password.txt 26 | build/kernel-configs/*.config.backup 27 | build/kernel-configs/minimal.config 28 | build/kernel-configs/standard.config 29 | build/kernel-configs/base/*.config 30 | output/ 31 | *.tar.gz 32 | *.tar.xz 33 | 34 | # Docker artifacts 35 | docker/.env 36 | 37 | # Claude working directory 38 | zclaude/ 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 OneFileLinux Contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | onefilelinux-builder: 3 | build: 4 | context: . 5 | dockerfile: Dockerfile 6 | image: onefilelinux-builder-local:latest 7 | container_name: onefilelinux-builder 8 | # Run as root by default in GitHub Actions 9 | user: ${RUN_AS_USER:-root} 10 | volumes: 11 | # Mount source code including all library scripts 12 | - ../build:/onefilelinux/build:rw 13 | # Mount output directory 14 | - ../output:/onefilelinux/output:rw 15 | # Mount persistent build cache 16 | - onefilelinux-cache:/onefilelinux/.buildcache 17 | environment: 18 | # Configure build arguments here (can be overridden with .env) 19 | - BUILD_ARGS=${BUILD_ARGS:-"--with-zfs --with-recovery-tools --with-network-tools --use-cache --make-verbose"} 20 | # Configure user ID mapping (only used if not running as root) 21 | - HOST_UID=${HOST_UID:-1000} 22 | - HOST_GID=${HOST_GID:-1000} 23 | # Explicitly run as root in container 24 | - RUN_AS_ROOT=true 25 | # Build optimization 26 | - USE_CACHE=true 27 | - CCACHE_COMPRESS=true 28 | # Timing and performance logging 29 | - FINALIZE_TIMING_LOG=true 30 | - TIMING_LOG_FILE=/onefilelinux/build/build_timing.log 31 | # Password settings 32 | - GENERATE_RANDOM_PASSWORD=${GENERATE_RANDOM_PASSWORD:-true} 33 | - ROOT_PASSWORD=${ROOT_PASSWORD:-"onefilelinux"} 34 | # Resource limits (dynamically set by auto-resources.sh script) 35 | deploy: 36 | resources: 37 | limits: 38 | memory: ${DOCKER_MEMORY:-"4g"} 39 | cpus: ${DOCKER_CPUS:-2} 40 | # Enable any required capabilities 41 | cap_add: 42 | - SYS_ADMIN # Required for chroot operations 43 | # Enable privileged mode for complex operations like loop devices 44 | privileged: true 45 | 46 | volumes: 47 | onefilelinux-cache: 48 | driver: local -------------------------------------------------------------------------------- /docker/ci-workflow-example.yml: -------------------------------------------------------------------------------- 1 | name: Build OneFileLinux 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | workflow_dispatch: 9 | inputs: 10 | build_profile: 11 | description: 'Build profile to use' 12 | required: true 13 | default: 'standard' 14 | type: choice 15 | options: 16 | - minimal 17 | - standard 18 | - full 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | container: 24 | image: ghcr.io/onefilelinux/builder:latest 25 | options: --privileged 26 | 27 | steps: 28 | - name: Check Environment 29 | run: | 30 | echo "Running in prebuilt OneFileLinux builder container" 31 | uname -a 32 | echo "CPU info:" 33 | cat /proc/cpuinfo | grep "model name" | head -1 34 | echo "Memory info:" 35 | free -h 36 | echo "Disk info:" 37 | df -h 38 | 39 | - name: Determine Build Profile 40 | id: profile 41 | run: | 42 | if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then 43 | echo "Using manually selected profile: ${{ github.event.inputs.build_profile }}" 44 | echo "profile=${{ github.event.inputs.build_profile }}" >> $GITHUB_OUTPUT 45 | else 46 | echo "Using default profile: standard" 47 | echo "profile=standard" >> $GITHUB_OUTPUT 48 | fi 49 | 50 | - name: Build OneFileLinux 51 | run: | 52 | cd /onefilelinux/build 53 | BUILD_PROFILE="${{ steps.profile.outputs.profile }}" 54 | echo "Building OneFileLinux with profile: $BUILD_PROFILE" 55 | 56 | # Run the build with the selected profile 57 | if [ "$BUILD_PROFILE" == "minimal" ]; then 58 | ./build.sh --minimal --use-cache 59 | elif [ "$BUILD_PROFILE" == "full" ]; then 60 | ./build.sh --full --with-zfs --with-network-tools --with-crypto --use-cache 61 | else 62 | ./build.sh --standard --with-network-tools --use-cache 63 | fi 64 | 65 | - name: Check Build Artifacts 66 | run: | 67 | cd /onefilelinux/output 68 | ls -lah 69 | file *.efi || echo "No EFI files found" 70 | 71 | - name: Upload Artifacts 72 | uses: actions/upload-artifact@v3 73 | with: 74 | name: onefilelinux-efi-${{ steps.profile.outputs.profile }} 75 | path: | 76 | /onefilelinux/output/*.efi 77 | /onefilelinux/build/build_timing.log -------------------------------------------------------------------------------- /docker/auto-resources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Script to automatically determine optimal resource allocation for Docker build 3 | 4 | # Default values if detection fails 5 | DEFAULT_MEM="4g" 6 | DEFAULT_CPUS="2" 7 | 8 | MIN_FREE_MEM_GB=4 # Minimum free memory to leave for the host system 9 | MIN_FREE_CPUS=1 # Minimum free CPU cores to leave for the host system 10 | 11 | # Get total system memory 12 | if [[ "$OSTYPE" == "darwin"* ]]; then 13 | # macOS 14 | TOTAL_MEM_KB=$(sysctl -n hw.memsize | awk '{print $1/1024}') 15 | TOTAL_CPUS=$(sysctl -n hw.ncpu) 16 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then 17 | # Linux 18 | TOTAL_MEM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}') 19 | TOTAL_CPUS=$(nproc) 20 | else 21 | # Unsupported OS, use defaults 22 | echo "Unable to detect system resources on this OS. Using defaults." 23 | echo "DOCKER_MEMORY=$DEFAULT_MEM" 24 | echo "DOCKER_CPUS=$DEFAULT_CPUS" 25 | exit 0 26 | fi 27 | 28 | # Convert to GB and round down 29 | TOTAL_MEM_GB=$((TOTAL_MEM_KB / 1024 / 1024)) 30 | 31 | # Calculate available resources, leaving some for the host 32 | AVAIL_MEM_GB=$((TOTAL_MEM_GB - MIN_FREE_MEM_GB)) 33 | AVAIL_CPUS=$((TOTAL_CPUS - MIN_FREE_CPUS)) 34 | 35 | # Ensure minimums 36 | if [ $AVAIL_MEM_GB -lt 2 ]; then 37 | AVAIL_MEM_GB=2 38 | fi 39 | if [ $AVAIL_CPUS -lt 1 ]; then 40 | AVAIL_CPUS=1 41 | fi 42 | 43 | # Use 75% of available memory for Docker if less than 10GB, otherwise 85% 44 | if [ $AVAIL_MEM_GB -lt 10 ]; then 45 | DOCKER_MEM_GB=$((AVAIL_MEM_GB * 3 / 4)) 46 | else 47 | DOCKER_MEM_GB=$((AVAIL_MEM_GB * 85 / 100)) 48 | fi 49 | DOCKER_MEM="${DOCKER_MEM_GB}g" 50 | 51 | # Determine build flags 52 | BUILD_FLAGS="--jobs=$AVAIL_CPUS" 53 | if [ $DOCKER_MEM_GB -gt 16 ]; then 54 | # Plenty of memory, no need for special flags 55 | BUILD_FLAGS="$BUILD_FLAGS" 56 | else 57 | # Limited memory, use memory optimization flags 58 | BUILD_FLAGS="$BUILD_FLAGS --use-swap" 59 | fi 60 | 61 | # Output results 62 | echo "Detected system resources: ${TOTAL_MEM_GB}GB RAM, ${TOTAL_CPUS} CPU cores" 63 | echo "Allocating: ${DOCKER_MEM} RAM, ${AVAIL_CPUS} CPU cores to Docker" 64 | 65 | # Always set the variables for sourcing 66 | DOCKER_MEMORY=$DOCKER_MEM 67 | DOCKER_CPUS=$AVAIL_CPUS 68 | BUILD_FLAGS=$BUILD_FLAGS 69 | 70 | # Output for different modes 71 | if [ "$1" == "--env" ]; then 72 | echo "DOCKER_MEMORY=$DOCKER_MEM" 73 | echo "DOCKER_CPUS=$AVAIL_CPUS" 74 | echo "BUILD_FLAGS=$BUILD_FLAGS" 75 | 76 | # Also export for sourcing 77 | export DOCKER_MEMORY 78 | export DOCKER_CPUS 79 | export BUILD_FLAGS 80 | elif [ "$1" == "--export" ]; then 81 | echo "export DOCKER_MEMORY=$DOCKER_MEM" 82 | echo "export DOCKER_CPUS=$AVAIL_CPUS" 83 | echo "export BUILD_FLAGS=$BUILD_FLAGS" 84 | else 85 | # Default output 86 | echo "DOCKER_MEMORY=$DOCKER_MEM" 87 | echo "DOCKER_CPUS=$AVAIL_CPUS" 88 | echo "BUILD_FLAGS=$BUILD_FLAGS" 89 | fi -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM --platform=$BUILDPLATFORM alpine:latest 2 | 3 | # Set build arguments with defaults 4 | ARG BUILDPLATFORM="linux/amd64" 5 | ARG TARGETPLATFORM="linux/amd64" 6 | 7 | # Print platform info for debugging 8 | RUN echo "Building on $BUILDPLATFORM for $TARGETPLATFORM" 9 | 10 | # Install build dependencies 11 | RUN apk add --no-cache \ 12 | bash \ 13 | build-base \ 14 | musl-dev \ 15 | linux-headers \ 16 | git \ 17 | autoconf \ 18 | automake \ 19 | libtool \ 20 | util-linux \ 21 | util-linux-dev \ 22 | xz-dev \ 23 | zlib-dev \ 24 | zstd-dev \ 25 | lz4-dev \ 26 | openssl-dev \ 27 | libelf \ 28 | elfutils-dev \ 29 | bison \ 30 | flex \ 31 | ccache \ 32 | upx \ 33 | xz \ 34 | zstd \ 35 | curl \ 36 | wget \ 37 | sudo \ 38 | gcc \ 39 | g++ \ 40 | make \ 41 | patch \ 42 | python3 \ 43 | python3-dev \ 44 | py3-setuptools \ 45 | ncurses-dev \ 46 | e2fsprogs \ 47 | e2fsprogs-dev \ 48 | coreutils \ 49 | mtools \ 50 | xorriso \ 51 | squashfs-tools \ 52 | kmod \ 53 | bc \ 54 | rsync \ 55 | shadow \ 56 | su-exec \ 57 | # Full GNU utilities for kernel build (BusyBox lacks some required options) 58 | diffutils \ 59 | findutils \ 60 | # OpenSSL for kernel signing operations 61 | openssl \ 62 | # Package config tool for build system 63 | pkgconf \ 64 | # UUID libraries required for ZFS 65 | libuuid \ 66 | # Extended attribute support required for ZFS 67 | attr-dev \ 68 | # Device management support for ZFS 69 | eudev-dev \ 70 | # RPC support required for ZFS 71 | libtirpc-dev \ 72 | # Math libraries for GCC plugins 73 | gmp-dev \ 74 | mpfr-dev \ 75 | mpc1-dev \ 76 | # Additional dependencies needed for ZFS 77 | libunwind-dev \ 78 | libuuid \ 79 | musl-dev \ 80 | # Performance optimizations for archive extraction 81 | pigz \ 82 | pv 83 | 84 | # Create non-root user to run the build as 85 | RUN adduser -D -u 1000 builder && \ 86 | echo "builder ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/builder && \ 87 | chmod 4755 /bin/busybox 88 | 89 | # Set up build directories and cache locations 90 | RUN mkdir -p /onefilelinux/build /onefilelinux/output /onefilelinux/.buildcache && \ 91 | chown -R builder:builder /onefilelinux 92 | 93 | # Create cache directories 94 | RUN mkdir -p /onefilelinux/.buildcache/sources \ 95 | /onefilelinux/.buildcache/packages \ 96 | /onefilelinux/.buildcache/ccache \ 97 | /onefilelinux/.buildcache/build && \ 98 | chown -R builder:builder /onefilelinux/.buildcache 99 | 100 | # Configure ccache for better performance 101 | ENV CCACHE_DIR=/onefilelinux/.buildcache/ccache 102 | ENV PATH=/usr/lib/ccache:$PATH 103 | RUN su builder -c "ccache -M 5G" && \ 104 | su builder -c "ccache -o compression=true" && \ 105 | su builder -c "ccache -o compression_level=6" && \ 106 | su builder -c "ccache -z" 107 | 108 | # Copy entrypoint script 109 | COPY entrypoint.sh /usr/local/bin/entrypoint.sh 110 | RUN chmod +x /usr/local/bin/entrypoint.sh 111 | 112 | # Set workdir 113 | WORKDIR /onefilelinux 114 | 115 | # Install a healthcheck 116 | HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ 117 | CMD ps aux | grep -v grep | grep -q "bash" || exit 1 118 | 119 | # Set entrypoint 120 | ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] 121 | CMD ["./build.sh"] -------------------------------------------------------------------------------- /docs/BUILD_DOCS.md: -------------------------------------------------------------------------------- 1 | # OneFileLinux Build Documentation 2 | 3 | ## Quick References 4 | 5 | For detailed information about the build system and available options, please refer to: 6 | 7 | - [Build System README](../build/README.md) - Core build process documentation 8 | - [Docker Build System README](../docker/README.md) - Containerized build instructions 9 | - [User Guide](USER_GUIDE.md#detailed-build-script-options) - Detailed build script options 10 | 11 | ## Build System Architecture 12 | 13 | The OneFileLinux build system employs a structured approach with modular components and library scripts to ensure reliable builds across different environments. 14 | 15 | ### Script Organization 16 | 17 | #### Library Scripts (80-89 range) 18 | 19 | The build system has been reorganized to use a numbered library script system in the 80-89 range: 20 | 21 | - **80_common.sh**: Basic utilities, logging functions, and environment detection 22 | - Provides color definitions, logging, banners, and environment checks 23 | - Has minimal dependencies and loads quickly 24 | - Used by all other scripts for consistent output formatting 25 | 26 | - **81_error_handling.sh**: Error management and recovery 27 | - Handles error trapping, reporting, and recovery 28 | - Performs prerequisite checking for build scripts 29 | - Tracks build progress for resuming interrupted builds 30 | 31 | - **82_build_helper.sh**: Environment-aware build utilities 32 | - Provides file and directory operations with proper permissions 33 | - Implements extraction with fallback methods for different environments 34 | - Contains system configuration and build helper functions 35 | 36 | #### Build Scripts (00-10, 99 range) 37 | 38 | The main build process is divided into numbered steps: 39 | 40 | - **00_prepare.sh**: Environment preparation and dependency installation 41 | - **01_get.sh**: Component downloading and extraction 42 | - **02_chrootandinstall.sh**: Alpine Linux configuration and package installation 43 | - **03_conf.sh**: System services and settings configuration 44 | - **04_build.sh**: Kernel building and EFI file creation 45 | - **99_cleanup.sh**: Build artifact cleanup 46 | 47 | #### Entry Points 48 | 49 | - **build.sh**: Main entry point for the build process 50 | - **docker/build-onefilelinux.sh**: Docker-based build launcher 51 | 52 | ### Using the Build System 53 | 54 | When creating new scripts or modifying existing ones, follow this sourcing order: 55 | 56 | 1. Set script name: `SCRIPT_NAME=$(basename "$0")` 57 | 2. Source common utilities: `source ./80_common.sh` 58 | 3. Source error handling: `source ./81_error_handling.sh` 59 | 4. Initialize error handling: `init_error_handling` 60 | 5. Source build helper if needed: `source ./82_build_helper.sh` 61 | 62 | This ensures proper initialization and consistent behavior across the build system. 63 | 64 | ### Environment Detection 65 | 66 | The build system automatically adapts to different environments: 67 | 68 | - **Standard Environment**: Uses the local system directly 69 | - **Docker Container**: Adapts to container constraints and permissions 70 | - **CI/CD Systems**: Handles restricted permissions in GitHub Actions 71 | 72 | Environment detection is centralized in the common library to avoid inconsistencies. 73 | 74 | ### Key Improvements 75 | 76 | Recent improvements to the build system include: 77 | 78 | - **Better Separation of Concerns**: Clear responsibilities for each script 79 | - **Reduced Duplication**: Shared functionality moved to library scripts 80 | - **Standardized Banner Display**: Consistent headers across all scripts 81 | - **Extraction Caching**: Marker files to avoid redundant extractions 82 | - **Verbose Output Control**: Support for detailed build output (`--make-verbose`) 83 | 84 | For more detailed build options and customization, refer to the [User Guide](USER_GUIDE.md#detailed-build-script-options). -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # OneFileLinux Documentation Update Tasks 2 | 3 | ## Documentation Updates Completed 4 | 5 | 1. **Feature Flag System Documentation** 6 | - [x] Document `parse_build_flags()` function and its role in the build system 7 | - [x] Create comprehensive table of all feature flags with descriptions and default values 8 | - [x] Document relationships between high-level flags (--minimal, --full) and individual feature flags 9 | - [x] Explain how feature flags affect package selection, kernel configuration, and build output 10 | - [x] Include examples of common flag combinations 11 | 12 | 2. **Kernel Configuration System Updates** 13 | - [x] Document the overlay-based kernel configuration system 14 | - [x] Explain the role of base configs (minimal.config, standard.config) 15 | - [x] Document feature-specific overlays and how they're conditionally applied 16 | - [x] Update information about kernel minimization process 17 | - [x] Document kernel config directory structure and organization 18 | 19 | 3. **Build Environment Documentation** 20 | - [x] Document environment detection mechanisms (is_github_actions, is_docker_container) 21 | - [x] Explain environment-specific adaptations in the build system 22 | - [x] Document permission handling across different environments 23 | - [x] Explain resource optimization mechanisms (memory, threads) 24 | - [x] Document troubleshooting approaches for different environments 25 | 26 | 4. **CI/CD Documentation** 27 | - [x] Document GitHub Actions workflow structure 28 | - [x] Explain the build matrix for different configurations 29 | - [x] Document artifact generation and distribution 30 | - [x] Explain Docker integration in GitHub Actions 31 | - [x] Document release process 32 | 33 | 5. **Architecture Documentation Updates** 34 | - [x] Update library architecture documentation to include new functions 35 | - [x] Document build flag propagation through the build process 36 | - [x] Update build sequence documentation to reflect current implementation 37 | - [x] Document special handling for minimal builds 38 | 39 | ## Implementation Completed 40 | 41 | 1. **Research Phase** 42 | - [x] Review all shell scripts to identify undocumented features 43 | - [x] Catalog all feature flags and their effects 44 | - [x] Document kernel configuration overlay system 45 | 46 | 2. **Draft Phase** 47 | - [x] Create draft documentation sections 48 | - [x] Generate feature flag reference table 49 | - [x] Document kernel configuration overlay system 50 | 51 | 3. **Review and Update** 52 | - [x] Review documentation for accuracy and completeness 53 | - [x] Add all new documentation to USER_GUIDE.md Developer Documentation section 54 | - [x] Emphasize the single-file EFI nature and Docker as the recommended build approach 55 | 56 | 4. **Documentation Consolidation** 57 | - [x] Consolidated all documentation into the USER_GUIDE.md instead of separate files 58 | - [x] Added Developer Documentation section to USER_GUIDE.md 59 | - [x] Emphasized the importance of small image size and single-file EFI nature 60 | - [x] Highlighted Docker as the recommended cross-platform build method 61 | 62 | ## Future Documentation Improvements 63 | 64 | 1. **Enhanced Visual Documentation** 65 | - [ ] Add diagrams showing the build process flow 66 | - [ ] Create visual representations of the feature flag relationships 67 | - [ ] Add screenshots of the build process and output 68 | 69 | 2. **Advanced Developer Tutorials** 70 | - [ ] Create a step-by-step guide for adding new packages 71 | - [ ] Document the process for adding new hardware support 72 | - [ ] Create examples of common development tasks 73 | 74 | 3. **Performance Benchmarking** 75 | - [ ] Document build time comparisons across different environments 76 | - [ ] Create size impact analysis for different feature flags 77 | - [ ] Benchmark boot times on different hardware 78 | 79 | _The documentation now properly reflects the sophisticated architecture of OneFileLinux, with emphasis on its core features as a small single-file EFI executable and the Docker-based cross-platform build approach._ -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | # OneFileLinux Docker Build System 2 | 3 | This directory contains files for building OneFileLinux using Docker, providing a consistent build environment regardless of host system. 4 | 5 | ## Features 6 | 7 | - Isolated build environment with all dependencies pre-installed 8 | - Consistent builds across different host platforms (Linux, macOS, Windows) 9 | - Efficient build caching for faster rebuilds 10 | - Proper permission handling between container and host 11 | - Support for all OneFileLinux build options 12 | - Volume mounting for persistent build artifacts 13 | - Easy to use command-line interface 14 | 15 | ## Prerequisites 16 | 17 | - Docker (Docker Desktop for macOS/Windows, Docker Engine for Linux) 18 | - Docker Compose (included with Docker Desktop or install separately) 19 | - At least 4GB of free memory 20 | - At least 10GB of free disk space 21 | 22 | ## Quick Start 23 | 24 | 1. Make the build script executable: 25 | ```bash 26 | chmod +x build-onefilelinux.sh 27 | ``` 28 | 29 | 2. Run the build with default settings: 30 | ```bash 31 | ./build-onefilelinux.sh 32 | ``` 33 | 34 | 3. For a full build with all features: 35 | ```bash 36 | ./build-onefilelinux.sh -b "--full" 37 | ``` 38 | 39 | 4. For a minimal build: 40 | ```bash 41 | ./build-onefilelinux.sh -b "--minimal" 42 | ``` 43 | 44 | ## Configuration 45 | 46 | You can configure the build by: 47 | 48 | 1. Creating a `.env` file (copy from `.env.example`) and modifying variables 49 | 2. Using command-line arguments with the `-b` or `--build-args` option 50 | 51 | Example `.env` file: 52 | ``` 53 | BUILD_ARGS=--minimal --use-cache 54 | HOST_UID=1000 55 | HOST_GID=1000 56 | ``` 57 | 58 | ## Command Line Options 59 | 60 | The `build-onefilelinux.sh` script supports several options: 61 | 62 | ``` 63 | Usage: ./build-onefilelinux.sh [options] 64 | 65 | Options: 66 | -h, --help Display this help message 67 | -c, --clean Clean the Docker environment before building 68 | -v, --verbose Enable verbose output 69 | -b, --build-args ARG Pass build arguments to the build script 70 | -e, --env-file FILE Specify a custom .env file 71 | -i, --interactive Run in interactive mode (shell inside container) 72 | -p, --pull Pull the latest base image before building 73 | --no-cache Build the Docker image without using cache 74 | ``` 75 | 76 | ## Directory Structure 77 | 78 | - `Dockerfile`: Defines the containerized build environment 79 | - `docker-compose.yml`: Configuration for Docker Compose 80 | - `build-onefilelinux.sh`: Main build script to interact with the Docker environment 81 | - `entrypoint.sh`: Docker container entry point that bootstraps the build process 82 | - `auto-resources.sh`: Helper script to automatically detect and configure system resources 83 | - `.env.example`: Example environment variable file 84 | 85 | ## Build Artifacts 86 | 87 | After a successful build, the output file (`OneFileLinux.efi`) will be placed in the `../output/` directory relative to this directory. 88 | 89 | ## Troubleshooting 90 | 91 | ### Build Fails with Permission Errors 92 | 93 | If you encounter permission errors, try: 94 | 1. Ensuring the `HOST_UID` and `HOST_GID` are set correctly in the `.env` file 95 | 2. Running the build script with the `-c` option to clean the environment 96 | 3. Running Docker with appropriate privileges 97 | 98 | ### Container Runs Out of Memory 99 | 100 | If the build process runs out of memory: 101 | 1. Increase Docker's memory allocation in Docker Desktop settings 102 | 2. Add `DOCKER_MEMORY=8g` to your `.env` file 103 | 3. Use the `--use-swap` build option to enable swap inside the build 104 | 105 | ### Slow Build Performance 106 | 107 | To improve build performance: 108 | 1. Use the `--use-cache` build option (enabled by default) 109 | 2. Increase Docker's CPU allocation 110 | 3. Use SSD storage for Docker volumes 111 | 112 | ## Advanced Usage 113 | 114 | ### Interactive Mode 115 | 116 | You can enter an interactive shell in the container for debugging or manual builds: 117 | 118 | ```bash 119 | ./build-onefilelinux.sh -i 120 | ``` 121 | 122 | ### Custom Build Steps 123 | 124 | To run specific build steps: 125 | 126 | ```bash 127 | ./build-onefilelinux.sh -i 128 | # Inside the container: 129 | cd /onefilelinux/build 130 | ./build.sh get # Only run the download step 131 | ./build.sh build # Only run the build step 132 | ``` 133 | 134 | ### Clearing the Cache 135 | 136 | To clear the build cache: 137 | 138 | ```bash 139 | ./build-onefilelinux.sh -c 140 | ``` 141 | 142 | ## Integration with CI/CD 143 | 144 | This Docker build system can be easily integrated with CI/CD pipelines like GitHub Actions. See the `.github/workflows` directory for examples. 145 | 146 | ## Build System Architecture 147 | 148 | The Docker build system has been integrated with the standardized library-based build system: 149 | 150 | 1. **Library-Based Build**: The Docker entrypoint automatically detects and uses the library system (80-89 range): 151 | - `80_common.sh`: Logging, banners, environment detection 152 | - `81_error_handling.sh`: Error handling and prerequisite checks 153 | - `82_build_helper.sh`: Docker-specific functions for extraction and file handling 154 | - `83_config_helper.sh`: Configuration management 155 | 156 | 2. **Fallback Mode**: If the library files are not detected, the system falls back to the legacy build process using build.sh directly 157 | 158 | 3. **Environment Detection**: The container automatically marks `IN_DOCKER_CONTAINER=true` for proper environment-specific handling -------------------------------------------------------------------------------- /docker/README-prebuilt.md: -------------------------------------------------------------------------------- 1 | # OneFileLinux Prebuilt Docker Container 2 | 3 | This document explains how to use the prebuilt OneFileLinux build environment container. 4 | 5 | ## Why Use a Prebuilt Container? 6 | 7 | The prebuilt container offers several advantages: 8 | 9 | 1. **Instant Start**: No need to build the container from scratch each time 10 | 2. **All Dependencies Included**: All required build tools are pre-installed 11 | 3. **Resources Pre-Downloaded**: Alpine rootfs and other components are pre-cached 12 | 4. **CI/CD Ready**: Optimized for use in continuous integration pipelines 13 | 5. **Consistent Environment**: Identical build environment across all systems 14 | 15 | ## Quick Start 16 | 17 | ### Pull the Container 18 | 19 | ```bash 20 | # Pull the latest container image 21 | docker pull ghcr.io/onefilelinux/builder:latest 22 | ``` 23 | 24 | ### Build OneFileLinux 25 | 26 | ```bash 27 | # Create an output directory 28 | mkdir -p output 29 | 30 | # Run the container with the output directory mounted 31 | docker run -it --rm \ 32 | -v "$(pwd)/output:/onefilelinux/output" \ 33 | ghcr.io/onefilelinux/builder:latest 34 | ``` 35 | 36 | ### Build with Options 37 | 38 | ```bash 39 | # Build minimal version 40 | docker run -it --rm \ 41 | -v "$(pwd)/output:/onefilelinux/output" \ 42 | ghcr.io/onefilelinux/builder:latest ./build.sh --minimal 43 | 44 | # Build full version with ZFS support 45 | docker run -it --rm \ 46 | -v "$(pwd)/output:/onefilelinux/output" \ 47 | ghcr.io/onefilelinux/builder:latest ./build.sh --full --with-zfs 48 | ``` 49 | 50 | ## Using with Docker Compose 51 | 52 | Create a `docker-compose.yml` file: 53 | 54 | ```yaml 55 | services: 56 | onefilelinux-builder: 57 | image: ghcr.io/onefilelinux/builder:latest 58 | container_name: onefilelinux-builder 59 | volumes: 60 | # Mount output directory 61 | - ./output:/onefilelinux/output:rw 62 | environment: 63 | # Configure build arguments here 64 | - BUILD_ARGS=--with-zfs --with-recovery-tools 65 | # Ensure feature variables propagate to all scripts 66 | - INCLUDE_ZFS=true 67 | - INCLUDE_MINIMAL_KERNEL=false 68 | - INCLUDE_NETWORK_TOOLS=true 69 | - INCLUDE_CRYPTO=true 70 | # Enable any required capabilities 71 | cap_add: 72 | - SYS_ADMIN # Required for chroot operations 73 | # Enable privileged mode for complex operations like loop devices 74 | privileged: true 75 | ``` 76 | 77 | Then run: 78 | 79 | ```bash 80 | docker-compose up 81 | ``` 82 | 83 | ## Customizing the Build Environment 84 | 85 | ### Environment Variables 86 | 87 | The container supports several environment variables for customization: 88 | 89 | - `BUILD_ARGS`: Additional build arguments to pass to build.sh 90 | - `INCLUDE_ZFS`: Include ZFS support (true/false) 91 | - `INCLUDE_MINIMAL_KERNEL`: Use minimal kernel configuration (true/false) 92 | - `INCLUDE_NETWORK_TOOLS`: Include network tools (true/false) 93 | - `INCLUDE_CRYPTO`: Include crypto support (true/false) 94 | 95 | Example: 96 | 97 | ```bash 98 | docker run -it --rm \ 99 | -v "$(pwd)/output:/onefilelinux/output" \ 100 | -e INCLUDE_ZFS=false \ 101 | -e INCLUDE_MINIMAL_KERNEL=true \ 102 | ghcr.io/onefilelinux/builder:latest 103 | ``` 104 | 105 | ### Interactive Shell 106 | 107 | Access an interactive shell in the container: 108 | 109 | ```bash 110 | docker run -it --rm \ 111 | -v "$(pwd)/output:/onefilelinux/output" \ 112 | ghcr.io/onefilelinux/builder:latest /bin/bash 113 | ``` 114 | 115 | ## Using in CI/CD Pipelines 116 | 117 | ### GitHub Actions Example 118 | 119 | ```yaml 120 | name: Build OneFileLinux 121 | 122 | on: 123 | push: 124 | branches: [ main ] 125 | pull_request: 126 | branches: [ main ] 127 | 128 | jobs: 129 | build: 130 | runs-on: ubuntu-latest 131 | container: 132 | image: ghcr.io/onefilelinux/builder:latest 133 | options: --privileged 134 | 135 | steps: 136 | - uses: actions/checkout@v3 137 | with: 138 | path: src 139 | 140 | - name: Build OneFileLinux 141 | run: | 142 | cd /onefilelinux/build 143 | ./build.sh --standard 144 | 145 | - name: Upload Artifacts 146 | uses: actions/upload-artifact@v3 147 | with: 148 | name: onefilelinux-efi 149 | path: /onefilelinux/output/*.efi 150 | ``` 151 | 152 | ### GitLab CI Example 153 | 154 | ```yaml 155 | build: 156 | image: 157 | name: ghcr.io/onefilelinux/builder:latest 158 | entrypoint: [""] 159 | script: 160 | - cd /onefilelinux/build 161 | - ./build.sh --standard 162 | artifacts: 163 | paths: 164 | - /onefilelinux/output/*.efi 165 | ``` 166 | 167 | ## Building Your Own Prebuilt Container 168 | 169 | You can build and publish your own version of the container using the provided script: 170 | 171 | ```bash 172 | # Make the script executable 173 | chmod +x docker/build-container-image.sh 174 | 175 | # Build the container locally 176 | ./docker/build-container-image.sh 177 | 178 | # Build and push to a registry 179 | ./docker/build-container-image.sh --push --registry myregistry.com --username myuser --org myorg 180 | ``` 181 | 182 | ## Troubleshooting 183 | 184 | ### Permission Issues 185 | 186 | If you encounter permission issues with the output directory: 187 | 188 | ```bash 189 | # Run the container as your user ID 190 | docker run -it --rm \ 191 | -v "$(pwd)/output:/onefilelinux/output" \ 192 | -e HOST_UID=$(id -u) \ 193 | -e HOST_GID=$(id -g) \ 194 | ghcr.io/onefilelinux/builder:latest 195 | ``` 196 | 197 | ### Resource Constraints 198 | 199 | If the build fails due to resource constraints: 200 | 201 | ```bash 202 | # Allocate more resources 203 | docker run -it --rm \ 204 | -v "$(pwd)/output:/onefilelinux/output" \ 205 | --memory=8g --cpus=4 \ 206 | ghcr.io/onefilelinux/builder:latest 207 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OneFileLinux 2 | 3 | OneFileLinux is a single-file EFI-based Linux recovery environment designed for data recovery, system repair, and diagnostics. 4 | 5 | OneFileLinux 6 | 7 | ## Project Revival and Enhancements 8 | 9 | OneFileLinux has been revived and massively overhauled with a focus on modern systems and advanced recovery capabilities: 10 | 11 | - **Modern Architecture**: Completely rebuilt with a modular, maintainable codebase 12 | - **Latest Technology**: Updated to Linux kernel 6.12 and Alpine Linux 3.21 13 | - **Advanced File Systems**: Full ZFS and Btrfs support for modern storage solutions 14 | - **Flexible Building**: Modular build system with minimal to full-featured options 15 | - **Robust Error Handling**: Comprehensive error detection and recovery mechanisms 16 | - **CI/CD Integration**: Automated builds and testing with GitHub Actions 17 | - **Docker Support**: Containerized build environment for consistent results 18 | 19 | ## Why OneFileLinux? 20 | 21 | OneFileLinux provides a powerful system recovery solution with unique advantages: 22 | 23 | - **Zero Installation Required**: No need to create additional partitions or modify your system 24 | - **No External Media Needed**: Once copied to your EFI partition, it's always available 25 | - **Boot Directly From UEFI**: No additional boot managers required 26 | - **Works With Encrypted Disks**: Compatible with FileVault, BitLocker, and dm-crypt 27 | - **Leave No Trace**: Configure for one-time boot without changing default boot sequence 28 | - **Hardware-Level Access**: Direct access to hardware not available in virtual machines 29 | 30 | ## Features 31 | 32 | - **Single EFI File**: Boots directly from UEFI without additional bootloaders 33 | - **Advanced Filesystems**: Support for ZFS, Btrfs, ext4, XFS, and more 34 | - **Hardware Diagnostics**: Tools for hardware testing and analysis 35 | - **Network Support**: Ethernet, WiFi, and remote recovery capabilities 36 | - **Data Recovery**: Specialized tools for rescuing data from failed systems 37 | - **Boot Repair**: Tools to fix common boot problems across operating systems 38 | - **Text UI**: Full-featured text-based user interface for easy navigation 39 | - **Ultra Size Optimized**: Minimal builds around 7.5MB, standard builds around 50MB 40 | 41 | ## Getting Started 42 | 43 | ### Building with Docker (Recommended) 44 | 45 | The easiest way to build OneFileLinux is using Docker, which provides a consistent build environment: 46 | 47 | ```bash 48 | # Clone the repository 49 | git clone https://github.com/zhovner/OneFileLinux.git 50 | cd OneFileLinux/docker 51 | 52 | # Build with default settings 53 | ./build-onefilelinux.sh 54 | 55 | # Or build with specific options 56 | ./build-onefilelinux.sh -b "--full" 57 | ./build-onefilelinux.sh -b "--minimal" 58 | ``` 59 | 60 | See the [Docker build documentation](docker/README.md) for more details. 61 | 62 | ### Building Natively 63 | 64 | If you prefer to build on your local system: 65 | 66 | ```bash 67 | # Install build dependencies (Ubuntu/Debian example) 68 | sudo apt-get update 69 | sudo apt-get install build-essential git autoconf automake libtool \ 70 | util-linux libelf-dev libssl-dev zlib1g-dev libzstd-dev liblz4-dev \ 71 | upx xz-utils zstd curl wget sudo python3 gcc g++ make patch \ 72 | libncurses-dev e2fsprogs coreutils mtools xorriso squashfs-tools 73 | 74 | # Clone the repository 75 | git clone https://github.com/zhovner/OneFileLinux.git 76 | cd OneFileLinux 77 | 78 | # Run the build 79 | cd build 80 | ./build.sh 81 | ``` 82 | 83 | #### Note for macOS Users 84 | 85 | macOS comes with an older version of Bash (3.2) that doesn't support associative arrays needed by the build system. To build on macOS: 86 | 87 | 1. Install a newer Bash with Homebrew: `brew install bash` 88 | 2. Run the build with the newer Bash: `/usr/local/bin/bash build.sh` 89 | 90 | ```bash 91 | # macOS with Homebrew 92 | brew install bash coreutils automake make gnu-sed 93 | /usr/local/bin/bash build.sh 94 | ``` 95 | 96 | ## Build Options 97 | 98 | OneFileLinux offers several build configurations to balance features and size: 99 | 100 | | Build Type | Description | Size | Command | 101 | |------------|-------------|------|---------| 102 | | Minimal | Core functionality only | ~7.5MB | `--minimal` | 103 | | Standard | Basic recovery features | ~50MB | (default) | 104 | | Full | All features and tools | ~70-90MB | `--full` | 105 | 106 | ### Advanced Package Groups 107 | 108 | You can customize your build with these package groups: 109 | 110 | | Package Group | Size Impact | Description | Flag | Included Packages | 111 | |---------------|-------------|-------------|------|-------------------| 112 | | Advanced FS | ~10MB | Extra filesystem tools | `--with-advanced-fs` | ntfs-3g, xfsprogs, gptfdisk, exfatprogs, f2fs-tools | 113 | | Disk Diagnostics | ~15MB | Hardware testing tools | `--with-disk-diag` | smartmontools, hdparm, nvme-cli, dmidecode, lshw | 114 | | Network Diagnostics | ~12MB | Network diagnostics | `--with-network-diag` | ethtool, nmap, wireguard-tools, openvpn | 115 | | System Tools | ~8MB | Advanced system utilities | `--with-system-tools` | htop, strace, pciutils, usbutils | 116 | | Data Recovery | ~20MB | Data rescue utilities | `--with-data-recovery` | testdisk (includes photorec) | 117 | | Boot Repair | ~15MB | Bootloader repair tools | `--with-boot-repair` | grub | 118 | | Advanced Editors | ~5MB | Text editors and tools | `--with-editors` | vim, tmux, jq | 119 | | Security Tools | ~10MB | Security analysis tools | `--with-security` | openssl | 120 | 121 | ## Installation 122 | 123 | 1. Copy the generated `OneFileLinux.efi` to your EFI System Partition (ESP): 124 | ```bash 125 | sudo mkdir -p /boot/efi/EFI/OneFileLinux 126 | sudo cp output/OneFileLinux.efi /boot/efi/EFI/OneFileLinux/ 127 | ``` 128 | 129 | 2. Add a boot entry (optional, you can also boot it directly from UEFI): 130 | ```bash 131 | sudo efibootmgr --create --disk /dev/sda --part 1 --label "OneFileLinux" --loader '\EFI\OneFileLinux\OneFileLinux.efi' 132 | ``` 133 | 134 | 3. Boot into UEFI and select OneFileLinux from the boot menu. 135 | 136 | For detailed installation instructions for macOS, Windows, and creating bootable USB drives, see the [User Guide](docs/USER_GUIDE.md). 137 | 138 | ## EFI Partition Size Considerations 139 | 140 | When planning to use OneFileLinux, keep in mind these EFI partition size guidelines: 141 | 142 | - **Minimal build**: 100MB EFI partition is sufficient 143 | - **Standard build**: 100MB EFI partition is typically sufficient 144 | - **Full build**: 300MB EFI partition recommended 145 | 146 | Most modern systems have EFI partitions ranging from 100MB to 300MB. 147 | 148 | ## Documentation 149 | 150 | - [User Guide](docs/USER_GUIDE.md) 151 | - [Docker Build Instructions](docker/README.md) 152 | - [Future Improvements](FUTURE_IMPROVEMENTS.md) 153 | - [Contributing Guidelines](CONTRIBUTING.md) 154 | 155 | ## License 156 | 157 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 158 | 159 | ## Acknowledgements 160 | 161 | - Based on Alpine Linux 162 | - Uses the Linux kernel 163 | - ZFS implementation from OpenZFS 164 | - Many open source recovery tools 165 | 166 | ## Contributing 167 | 168 | Contributions are welcome! Please see our [Contributing Guidelines](CONTRIBUTING.md) for more information. -------------------------------------------------------------------------------- /docker/build-container-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # OneFileLinux Docker Container Image Builder 4 | # This script builds and publishes a ready-to-use Docker image with the complete build environment 5 | 6 | # Script directory 7 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 8 | PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" 9 | 10 | # Define colors for output 11 | GREEN='\033[0;32m' 12 | BLUE='\033[0;34m' 13 | YELLOW='\033[0;33m' 14 | RED='\033[0;31m' 15 | NC='\033[0m' # No Color 16 | 17 | # Banner function 18 | print_banner() { 19 | echo -e "${BLUE}" 20 | echo " ____________ " 21 | echo " /|------------| " 22 | echo " /_| .---. | " 23 | echo " | / \ | " 24 | echo " | \.6-6./ | " 25 | echo " | /\`\_/\`\ | " 26 | echo " | // _ \\\ | " 27 | echo " | | \ / | | " 28 | echo " | /\`\_\`> <_/\`\ | " 29 | echo " | \__/'---'\__/ | " 30 | echo " |_______________| " 31 | echo " " 32 | echo -e "${GREEN} OneFileLinux Container Image Builder ${NC}" 33 | echo "----------------------------------------------------" 34 | } 35 | 36 | # Usage information 37 | usage() { 38 | echo "Usage: $0 [options]" 39 | echo "" 40 | echo "Options:" 41 | echo " -h, --help Display this help message" 42 | echo " -t, --tag TAG Custom tag for the Docker image (default: latest)" 43 | echo " -p, --pull Pull the latest base image before building" 44 | echo " --no-cache Build the Docker image without using cache" 45 | echo " --push Push the image to registry after building" 46 | echo " -r, --registry URL Registry to push to (default: ghcr.io)" 47 | echo " -u, --username USER Username for registry authentication" 48 | echo " -o, --org ORG Organization name for the image (default: local)" 49 | echo "" 50 | echo "Examples:" 51 | echo " $0 Build with default settings as onefilelinux-builder:latest" 52 | echo " $0 -t v1.0 Build with tag v1.0" 53 | echo " $0 --push -o myorg Build and push to myorg/onefilelinux-builder:latest" 54 | echo "" 55 | } 56 | 57 | # Parse command line arguments 58 | TAG="latest" 59 | PULL=false 60 | NO_CACHE=false 61 | PUSH=false 62 | REGISTRY="ghcr.io" 63 | USERNAME="" 64 | ORG="local" 65 | 66 | while [[ $# -gt 0 ]]; do 67 | case $1 in 68 | -h|--help) 69 | usage 70 | exit 0 71 | ;; 72 | -t|--tag) 73 | TAG=$2 74 | shift 2 75 | ;; 76 | -p|--pull) 77 | PULL=true 78 | shift 79 | ;; 80 | --no-cache) 81 | NO_CACHE=true 82 | shift 83 | ;; 84 | --push) 85 | PUSH=true 86 | shift 87 | ;; 88 | -r|--registry) 89 | REGISTRY=$2 90 | shift 2 91 | ;; 92 | -u|--username) 93 | USERNAME=$2 94 | shift 2 95 | ;; 96 | -o|--org) 97 | ORG=$2 98 | shift 2 99 | ;; 100 | *) 101 | echo -e "${RED}Error: Unknown option $1${NC}" 102 | usage 103 | exit 1 104 | ;; 105 | esac 106 | done 107 | 108 | # Print banner 109 | print_banner 110 | 111 | # Check if Docker is installed 112 | if ! command -v docker &> /dev/null; then 113 | echo -e "${RED}Error: Docker is not installed or not in the PATH.${NC}" 114 | echo "Please install Docker first:" 115 | echo " - macOS: https://docs.docker.com/desktop/install/mac/" 116 | echo " - Linux: https://docs.docker.com/engine/install/" 117 | echo " - Windows: https://docs.docker.com/desktop/install/windows/" 118 | exit 1 119 | fi 120 | 121 | # Check if Docker is running 122 | if ! docker info &> /dev/null; then 123 | echo -e "${RED}Error: Docker daemon is not running.${NC}" 124 | echo "Please start Docker Desktop or the Docker service before continuing." 125 | exit 1 126 | fi 127 | 128 | # Set up image name 129 | IMAGE_NAME="${ORG}/onefilelinux-builder:${TAG}" 130 | if [ "$REGISTRY" != "" ] && [ "$REGISTRY" != "docker.io" ]; then 131 | FULL_IMAGE_NAME="${REGISTRY}/${IMAGE_NAME}" 132 | else 133 | FULL_IMAGE_NAME="${IMAGE_NAME}" 134 | fi 135 | 136 | echo -e "${BLUE}[INFO]${NC} Building Docker image: ${FULL_IMAGE_NAME}" 137 | 138 | # Pull the latest base image if requested 139 | if [ "$PULL" = true ]; then 140 | echo -e "${BLUE}[INFO]${NC} Pulling latest Alpine base image..." 141 | docker pull alpine:latest 142 | echo -e "${GREEN}[SUCCESS]${NC} Base image updated." 143 | fi 144 | 145 | # Set up build arguments 146 | BUILD_ARGS="" 147 | if [ "$NO_CACHE" = true ]; then 148 | BUILD_ARGS="--no-cache" 149 | fi 150 | 151 | # Change to the docker directory 152 | cd "$SCRIPT_DIR" 153 | 154 | # Create an updated Dockerfile that includes the init scripts 155 | echo -e "${BLUE}[INFO]${NC} Creating Dockerfile with init support..." 156 | 157 | # Create a temporary modified Dockerfile 158 | cp Dockerfile Dockerfile.ready 159 | 160 | # Add init scripts by modifying the Dockerfile 161 | # We'll insert setup code near the WORKDIR line 162 | sed -i.bak '/WORKDIR \/onefilelinux/i \ 163 | # Pre-initialize the build environment \ 164 | RUN mkdir -p /onefilelinux/build /onefilelinux/output \ 165 | /onefilelinux/.buildcache/sources \ 166 | /onefilelinux/.buildcache/packages \ 167 | /onefilelinux/.buildcache/ccache \ 168 | /onefilelinux/.buildcache/build \ 169 | && chown -R builder:builder /onefilelinux\n\ 170 | # Download Alpine minirootfs for reuse \ 171 | RUN mkdir -p /onefilelinux/.buildcache/sources && \\\n\ 172 | cd /onefilelinux/.buildcache/sources && \\\n\ 173 | wget -q https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.3-x86_64.tar.gz && \\\n\ 174 | chown builder:builder alpine-minirootfs-3.21.3-x86_64.tar.gz\n\ 175 | # Copy build scripts \ 176 | COPY --chown=builder:builder ../build/*.sh /onefilelinux/build/\n\ 177 | # Copy tools \ 178 | COPY --chown=builder:builder ../build/tools/*.sh /onefilelinux/build/tools/\n\ 179 | # Copy zfiles \ 180 | COPY --chown=builder:builder ../build/zfiles /onefilelinux/build/zfiles/\n\ 181 | # Copy kernel configs \ 182 | COPY --chown=builder:builder ../build/kernel-configs /onefilelinux/build/kernel-configs/\n\ 183 | # Make scripts executable \ 184 | RUN chmod +x /onefilelinux/build/*.sh /onefilelinux/build/tools/*.sh\n\ 185 | # Pre-extract Alpine minirootfs to speed up initial build \ 186 | RUN cd /onefilelinux/build && \\\n\ 187 | ln -sf /onefilelinux/.buildcache/sources/alpine-minirootfs-3.21.3-x86_64.tar.gz .\n 188 | ' Dockerfile.ready 189 | 190 | # Build the Docker image 191 | echo -e "${BLUE}[INFO]${NC} Building Docker image..." 192 | docker build $BUILD_ARGS -t "${IMAGE_NAME}" -f Dockerfile.ready . 193 | BUILD_RESULT=$? 194 | 195 | # Clean up temporary Dockerfile 196 | rm -f Dockerfile.ready Dockerfile.ready.bak 197 | 198 | if [ $BUILD_RESULT -ne 0 ]; then 199 | echo -e "${RED}[ERROR]${NC} Docker image build failed." 200 | exit 1 201 | fi 202 | 203 | echo -e "${GREEN}[SUCCESS]${NC} Docker image built successfully: ${IMAGE_NAME}" 204 | 205 | # Tag with registry name if pushing 206 | if [ "$PUSH" = true ]; then 207 | echo -e "${BLUE}[INFO]${NC} Tagging image for registry: ${FULL_IMAGE_NAME}" 208 | docker tag "${IMAGE_NAME}" "${FULL_IMAGE_NAME}" 209 | 210 | # Login to registry if username provided 211 | if [ -n "$USERNAME" ]; then 212 | echo -e "${BLUE}[INFO]${NC} Logging in to registry ${REGISTRY}..." 213 | echo "Enter your registry password:" 214 | docker login "${REGISTRY}" -u "${USERNAME}" 215 | LOGIN_RESULT=$? 216 | 217 | if [ $LOGIN_RESULT -ne 0 ]; then 218 | echo -e "${RED}[ERROR]${NC} Failed to login to registry." 219 | exit 1 220 | fi 221 | fi 222 | 223 | echo -e "${BLUE}[INFO]${NC} Pushing image to registry: ${FULL_IMAGE_NAME}" 224 | docker push "${FULL_IMAGE_NAME}" 225 | PUSH_RESULT=$? 226 | 227 | if [ $PUSH_RESULT -ne 0 ]; then 228 | echo -e "${RED}[ERROR]${NC} Failed to push image to registry." 229 | exit 1 230 | fi 231 | 232 | echo -e "${GREEN}[SUCCESS]${NC} Image pushed to registry: ${FULL_IMAGE_NAME}" 233 | fi 234 | 235 | echo -e "${BLUE}[INFO]${NC} Creating README with usage instructions..." 236 | 237 | cat > README.container.md << EOF 238 | # OneFileLinux Builder Container 239 | 240 | This container provides a complete, ready-to-use build environment for OneFileLinux. 241 | 242 | ## Quick Start 243 | 244 | ```bash 245 | # Pull the image 246 | docker pull ${FULL_IMAGE_NAME} 247 | 248 | # Run with mounted volumes for output 249 | docker run -it --rm \\ 250 | -v \$(pwd)/output:/onefilelinux/output \\ 251 | ${FULL_IMAGE_NAME} 252 | ``` 253 | 254 | ## Advanced Usage 255 | 256 | ### Building with Custom Options 257 | 258 | ```bash 259 | # Run with specific build options 260 | docker run -it --rm \\ 261 | -v \$(pwd)/output:/onefilelinux/output \\ 262 | ${FULL_IMAGE_NAME} ./build.sh --minimal 263 | ``` 264 | 265 | ### Interactive Shell 266 | 267 | ```bash 268 | # Get an interactive shell in the container 269 | docker run -it --rm \\ 270 | -v \$(pwd)/output:/onefilelinux/output \\ 271 | ${FULL_IMAGE_NAME} /bin/bash 272 | ``` 273 | 274 | ### Custom Build Steps 275 | 276 | ```bash 277 | # Run only specific build steps 278 | docker run -it --rm \\ 279 | -v \$(pwd)/output:/onefilelinux/output \\ 280 | ${FULL_IMAGE_NAME} /bin/bash -c "cd /onefilelinux/build && ./01_get.sh && ./02_chrootandinstall.sh" 281 | ``` 282 | 283 | ## Environment Variables 284 | 285 | - \`BUILD_ARGS\`: Additional build arguments to pass to build.sh 286 | - \`INCLUDE_ZFS\`: Include ZFS support (true/false) 287 | - \`INCLUDE_MINIMAL_KERNEL\`: Use minimal kernel configuration (true/false) 288 | - \`INCLUDE_NETWORK_TOOLS\`: Include network tools (true/false) 289 | - \`INCLUDE_CRYPTO\`: Include crypto support (true/false) 290 | 291 | Example: 292 | 293 | ```bash 294 | docker run -it --rm \\ 295 | -v \$(pwd)/output:/onefilelinux/output \\ 296 | -e INCLUDE_ZFS=false \\ 297 | -e INCLUDE_MINIMAL_KERNEL=true \\ 298 | ${FULL_IMAGE_NAME} 299 | ``` 300 | 301 | ## Resource Settings 302 | 303 | The container automatically adapts to available resources, but you can specify limits: 304 | 305 | ```bash 306 | docker run -it --rm \\ 307 | -v \$(pwd)/output:/onefilelinux/output \\ 308 | --memory=4g --cpus=2 \\ 309 | ${FULL_IMAGE_NAME} 310 | ``` 311 | 312 | ## Container Details 313 | 314 | This container includes: 315 | - All build dependencies pre-installed 316 | - Alpine Linux rootfs pre-downloaded 317 | - Build scripts and configuration files 318 | - CCache for faster rebuilds 319 | EOF 320 | 321 | echo -e "${GREEN}[SUCCESS]${NC} README created: README.container.md" 322 | 323 | # Final summary 324 | echo -e "${GREEN}[COMPLETE]${NC} OneFileLinux builder container image created successfully." 325 | echo -e "${BLUE}[INFO]${NC} Container image details:" 326 | echo " - Image name: ${FULL_IMAGE_NAME}" 327 | echo " - Ready to use with: docker run -it --rm -v \$(pwd)/output:/onefilelinux/output ${FULL_IMAGE_NAME}" 328 | echo "" 329 | echo -e "${BLUE}[INFO]${NC} To use this container in CI/CD pipelines:" 330 | echo " 1. Add this to your workflow:" 331 | echo " runs-on: ubuntu-latest" 332 | echo " container: ${FULL_IMAGE_NAME}" 333 | echo " 2. Mount output directory for artifacts" 334 | echo "" 335 | echo -e "${BLUE}[INFO]${NC} See README.container.md for detailed usage instructions." -------------------------------------------------------------------------------- /.github/workflows/docker-build.yml: -------------------------------------------------------------------------------- 1 | name: Docker Build 2 | 3 | on: 4 | push: 5 | # Only build on tags, not branches 6 | branches-ignore: ['**'] # Explicitly ignore all branches 7 | tags: 8 | - 'build-*' # Tags for builds only (no release) 9 | - 'v*' # Tags for builds with releases (e.g., v1.0.0) 10 | pull_request: 11 | branches: [master, main] 12 | paths-ignore: 13 | - '**.md' 14 | - 'docs/**' 15 | workflow_dispatch: 16 | inputs: 17 | build_type: 18 | description: 'Build type (minimal, standard, full)' 19 | required: true 20 | default: 'standard' 21 | type: choice 22 | options: 23 | - minimal 24 | - standard 25 | - full 26 | 27 | jobs: 28 | # Job to determine which builds to run based on trigger type 29 | setup: 30 | runs-on: ubuntu-latest 31 | outputs: 32 | matrix: ${{ steps.set-matrix.outputs.matrix }} 33 | release: ${{ steps.check-release.outputs.should_release }} 34 | steps: 35 | - id: check-release 36 | run: | 37 | # Check if this is a release tag (starts with 'v') 38 | if [[ "${{ github.ref }}" == refs/tags/v* ]]; then 39 | echo "should_release=true" >> $GITHUB_OUTPUT 40 | else 41 | echo "should_release=false" >> $GITHUB_OUTPUT 42 | fi 43 | 44 | - id: set-matrix 45 | run: | 46 | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then 47 | # For manual triggers, only build the selected type 48 | echo "matrix={\"include\":[{\"name\":\"${{ github.event.inputs.build_type }}\",\"build_args\":\"--profile=${{ github.event.inputs.build_type }} --compression-tool=upx\"}]}" >> $GITHUB_OUTPUT 49 | else 50 | # For automatic triggers, build all types with UPX compression 51 | echo "matrix={\"include\":[{\"name\":\"minimal\",\"build_args\":\"--profile=minimal --compression-tool=upx\"},{\"name\":\"standard\",\"build_args\":\"--profile=standard --compression-tool=upx\"},{\"name\":\"full\",\"build_args\":\"--profile=full --compression-tool=upx\"}]}" >> $GITHUB_OUTPUT 52 | fi 53 | 54 | # Build job using Docker with the same setup as local builds 55 | build: 56 | needs: setup 57 | runs-on: ubuntu-latest 58 | strategy: 59 | matrix: ${{fromJson(needs.setup.outputs.matrix)}} 60 | fail-fast: false 61 | 62 | name: Build OneFileLinux (${{ matrix.name }}) 63 | 64 | steps: 65 | - name: Checkout code 66 | uses: actions/checkout@v4 67 | 68 | - name: Set up build dependencies 69 | run: | 70 | sudo apt-get update 71 | sudo apt-get install -y build-essential gcc g++ make autoconf automake libtool libelf-dev upx-ucl unzip zstd xz-utils ccache uuid-dev libuuid1 libblkid-dev libtirpc-dev 72 | 73 | # Verify Docker is installed and running (GitHub Actions has Docker pre-installed) 74 | docker --version 75 | 76 | # Set up Docker Compose (either install it or create wrapper for docker compose plugin) 77 | if ! command -v docker-compose &> /dev/null; then 78 | echo "docker-compose command not found, setting up alternatives..." 79 | 80 | # First try to use docker compose plugin if available 81 | if docker compose version &> /dev/null; then 82 | echo "Docker Compose plugin is available, creating wrapper script" 83 | echo '#!/bin/bash 84 | docker compose "$@"' > /tmp/docker-compose 85 | chmod +x /tmp/docker-compose 86 | sudo mv /tmp/docker-compose /usr/local/bin/docker-compose 87 | else 88 | # If plugin not available, install docker-compose binary 89 | echo "Installing docker-compose from GitHub releases" 90 | sudo curl -L "https://github.com/docker/compose/releases/download/v2.24.6/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 91 | sudo chmod +x /usr/local/bin/docker-compose 92 | fi 93 | fi 94 | 95 | # Verify docker-compose is now available 96 | docker-compose --version || echo "Warning: docker-compose not available, will use docker compose plugin directly" 97 | 98 | # Create output directories with appropriate permissions and ensure docker can write to them 99 | mkdir -p build/output output 100 | sudo chown -R $(id -u):$(id -g) build output 101 | sudo chmod -R 777 build output 102 | 103 | # Create a .build_progress file with correct permissions if it doesn't exist 104 | touch build/.build_progress 105 | chmod 666 build/.build_progress 106 | 107 | # Make all scripts executable 108 | chmod -R +x build/*.sh docker/*.sh 109 | find build/tools -name "*.sh" -exec chmod +x {} \; 2>/dev/null || true 110 | 111 | - name: Cache Alpine kernel configs 112 | uses: actions/cache@v4 113 | with: 114 | path: build/zfiles/kernel-configs 115 | key: alpine-kernel-config-${{ hashFiles('build/80_common.sh') }} 116 | restore-keys: | 117 | alpine-kernel-config- 118 | 119 | - name: Set up ccache 120 | uses: actions/cache@v4 121 | with: 122 | path: ~/.ccache 123 | key: ccache-${{ runner.os }}-${{ matrix.name }}-${{ github.sha }} 124 | restore-keys: | 125 | ccache-${{ runner.os }}-${{ matrix.name }}- 126 | ccache-${{ runner.os }}- 127 | 128 | # Create custom env file for GitHub Actions using the same docker-compose setup as local 129 | - name: Configure build environment 130 | run: | 131 | # Create .env file with GitHub-specific settings 132 | cat > docker/.env << EOF 133 | # GitHub Actions build environment 134 | # Generated at $(date) 135 | 136 | # Build arguments from matrix 137 | BUILD_ARGS=${{ matrix.build_args }} 138 | 139 | # Resource allocations appropriate for GitHub runners 140 | DOCKER_MEMORY=7g 141 | DOCKER_CPUS=2 142 | 143 | # User ID mapping - use the runner's UID/GID 144 | HOST_UID=$(id -u) 145 | HOST_GID=$(id -g) 146 | 147 | # GitHub-specific settings 148 | GITHUB_ACTIONS=true 149 | 150 | # Run as root to avoid permission issues 151 | RUN_AS_ROOT=true 152 | RUN_AS_USER=root 153 | 154 | # Use default password 'onefilelinux' instead of generating a random one 155 | GENERATE_RANDOM_PASSWORD=false 156 | ROOT_PASSWORD=onefilelinux 157 | 158 | # Debug settings 159 | DEBUG_FEATURE_FLAGS=true 160 | EOF 161 | 162 | # Also prepare build directory for Docker entrypoint 163 | mkdir -p build/.onefilelinux 164 | touch build/.onefilelinux/host_uid_gid 165 | echo "$(id -u):$(id -g)" > build/.onefilelinux/host_uid_gid 166 | chmod 666 build/.onefilelinux/host_uid_gid 167 | 168 | # Create ccache directory with proper permissions 169 | mkdir -p ~/.ccache 170 | sudo chmod -R 777 ~/.ccache 171 | 172 | # Copy any existing kernel configs to the expected location 173 | mkdir -p build/zfiles/kernel-configs/features 174 | chmod -R 777 build/zfiles/kernel-configs 175 | 176 | # Run the build using the same docker-compose setup as local builds 177 | - name: Build OneFileLinux using Docker 178 | env: 179 | BUILD_ARGS: ${{ matrix.build_args }} 180 | GENERATE_RANDOM_PASSWORD: "false" 181 | ROOT_PASSWORD: "onefilelinux" 182 | run: | 183 | cd docker 184 | 185 | # Show configuration 186 | echo "Building with arguments: $BUILD_ARGS" 187 | cat .env 188 | 189 | # Set environment variables for Docker 190 | export HOST_UID=$(id -u) 191 | export HOST_GID=$(id -g) 192 | echo "Setting HOST_UID=$HOST_UID and HOST_GID=$HOST_GID in environment" 193 | 194 | # Use the local docker-compose setup for builds 195 | # Try both docker-compose and docker compose commands 196 | if command -v docker-compose &> /dev/null; then 197 | echo "Using docker-compose command" 198 | docker-compose up --build 199 | COMPOSE_EXIT_CODE=$? 200 | else 201 | echo "Using docker compose plugin directly" 202 | docker compose up --build 203 | COMPOSE_EXIT_CODE=$? 204 | fi 205 | 206 | # Check the exit code 207 | if [ $COMPOSE_EXIT_CODE -ne 0 ]; then 208 | echo "Docker build failed with exit code: $COMPOSE_EXIT_CODE" 209 | if command -v docker-compose &> /dev/null; then 210 | docker-compose logs 211 | else 212 | docker compose logs 213 | fi 214 | exit 1 215 | fi 216 | 217 | # Show output directory 218 | echo "Build output files:" 219 | ls -la ../output/ 220 | 221 | # If we need to apply any GitHub-specific fixes to output files, do it here 222 | 223 | - name: Check for build artifacts 224 | id: check_files 225 | run: | 226 | # Find all EFI files in the output directory 227 | echo "Searching for build artifacts in ./output/" 228 | ls -la ./output/ || true 229 | 230 | # Find EFI files (including those with custom names) 231 | EFI_FILES=$(find ./output/ -name "*.efi" | sort) 232 | 233 | if [ -n "$EFI_FILES" ]; then 234 | echo "efi_file=true" >> $GITHUB_OUTPUT 235 | 236 | # Check if we have a profile-specific EFI first 237 | PROFILE_EFI="./output/OneFileLinux-${{ matrix.name }}.efi" 238 | GENERIC_EFI="./output/OneFileLinux.efi" 239 | 240 | # Look for custom profile names (contain 'custom' in the name) 241 | CUSTOM_EFI=$(echo "$EFI_FILES" | grep -i "custom" | head -1) 242 | 243 | # Prioritize files in this order: Profile-specific > Custom > Generic 244 | if [ -f "$PROFILE_EFI" ]; then 245 | PRIMARY_EFI="$PROFILE_EFI" 246 | echo "efi_path=$PROFILE_EFI" >> $GITHUB_OUTPUT 247 | echo "Found profile-specific EFI file: $PROFILE_EFI" 248 | elif [ -n "$CUSTOM_EFI" ] && [ -f "$CUSTOM_EFI" ]; then 249 | PRIMARY_EFI="$CUSTOM_EFI" 250 | echo "efi_path=$CUSTOM_EFI" >> $GITHUB_OUTPUT 251 | echo "Found custom profile EFI file: $CUSTOM_EFI" 252 | elif [ -f "$GENERIC_EFI" ]; then 253 | PRIMARY_EFI="$GENERIC_EFI" 254 | echo "efi_path=$GENERIC_EFI" >> $GITHUB_OUTPUT 255 | echo "Found generic EFI file: $GENERIC_EFI" 256 | 257 | # Copy it to the profile-specific name for consistent artifacts 258 | cp "$GENERIC_EFI" "$PROFILE_EFI" 259 | echo "Copied to: $PROFILE_EFI" 260 | else 261 | # If none of the expected names are found, use the first EFI file 262 | PRIMARY_EFI=$(echo "$EFI_FILES" | head -1) 263 | echo "efi_path=$PRIMARY_EFI" >> $GITHUB_OUTPUT 264 | echo "Found alternative EFI file: $PRIMARY_EFI" 265 | fi 266 | 267 | # Show information about the primary EFI file 268 | du -h "$PRIMARY_EFI" 269 | 270 | # List all EFI files found (for comprehensive logging) 271 | echo "All EFI files found:" 272 | for efi in $EFI_FILES; do 273 | file_size=$(du -h "$efi" | cut -f1) 274 | echo "- $efi (Size: $file_size)" 275 | done 276 | else 277 | echo "efi_file=false" >> $GITHUB_OUTPUT 278 | echo "Build failed to produce any EFI file" 279 | ls -la ./output/ 280 | exit 1 281 | fi 282 | 283 | # Display timing data if available 284 | if [ -f "./build/build_timing.log" ]; then 285 | echo "Build Timing Data:" 286 | cat ./build/build_timing.log 287 | fi 288 | 289 | - name: Upload build artifact 290 | if: steps.check_files.outputs.efi_file == 'true' 291 | uses: actions/upload-artifact@v4 292 | with: 293 | name: OneFileLinux-${{ matrix.name }} 294 | # Upload all EFI files to ensure custom profiles are included 295 | path: | 296 | ./output/*.efi 297 | if-no-files-found: error 298 | 299 | - name: Upload build timing log 300 | if: always() 301 | uses: actions/upload-artifact@v4 302 | with: 303 | name: build-timing-log-${{ matrix.name }} 304 | path: ./build/build_timing.log 305 | if-no-files-found: warn 306 | 307 | # Release job - now conditional on the tag pattern only 308 | release: 309 | name: Package and Release 310 | needs: [setup, build] 311 | # Only run release job for 'v*' tags 312 | if: needs.setup.outputs.release == 'true' 313 | runs-on: ubuntu-latest 314 | steps: 315 | - name: Download all artifacts 316 | uses: actions/download-artifact@v4 317 | with: 318 | path: ./artifacts 319 | 320 | - name: Create release package 321 | run: | 322 | mkdir -p release 323 | 324 | # Copy all EFI files from each artifact directory to the release directory 325 | echo "Examining artifact directories:" 326 | ls -la ./artifacts/ 327 | 328 | # Loop through all artifact directories 329 | for artifact_dir in ./artifacts/OneFileLinux-*/; do 330 | if [ -d "$artifact_dir" ]; then 331 | echo "Processing artifact directory: $artifact_dir" 332 | ls -la "$artifact_dir" 333 | 334 | # Get the artifact name (last part of the directory path) 335 | artifact_name=$(basename "$artifact_dir") 336 | 337 | # Find all EFI files in the artifact directory 338 | for efi_file in "$artifact_dir"/*.efi; do 339 | if [ -f "$efi_file" ]; then 340 | # Use the original filename if it's profile-specific (contains a hyphen) 341 | # Otherwise rename it based on the artifact name 342 | efi_basename=$(basename "$efi_file") 343 | if [[ "$efi_basename" == *"-"* ]]; then 344 | # Already has a profile in the name, keep it 345 | cp "$efi_file" "./release/" 346 | echo "Copied $efi_file to ./release/$efi_basename (keeping original name)" 347 | else 348 | # Standard OneFileLinux.efi file, rename based on artifact 349 | profile_name=${artifact_name#OneFileLinux-} 350 | cp "$efi_file" "./release/OneFileLinux-$profile_name.efi" 351 | echo "Copied $efi_file to ./release/OneFileLinux-$profile_name.efi" 352 | fi 353 | fi 354 | done 355 | fi 356 | done 357 | 358 | # Handle special case for custom builds that might have a different naming pattern 359 | for artifact_dir in ./artifacts/OneFileLinux-custom*/; do 360 | if [ -d "$artifact_dir" ]; then 361 | echo "Processing custom artifact directory: $artifact_dir" 362 | # Copy all EFI files as-is 363 | for efi_file in "$artifact_dir"/*.efi; do 364 | if [ -f "$efi_file" ]; then 365 | cp "$efi_file" "./release/" 366 | echo "Copied custom build file: $efi_file" 367 | fi 368 | done 369 | fi 370 | done 371 | 372 | # Check what EFI files we have 373 | echo "Release files:" 374 | ls -la ./release/ 375 | 376 | # Create zip with all EFI files 377 | cd release 378 | zip -r OneFileLinux-release.zip *.efi 379 | 380 | - name: Upload release package 381 | uses: actions/upload-artifact@v4 382 | with: 383 | name: OneFileLinux-release 384 | path: ./release/OneFileLinux-release.zip 385 | 386 | # Create GitHub Release for v* tags 387 | - name: Create GitHub Release 388 | uses: softprops/action-gh-release@v1 389 | with: 390 | files: ./release/OneFileLinux-release.zip 391 | name: "OneFileLinux ${{ github.ref_name }}" 392 | draft: false 393 | prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-beta') || contains(github.ref, '-alpha') }} 394 | generate_release_notes: true -------------------------------------------------------------------------------- /docker/build-onefilelinux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # OneFileLinux Docker Build Script 4 | # This script launches the OneFileLinux build inside a Docker container 5 | 6 | # Script directory 7 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 8 | PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" 9 | 10 | # Define colors for output 11 | GREEN='\033[0;32m' 12 | BLUE='\033[0;34m' 13 | YELLOW='\033[0;33m' 14 | RED='\033[0;31m' 15 | NC='\033[0m' # No Color 16 | 17 | # Banner function 18 | print_banner() { 19 | echo -e "${BLUE}" 20 | echo " ____________ " 21 | echo " /|------------| " 22 | echo " /_| .---. | " 23 | echo " | / \ | " 24 | echo " | \.6-6./ | " 25 | echo " | /\`\_/\`\ | " 26 | echo " | // _ \\\ | " 27 | echo " | | \ / | | " 28 | echo " | /\`\_\`> <_/\`\ | " 29 | echo " | \__/'---'\__/ | " 30 | echo " |_______________| " 31 | echo " " 32 | echo -e "${GREEN} OneFileLinux Docker Builder ${NC}" 33 | echo "----------------------------------------------------" 34 | } 35 | 36 | # Usage information 37 | usage() { 38 | echo "Usage: $0 [options]" 39 | echo "" 40 | echo "Options:" 41 | echo " -h, --help Display this help message" 42 | echo " -c, --clean Clean the Docker environment before building" 43 | echo " -v, --verbose Enable verbose output" 44 | echo " -b, --build-args ARG Pass build arguments to the build script (uses the -- passthrough mechanism)" 45 | echo " -e, --env-file FILE Specify a custom .env file" 46 | echo " -i, --interactive Run in interactive mode (shell inside container)" 47 | echo " -p, --pull Pull the latest base image before building" 48 | echo " --no-cache Build the Docker image without using cache" 49 | echo " --make-verbose Enable verbose make output (V=1)" 50 | echo " --make-quiet Use quiet make output (V=0, default)" 51 | echo "" 52 | echo "Examples:" 53 | echo " $0 Build with default settings" 54 | echo " $0 -c Clean and rebuild" 55 | echo " $0 -b \"--minimal\" Build with minimal profile" 56 | echo " $0 -b \"--full\" Build with full profile" 57 | echo " $0 -b \"--standard\" Build with standard profile (default)" 58 | echo " $0 -b \"--minimal --dry-run\" Show minimal profile configuration without building" 59 | echo " $0 -i Launch interactive shell in the container" 60 | echo " $0 --max-resources Use maximum available system resources" 61 | echo " $0 --make-verbose Build with verbose make output (V=1)" 62 | echo " $0 --make-quiet Build with quiet make output (V=0, default)" 63 | echo "" 64 | } 65 | 66 | # Parse command line arguments 67 | CLEAN=false 68 | VERBOSE=false 69 | BUILD_ARGS="" 70 | ENV_FILE=".env" 71 | INTERACTIVE=false 72 | PULL=false 73 | NO_CACHE=false 74 | RESOURCES="balanced" 75 | MAKE_VERBOSE=0 76 | 77 | while [[ $# -gt 0 ]]; do 78 | case $1 in 79 | -h|--help) 80 | usage 81 | exit 0 82 | ;; 83 | -c|--clean) 84 | CLEAN=true 85 | shift 86 | ;; 87 | -v|--verbose) 88 | VERBOSE=true 89 | shift 90 | ;; 91 | -b|--build-args) 92 | BUILD_ARGS=$2 93 | shift 2 94 | ;; 95 | -e|--env-file) 96 | ENV_FILE=$2 97 | shift 2 98 | ;; 99 | -i|--interactive) 100 | INTERACTIVE=true 101 | shift 102 | ;; 103 | -p|--pull) 104 | PULL=true 105 | shift 106 | ;; 107 | --no-cache) 108 | NO_CACHE=true 109 | shift 110 | ;; 111 | --make-verbose) 112 | MAKE_VERBOSE=1 113 | # Append to existing build args if they exist 114 | if [[ -n "$BUILD_ARGS" ]]; then 115 | BUILD_ARGS="$BUILD_ARGS --make-verbose" 116 | else 117 | BUILD_ARGS="--make-verbose" 118 | fi 119 | shift 120 | ;; 121 | --make-quiet) 122 | MAKE_VERBOSE=0 123 | # Append to existing build args if they exist 124 | if [[ -n "$BUILD_ARGS" ]]; then 125 | BUILD_ARGS="$BUILD_ARGS --make-quiet" 126 | else 127 | BUILD_ARGS="--make-quiet" 128 | fi 129 | shift 130 | ;; 131 | *) 132 | echo -e "${RED}Error: Unknown option $1${NC}" 133 | usage 134 | exit 1 135 | ;; 136 | esac 137 | done 138 | 139 | # Print banner 140 | print_banner 141 | 142 | # Set the host user ID for consistent file ownership 143 | export HOST_UID=$(id -u) 144 | export HOST_GID=$(id -g) 145 | 146 | # Check if Docker is installed 147 | if ! command -v docker &> /dev/null; then 148 | echo -e "${RED}Error: Docker is not installed or not in the PATH.${NC}" 149 | echo "Please install Docker first:" 150 | echo " - macOS: https://docs.docker.com/desktop/install/mac/" 151 | echo " - Linux: https://docs.docker.com/engine/install/" 152 | echo " - Windows: https://docs.docker.com/desktop/install/windows/" 153 | exit 1 154 | fi 155 | 156 | # Check if Docker is running 157 | if ! docker info &> /dev/null; then 158 | echo -e "${RED}Error: Docker daemon is not running.${NC}" 159 | echo "Please start Docker Desktop or the Docker service before continuing." 160 | exit 1 161 | fi 162 | 163 | # Check if docker-compose is installed 164 | if ! command -v docker-compose &> /dev/null; then 165 | echo -e "${YELLOW}Warning: docker-compose not found, falling back to Docker Compose plugin.${NC}" 166 | COMPOSE_CMD="docker compose" 167 | else 168 | COMPOSE_CMD="docker-compose" 169 | fi 170 | 171 | # Make auto-resources.sh executable 172 | chmod +x "$SCRIPT_DIR/auto-resources.sh" 173 | 174 | # Determine resource allocation based on selected profile 175 | echo -e "${BLUE}[INFO]${NC} Detecting system resources..." 176 | 177 | # Get the resources from auto-resources.sh 178 | source "$SCRIPT_DIR/auto-resources.sh" --env > /dev/null 179 | echo -e "${BLUE}[INFO]${NC} Using detected available resources: $DOCKER_MEMORY RAM, $DOCKER_CPUS CPU cores" 180 | 181 | # Append resource flags to build arguments if not already specified 182 | if [[ "$BUILD_ARGS" != *"--jobs="* ]] && [[ -n "$BUILD_FLAGS" ]]; then 183 | BUILD_ARGS="$BUILD_ARGS $BUILD_FLAGS" 184 | fi 185 | 186 | # Create .env file for docker-compose 187 | cat > "$SCRIPT_DIR/.env" << EOF 188 | # Auto-generated environment file for OneFileLinux build 189 | # Generated on $(date) 190 | 191 | # Resource limits 192 | DOCKER_MEMORY=$DOCKER_MEMORY 193 | DOCKER_CPUS=$DOCKER_CPUS 194 | 195 | # Build arguments 196 | BUILD_ARGS=$BUILD_ARGS 197 | 198 | # User mapping 199 | HOST_UID=$HOST_UID 200 | HOST_GID=$HOST_GID 201 | EOF 202 | 203 | # Clean if requested 204 | if [ "$CLEAN" = true ]; then 205 | echo -e "${BLUE}[INFO]${NC} Cleaning up Docker environment..." 206 | cd "$SCRIPT_DIR" 207 | $COMPOSE_CMD down -v --rmi all 208 | echo -e "${GREEN}[SUCCESS]${NC} Docker environment cleaned." 209 | fi 210 | 211 | # Create output directory if it doesn't exist 212 | mkdir -p "$PROJECT_DIR/output" 213 | 214 | # Set verbose mode if requested 215 | if [ "$VERBOSE" = true ]; then 216 | export VERBOSE=true 217 | echo -e "${BLUE}[INFO]${NC} Verbose mode enabled." 218 | fi 219 | 220 | # Pull the latest base image if requested 221 | if [ "$PULL" = true ]; then 222 | echo -e "${BLUE}[INFO]${NC} Pulling latest Alpine base image..." 223 | docker pull alpine:latest 224 | echo -e "${GREEN}[SUCCESS]${NC} Base image updated." 225 | fi 226 | 227 | # Build options for docker-compose 228 | BUILD_OPTS="" 229 | if [ "$NO_CACHE" = true ]; then 230 | BUILD_OPTS="--build --no-cache" 231 | echo -e "${BLUE}[INFO]${NC} Building without cache." 232 | else 233 | BUILD_OPTS="--build" 234 | fi 235 | 236 | # Check if Docker Buildx is available for better performance 237 | if docker buildx version &>/dev/null; then 238 | echo -e "${BLUE}[INFO]${NC} Using Docker Buildx for improved build performance." 239 | export DOCKER_BUILDKIT=1 240 | export COMPOSE_DOCKER_CLI_BUILD=1 241 | else 242 | echo -e "${YELLOW}[WARNING]${NC} Docker Buildx not detected. Build performance may be reduced." 243 | fi 244 | 245 | # Change to the docker directory 246 | cd "$SCRIPT_DIR" 247 | 248 | # Show resource allocation 249 | echo -e "${BLUE}[INFO]${NC} Docker container resource allocation:" 250 | echo -e "${BLUE}[INFO]${NC} - Memory: $DOCKER_MEMORY" 251 | echo -e "${BLUE}[INFO]${NC} - CPUs: $DOCKER_CPUS" 252 | echo -e "${BLUE}[INFO]${NC} - Build flags: $BUILD_ARGS" 253 | 254 | # Run in interactive mode or normal build mode 255 | # Record build start time 256 | BUILD_START_TIME=$(date +%s) 257 | 258 | if [ "$INTERACTIVE" = true ]; then 259 | echo -e "${BLUE}[INFO]${NC} Starting interactive shell in container..." 260 | $COMPOSE_CMD run --rm $BUILD_OPTS onefilelinux-builder /bin/bash 261 | else 262 | echo -e "${BLUE}[INFO]${NC} Starting OneFileLinux build in container..." 263 | 264 | # Print timestamp 265 | echo -e "${BLUE}[INFO]${NC} Build started at $(date)" 266 | 267 | # Run the container with detailed debugging 268 | $COMPOSE_CMD up $BUILD_OPTS --remove-orphans 269 | COMPOSE_EXIT_CODE=$? 270 | echo -e "${BLUE}[DEBUG]${NC} Docker Compose exit code: $COMPOSE_EXIT_CODE" 271 | 272 | # Check the actual container exit code which might be different 273 | CONTAINER_EXIT=$(docker inspect --format='{{.State.ExitCode}}' onefilelinux-builder 2>/dev/null || echo "unknown") 274 | echo -e "${BLUE}[DEBUG]${NC} Container onefilelinux-builder exit code: $CONTAINER_EXIT" 275 | 276 | # Check for output files with timestamp verification 277 | echo -e "${BLUE}[INFO]${NC} Checking for recent build output files..." 278 | 279 | # Check for dry run mode - handle expected lack of output files 280 | if [[ "$BUILD_ARGS" == *"--dry-run"* ]]; then 281 | echo -e "${GREEN}[SUCCESS]${NC} Dry run completed successfully!" 282 | echo -e "${BLUE}[INFO]${NC} No EFI file was created because --dry-run was specified." 283 | echo -e "${BLUE}[INFO]${NC} Dry run mode only shows configuration without performing actual build." 284 | echo -e "${BLUE}[INFO]${NC} Remove the --dry-run flag to perform a full build." 285 | BUILD_DRY_RUN=true 286 | else 287 | BUILD_DRY_RUN=false 288 | fi 289 | 290 | # Look for any EFI files 291 | EXPECTED_EFI_FILE="" 292 | 293 | # Check for standard minimal and full profiles 294 | for profile in "minimal" "standard" "full"; do 295 | if [ -f "$PROJECT_DIR/output/OneFileLinux-${profile}.efi" ]; then 296 | EXPECTED_EFI_FILE="OneFileLinux-${profile}.efi" 297 | echo -e "${BLUE}[INFO]${NC} Found EFI file for ${profile} profile: ${EXPECTED_EFI_FILE}" 298 | break 299 | fi 300 | done 301 | 302 | # Current time in seconds since epoch 303 | CURRENT_TIME=$(date +%s) 304 | 305 | # Check if the expected file exists and was created/modified recently (within 5 minutes) 306 | if [ -n "$EXPECTED_EFI_FILE" ] && [ -f "$PROJECT_DIR/output/$EXPECTED_EFI_FILE" ]; then 307 | # Get file modification time 308 | FILE_MTIME=$(stat -c %Y "$PROJECT_DIR/output/$EXPECTED_EFI_FILE" 2>/dev/null || stat -f %m "$PROJECT_DIR/output/$EXPECTED_EFI_FILE") 309 | # Calculate age in seconds 310 | FILE_AGE=$((CURRENT_TIME - FILE_MTIME)) 311 | 312 | if [ "$FILE_AGE" -lt 300 ]; then # 5 minutes 313 | echo -e "${GREEN}[SUCCESS]${NC} OneFileLinux build completed successfully!" 314 | echo -e "${BLUE}[INFO]${NC} Output files created:" 315 | 316 | # Display the expected file first 317 | FILE_SIZE=$(du -h "$PROJECT_DIR/output/$EXPECTED_EFI_FILE" | cut -f1) 318 | echo -e " - ${GREEN}${EXPECTED_EFI_FILE}${NC} (Size: $FILE_SIZE) - Created $(printf "%d minutes %d seconds" $((FILE_AGE/60)) $((FILE_AGE%60))) ago" 319 | 320 | # List any other EFI files 321 | for efi_file in $(find "$PROJECT_DIR/output" -name "*.efi" -not -name "$EXPECTED_EFI_FILE" | sort); do 322 | FILE_SIZE=$(du -h "$efi_file" | cut -f1) 323 | file_basename=$(basename "$efi_file") 324 | echo -e " - ${GREEN}$file_basename${NC} (Size: $FILE_SIZE)" 325 | done 326 | else 327 | echo -e "${RED}[ERROR]${NC} Found expected EFI file ($EXPECTED_EFI_FILE) but it's too old (${FILE_AGE} seconds)." 328 | echo -e "${RED}[ERROR]${NC} The build process likely failed to create a new EFI file." 329 | # Check for any EFI files created/modified in the last 5 minutes 330 | echo -e "${BLUE}[INFO]${NC} Checking for any recently created EFI files..." 331 | # Find files less than 5 minutes old 332 | RECENT_FILES=$(find "$PROJECT_DIR/output" -name "*.efi" -mmin -5 | sort) 333 | if [ -n "$RECENT_FILES" ]; then 334 | echo -e "${YELLOW}[WARNING]${NC} Found recent EFI files with different names:" 335 | for recent_file in $RECENT_FILES; do 336 | FILE_SIZE=$(du -h "$recent_file" | cut -f1) 337 | file_basename=$(basename "$recent_file") 338 | echo -e " - ${GREEN}$file_basename${NC} (Size: $FILE_SIZE)" 339 | done 340 | echo -e "${YELLOW}[WARNING]${NC} Profile name may have changed during build." 341 | echo -e "${GREEN}[SUCCESS]${NC} Using alternative EFI file for build result." 342 | else 343 | echo -e "${RED}[ERROR]${NC} No recent EFI files found. Build failed." 344 | exit 1 345 | fi 346 | fi 347 | else 348 | # Check for any EFI files created in the last 5 minutes 349 | RECENT_FILES=$(find "$PROJECT_DIR/output" -name "*.efi" -mmin -5 | sort) 350 | if [ -n "$RECENT_FILES" ]; then 351 | echo -e "${GREEN}[SUCCESS]${NC} OneFileLinux build completed successfully!" 352 | echo -e "${BLUE}[INFO]${NC} Output files created (from timestamp detection):" 353 | for recent_file in $RECENT_FILES; do 354 | FILE_SIZE=$(du -h "$recent_file" | cut -f1) 355 | file_basename=$(basename "$recent_file") 356 | echo -e " - ${GREEN}$file_basename${NC} (Size: $FILE_SIZE)" 357 | done 358 | else 359 | # Adjust error message for dry run mode 360 | if [ "$BUILD_DRY_RUN" = true ]; then 361 | # Skip this message in dry run mode 362 | : 363 | else 364 | echo -e "${RED}[ERROR]${NC} No recent EFI files found in output directory." 365 | fi 366 | 367 | # List all EFI files in the output directory regardless of age 368 | ALL_EFI_FILES=$(find "$PROJECT_DIR/output" -name "*.efi" | sort) 369 | if [ -n "$ALL_EFI_FILES" ]; then 370 | echo -e "${RED}[ERROR]${NC} Found old EFI files but none created recently. Build likely failed." 371 | echo -e "${BLUE}[INFO]${NC} Existing EFI files in output directory:" 372 | for efi_file in $ALL_EFI_FILES; do 373 | FILE_SIZE=$(du -h "$efi_file" | cut -f1) 374 | file_basename=$(basename "$efi_file") 375 | FILE_MTIME=$(stat -c %Y "$efi_file" 2>/dev/null || stat -f %m "$efi_file") 376 | FILE_AGE=$((CURRENT_TIME - FILE_MTIME)) 377 | echo -e " - ${YELLOW}$file_basename${NC} (Size: $FILE_SIZE, Age: $(printf "%d minutes %d seconds" $((FILE_AGE/60)) $((FILE_AGE%60))))" 378 | done 379 | echo -e "${RED}[ERROR]${NC} Build failed to create new EFI files." 380 | exit 1 381 | else 382 | # Don't error in dry run mode 383 | if [ "$BUILD_DRY_RUN" = true ]; then 384 | # We already showed success message, don't repeat it 385 | : 386 | else 387 | echo -e "${RED}[ERROR]${NC} No EFI files found at all." 388 | exit 1 389 | fi 390 | fi 391 | fi 392 | fi 393 | 394 | # If we got here, we have some valid EFI files 395 | # Find the best file to display for log information 396 | MAIN_FILE="" 397 | 398 | # Get the most recently created EFI file 399 | RECENT_FILES=$(find "$PROJECT_DIR/output" -name "*.efi" -mmin -5 2>/dev/null | sort) 400 | if [ -n "$RECENT_FILES" ]; then 401 | # Use the expected file if it exists and is recent 402 | if [ -n "$EXPECTED_EFI_FILE" ] && [ -f "$PROJECT_DIR/output/$EXPECTED_EFI_FILE" ]; then 403 | MAIN_FILE="$PROJECT_DIR/output/$EXPECTED_EFI_FILE" 404 | else 405 | # Otherwise use the first recent file 406 | MAIN_FILE=$(echo "$RECENT_FILES" | head -1) 407 | fi 408 | echo -e "${BLUE}[INFO]${NC} Primary output file: $(basename "$MAIN_FILE")" 409 | fi 410 | 411 | # Display build timing information if available 412 | TIMING_LOG="$PROJECT_DIR/build/build_timing.log" 413 | if [ -f "$TIMING_LOG" ]; then 414 | echo -e "${BLUE}[INFO]${NC} Build timing information:" 415 | echo "==============================================================" 416 | cat "$TIMING_LOG" 417 | echo "==============================================================" 418 | echo -e "${BLUE}[INFO]${NC} Full timing log saved to: $TIMING_LOG" 419 | fi 420 | fi 421 | 422 | # Calculate and display the total build time 423 | BUILD_END_TIME=$(date +%s) 424 | BUILD_DURATION=$((BUILD_END_TIME - BUILD_START_TIME)) 425 | BUILD_MINUTES=$((BUILD_DURATION / 60)) 426 | BUILD_SECONDS=$((BUILD_DURATION % 60)) 427 | 428 | echo -e "${BLUE}[INFO]${NC} Total build time: ${BUILD_MINUTES}m ${BUILD_SECONDS}s" 429 | echo -e "${BLUE}[INFO]${NC} Process complete." -------------------------------------------------------------------------------- /docker/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Docker entrypoint script for OneFileLinux builder 3 | set -e 4 | 5 | # Fixed uid/gid or take from environment 6 | USER_ID=${USER_ID:-1000} 7 | GROUP_ID=${GROUP_ID:-1000} 8 | 9 | echo "Starting with UID: $USER_ID, GID: $GROUP_ID" 10 | 11 | # Make sure we have a /tmp directory with proper permissions 12 | mkdir -p /tmp 13 | chmod 1777 /tmp 14 | 15 | # Create a fresh work directory with all permissions for extraction 16 | TEMP_EXTRACT_DIR="/onefilelinux/extract_temp" 17 | mkdir -p "$TEMP_EXTRACT_DIR" 18 | chmod 777 "$TEMP_EXTRACT_DIR" 19 | 20 | # Make sure we have build directories 21 | mkdir -p /onefilelinux/build 22 | mkdir -p /onefilelinux/output 23 | mkdir -p /onefilelinux/.buildcache 24 | 25 | # Ensure proper permissions for output directory 26 | chmod 777 /onefilelinux/output 27 | 28 | # Get build directory absolute path 29 | BUILD_DIR=$(cd /onefilelinux/build && pwd) 30 | 31 | # Update the builder user's uid/gid if needed 32 | if [ "$USER_ID" != "1000" ] || [ "$GROUP_ID" != "1000" ]; then 33 | echo "Updating builder user to match host UID/GID" 34 | 35 | # First, set alpine-minirootfs directory to root if it exists 36 | if [ -d "$BUILD_DIR/alpine-minirootfs" ]; then 37 | chown -R root:root "$BUILD_DIR/alpine-minirootfs" || true 38 | fi 39 | 40 | # Update user 41 | deluser builder 42 | addgroup -g $GROUP_ID builder 43 | adduser -D -u $USER_ID -G builder builder 44 | echo "builder ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/builder 45 | fi 46 | 47 | # Set proper ownership for build directories, excluding special directories 48 | log_info() { 49 | echo "[INFO] $1" 50 | } 51 | 52 | log_warn() { 53 | echo "[WARN] $1" 54 | } 55 | 56 | log_info "Setting up build environment..." 57 | # Instead of changing ownership of all mounted volumes (which is slow), 58 | # we'll change Docker's approach to use the host user's UID/GID directly 59 | 60 | # Ensure runtime directories exist and have correct permissions 61 | mkdir -p /onefilelinux/build /onefilelinux/output /onefilelinux/.buildcache 62 | chmod 755 /onefilelinux/build /onefilelinux/output /onefilelinux/.buildcache 63 | 64 | # Set ownership of the .buildcache directory which is a Docker volume with persistence 65 | # This is necessary for proper ccache operation 66 | chown -R builder:builder /onefilelinux/.buildcache 2>/dev/null || true 67 | 68 | # For mounted host volumes (build and output), we skip ownership changes 69 | # This is much faster and works better with bind mounts from the host 70 | log_info "Using host's ownership for mounted volumes" 71 | 72 | # Ensure specific directories exist with correct permissions 73 | if [ -d "/onefilelinux/build/alpine-minirootfs" ]; then 74 | log_info "Setting up special directories in alpine-minirootfs..." 75 | 76 | # Create and set permissions for key directories 77 | if [ -d "/onefilelinux/build/alpine-minirootfs/proc" ]; then 78 | chmod 555 "/onefilelinux/build/alpine-minirootfs/proc" 2>/dev/null || log_warn "Could not set permissions on /proc (this is normal in Docker)" 79 | fi 80 | 81 | if [ -d "/onefilelinux/build/alpine-minirootfs/var/empty" ]; then 82 | chmod 555 "/onefilelinux/build/alpine-minirootfs/var/empty" 2>/dev/null || log_warn "Could not set permissions on /var/empty (this is normal in Docker)" 83 | fi 84 | fi 85 | 86 | # Add environment variable to indicate we're in a Docker environment 87 | export IN_DOCKER_CONTAINER=true 88 | 89 | # Function to fix kernel permissions (called before build) 90 | fix_kernel_permissions() { 91 | log_info "Checking for kernel source directory permissions" 92 | 93 | # Check if linux directory exists 94 | if [ -d "/onefilelinux/build/linux" ]; then 95 | log_info "Fixing permissions for kernel source directory" 96 | 97 | # Find problematic directories with incorrect permissions 98 | find /onefilelinux/build/linux -type d -not -perm -u+rwx -exec chmod u+rwx {} \; 2>/dev/null || true 99 | 100 | # Find problematic files with incorrect permissions 101 | find /onefilelinux/build/linux -type f -not -perm -u+rw -exec chmod u+rw {} \; 2>/dev/null || true 102 | 103 | # Specifically handle common problem areas 104 | chmod -R u+rwX /onefilelinux/build/linux/include 2>/dev/null || true 105 | chmod -R u+rwX /onefilelinux/build/linux/arch 2>/dev/null || true 106 | chmod -R u+rwX /onefilelinux/build/linux/scripts 2>/dev/null || true 107 | 108 | # Make sure scripts are executable 109 | find /onefilelinux/build/linux/scripts -name "*.sh" -exec chmod +x {} \; 2>/dev/null || true 110 | 111 | log_info "Kernel source permissions fixed" 112 | else 113 | log_info "Kernel source directory not found, skipping permission fix" 114 | fi 115 | 116 | # Make sure all library scripts are executable 117 | log_info "Making all library scripts executable" 118 | 119 | # Make core library scripts executable 120 | find /onefilelinux/build -name "8*_*.sh" -exec chmod +x {} \; 2>/dev/null || true 121 | } 122 | 123 | # Set up performance optimizations 124 | log_info "Setting up build performance optimizations" 125 | 126 | # Configure ccache for better performance 127 | export CCACHE_DIR=/onefilelinux/.buildcache/ccache 128 | export PATH=/usr/lib/ccache:$PATH 129 | 130 | # Check if we have enough memory for parallel builds 131 | if [ -f "/proc/meminfo" ]; then 132 | available_memory_kb=$(grep MemAvailable /proc/meminfo 2>/dev/null | awk '{print $2}' || echo 0) 133 | if [ "$available_memory_kb" -gt 0 ]; then 134 | available_memory_gb=$(awk "BEGIN {printf \"%.1f\", $available_memory_kb/1024/1024}") 135 | log_info "Available memory: ${available_memory_gb}GB" 136 | 137 | # Calculate optimal number of jobs based on memory 138 | # Each job needs about 2GB for kernel compilation 139 | optimal_jobs=$(awk "BEGIN {print int($available_memory_kb/1024/1024/2)}") 140 | # Ensure at least 1 job and get the minimum of this and the number of CPUs 141 | cpu_count=$(nproc 2>/dev/null || echo 2) 142 | optimal_jobs=$(( optimal_jobs < 1 ? 1 : optimal_jobs )) 143 | optimal_jobs=$(( optimal_jobs > cpu_count ? cpu_count : optimal_jobs )) 144 | 145 | log_info "Automatically using $optimal_jobs parallel jobs based on available memory" 146 | export BUILD_JOBS=$optimal_jobs 147 | 148 | # Add to BUILD_ARGS if not already specified 149 | if [ -n "$BUILD_ARGS" ] && [[ "$BUILD_ARGS" != *"--jobs="* ]]; then 150 | BUILD_ARGS="$BUILD_ARGS --jobs=$optimal_jobs" 151 | fi 152 | fi 153 | fi 154 | 155 | # Initialize ccache with optimal settings 156 | ccache -M 5G 2>/dev/null || true 157 | ccache -o compression=true 2>/dev/null || true 158 | ccache -o compression_level=6 2>/dev/null || true 159 | ccache -z 2>/dev/null || true 160 | 161 | # Define a lightweight extraction function for bootstrapping 162 | # This is used before we can access our library functions 163 | bootstrap_extraction() { 164 | local src_file="$1" 165 | local dest_dir="$2" 166 | 167 | echo "Bootstrapping extraction of $src_file to $dest_dir" 168 | 169 | # Create destination directory first 170 | mkdir -p "$dest_dir" 171 | 172 | # Use temp directory for intermediate extraction 173 | mkdir -p "$TEMP_EXTRACT_DIR" 174 | 175 | # Extract as root first to a temp location 176 | if [[ "$src_file" == *.tar.gz ]]; then 177 | tar -xzf "$src_file" -C "$TEMP_EXTRACT_DIR" 178 | elif [[ "$src_file" == *.tar.xz ]]; then 179 | # For .tar.xz files, must decompress and extract separately 180 | xz -dc "$src_file" | tar -x -C "$TEMP_EXTRACT_DIR" 181 | fi 182 | 183 | # Copy files to final location 184 | cp -a "$TEMP_EXTRACT_DIR"/* "$dest_dir"/ || true 185 | 186 | # Clean up 187 | rm -rf "$TEMP_EXTRACT_DIR"/* 188 | 189 | # Set permissions 190 | chown -R builder:builder "$dest_dir" 191 | 192 | echo "Bootstrapping extraction completed to $dest_dir" 193 | return 0 194 | } 195 | 196 | # Export the function for bootstrapping 197 | export -f bootstrap_extraction 198 | 199 | # Set working directory 200 | cd /onefilelinux/build 201 | 202 | # Define function to run build 203 | run_build() { 204 | # Fix kernel permissions to avoid build errors 205 | fix_kernel_permissions 206 | 207 | # Check for the core library scripts 208 | if [ -f "80_common.sh" ] && [ -f "81_error_handling.sh" ] && [ -f "82_build_helper.sh" ] && [ -f "83_config_helper.sh" ] && [ -f "84_build_core.sh" ]; then 209 | # Use the library-based build system for consistent builds 210 | echo "Using library-based build system" 211 | 212 | # Make all library scripts executable 213 | chmod +x 80_common.sh 214 | chmod +x 81_error_handling.sh 215 | chmod +x 82_build_helper.sh 216 | chmod +x 83_config_helper.sh 217 | chmod +x 84_build_core.sh 218 | 219 | # Make build scripts executable 220 | chmod +x 01_get.sh 221 | chmod +x 02_chrootandinstall.sh 222 | chmod +x 03_conf.sh 223 | chmod +x 04_build.sh 224 | 225 | # No pre-initialization needed - each script will properly load libraries 226 | # This line was previously causing double initialization of error handling 227 | 228 | # Make sure the build script exists and is executable 229 | if [ -f "04_build.sh" ]; then 230 | chmod +x 04_build.sh 231 | echo "Found build script: 04_build.sh" 232 | else 233 | echo "WARNING: Build script not found in container" 234 | echo "Searching for the script in the build directory..." 235 | 236 | # Find the script in the mounted volumes 237 | SCRIPT_PATH=$(find /onefilelinux -name "04_build.sh" -type f 2>/dev/null | head -n 1) 238 | 239 | if [ -n "$SCRIPT_PATH" ]; then 240 | echo "Found script at: $SCRIPT_PATH" 241 | echo "Creating symlink to make script accessible" 242 | ln -sf "$SCRIPT_PATH" ./04_build.sh 243 | chmod +x 04_build.sh 244 | else 245 | echo "ERROR: Critical file not found: 04_build.sh" 246 | echo "Please ensure the build directory is correctly mounted" 247 | fi 248 | fi 249 | 250 | # Use the unified build script for complete timing information 251 | # Make sure the unified build script exists and is executable 252 | if [ -f "build.sh" ]; then 253 | chmod +x build.sh 254 | else 255 | echo "Creating build.sh symlink" 256 | # Find the script in the mounted volumes 257 | SCRIPT_PATH=$(find /onefilelinux -name "build.sh" -type f 2>/dev/null | head -n 1) 258 | 259 | if [ -n "$SCRIPT_PATH" ]; then 260 | echo "Found script at: $SCRIPT_PATH" 261 | ln -sf "$SCRIPT_PATH" ./build.sh 262 | chmod +x build.sh 263 | else 264 | echo "ERROR: Unified build script not found: build.sh" 265 | echo "Please ensure the build directory contains build.sh" 266 | return 1 267 | fi 268 | fi 269 | 270 | # Add common options for better performance 271 | if [ -n "$BUILD_ARGS" ]; then 272 | # Add our performance options if not already included 273 | if [[ "$BUILD_ARGS" != *"--use-cache"* ]]; then 274 | BUILD_ARGS="$BUILD_ARGS --use-cache" 275 | fi 276 | if [[ "$BUILD_ARGS" != *"--use-swap"* && "$BUILD_ARGS" != *"--no-swap"* ]]; then 277 | BUILD_ARGS="$BUILD_ARGS --use-swap" 278 | fi 279 | 280 | # Try a more explicit step-by-step approach in Docker environment 281 | echo "Running build steps sequentially for Docker environment:" 282 | 283 | # Display ccache stats before build 284 | echo "CCache statistics before build:" 285 | ccache -s 286 | 287 | # Load common library to get access to source_libraries 288 | if [ -f "./80_common.sh" ]; then 289 | echo "Loading common library first to properly handle build profiles" 290 | source "./80_common.sh" 291 | 292 | # Use the proper library loading function to ensure correct order 293 | if declare -f source_libraries >/dev/null 2>&1; then 294 | echo "Using source_libraries function to load all libraries in correct order" 295 | source_libraries "." 296 | fi 297 | else 298 | # Fallback if common library is not available 299 | echo "WARNING: 80_common.sh not found, falling back to direct dependency loading" 300 | source "./82_build_helper.sh" 301 | fi 302 | 303 | # Parse build arguments properly through the build helper's function 304 | echo "[INFO] Processing BUILD_ARGS from environment: $BUILD_ARGS" 305 | 306 | # Extract build profile from BUILD_ARGS 307 | BUILD_PROFILE="standard" # Default 308 | if [[ "$BUILD_ARGS" == *"--minimal"* ]]; then 309 | BUILD_PROFILE="minimal" 310 | echo "[INFO] Detected minimal profile in build arguments" 311 | elif [[ "$BUILD_ARGS" == *"--standard"* ]]; then 312 | BUILD_PROFILE="standard" 313 | echo "[INFO] Detected standard profile in build arguments" 314 | elif [[ "$BUILD_ARGS" == *"--full"* ]]; then 315 | BUILD_PROFILE="full" 316 | echo "[INFO] Detected full profile in build arguments" 317 | elif [[ "$BUILD_ARGS" =~ --profile=([a-zA-Z0-9_-]+) ]]; then 318 | BUILD_PROFILE="${BASH_REMATCH[1]}" 319 | echo "[INFO] Detected profile parameter: $BUILD_PROFILE" 320 | fi 321 | 322 | # Set BUILD_TYPE and export for all downstream scripts 323 | export BUILD_TYPE="$BUILD_PROFILE" 324 | export BUILD_PROFILE="$BUILD_PROFILE" 325 | export explicit_profile=true 326 | 327 | # Also parse flags through build helper for consistency 328 | if declare -f parse_build_flags >/dev/null 2>&1; then 329 | parse_build_flags "$BUILD_ARGS" true 330 | echo "[INFO] Profile configuration completed through parse_build_flags" 331 | echo "[INFO] Set BUILD_TYPE=$BUILD_TYPE for downstream scripts" 332 | else 333 | echo "[WARNING] parse_build_flags function not available" 334 | fi 335 | 336 | # Log the configuration that will be used 337 | echo "Using build configuration:" 338 | echo "- ZFS support: ${INCLUDE_ZFS:-true}" 339 | echo "- Network tools: ${INCLUDE_NETWORK_TOOLS:-true}" 340 | echo "- Crypto support: ${INCLUDE_CRYPTO:-true}" 341 | echo "- Minimal kernel: ${INCLUDE_MINIMAL_KERNEL:-false}" 342 | 343 | # Run each step explicitly to ensure proper error handling 344 | echo "Step 1: Running 01_get.sh to download components" 345 | ./01_get.sh 346 | 347 | echo "Step 2: Running 02_chrootandinstall.sh to prepare the environment" 348 | ./02_chrootandinstall.sh 349 | 350 | echo "Step 3: Running 03_conf.sh for configuration" 351 | ./03_conf.sh 352 | 353 | echo "Step 4: Running 04_build.sh for final build with args: $BUILD_ARGS" 354 | 355 | # Set flag to finalize timing log in the last script 356 | export FINALIZE_TIMING_LOG=true 357 | 358 | # Ensure BUILD_TYPE is in the environment for 04_build.sh 359 | if [ -n "${BUILD_TYPE:-}" ]; then 360 | echo "[INFO] Using build profile: $BUILD_TYPE" 361 | export BUILD_TYPE 362 | fi 363 | 364 | # Pass the build arguments directly to 04_build.sh 365 | echo "[INFO] Executing build with arguments: $BUILD_ARGS" 366 | ./04_build.sh $BUILD_ARGS 367 | 368 | # Display ccache stats after build 369 | echo "CCache statistics after build:" 370 | ccache -s 371 | else 372 | echo "Running build steps sequentially for Docker environment (default options):" 373 | echo "CCache statistics before build:" 374 | ccache -s 375 | 376 | # Run each step explicitly to ensure proper error handling 377 | echo "Step 1: Running 01_get.sh to download components" 378 | ./01_get.sh 379 | 380 | echo "Step 2: Running 02_chrootandinstall.sh to prepare the environment" 381 | ./02_chrootandinstall.sh 382 | 383 | echo "Step 3: Running 03_conf.sh for configuration" 384 | ./03_conf.sh 385 | 386 | echo "Step 4: Running 04_build.sh for final build with default args" 387 | 388 | # Set flag to finalize timing log in the last script 389 | export FINALIZE_TIMING_LOG=true 390 | 391 | # Just use sensible defaults without re-adding profile 392 | local build_args="--use-cache --use-swap" 393 | 394 | # Pass build arguments directly to 04_build.sh 395 | echo "Running with default arguments: $build_args" 396 | ./04_build.sh $build_args 397 | 398 | echo "CCache statistics after build:" 399 | ccache -s 400 | fi 401 | else 402 | # Required scripts are missing 403 | echo "ERROR: Core library scripts not found" 404 | echo "Please ensure the build directory contains all required scripts" 405 | 406 | # Handle special alpine extraction issues 407 | if [ -f "alpine-minirootfs-3.21.3-x86_64.tar.gz" ]; then 408 | echo "Pre-extracting Alpine minirootfs as root" 409 | # Remove existing directory if it exists 410 | if [ -d "alpine-minirootfs" ]; then 411 | rm -rf alpine-minirootfs 412 | fi 413 | 414 | # Create directory with proper permissions 415 | mkdir -p alpine-minirootfs 416 | 417 | # Use bootstrap extraction first 418 | bootstrap_extraction "alpine-minirootfs-3.21.3-x86_64.tar.gz" "alpine-minirootfs" 419 | 420 | # Mark extraction as complete 421 | touch "alpine-minirootfs/.extraction_complete" 422 | 423 | echo "Set proper permissions on Alpine minirootfs" 424 | fi 425 | 426 | # Attempt to run the build script if it exists 427 | if [ -f "04_build.sh" ]; then 428 | chmod +x 04_build.sh 429 | if [ -n "$BUILD_ARGS" ]; then 430 | # Ensure BUILD_TYPE is in the environment for 04_build.sh 431 | if [ -n "${BUILD_TYPE:-}" ]; then 432 | echo "[INFO] Using build profile: $BUILD_TYPE" 433 | export BUILD_TYPE 434 | fi 435 | 436 | echo "[INFO] Running: ./04_build.sh $BUILD_ARGS" 437 | echo "[WARNING] Using direct build.sh approach is deprecated. Prefer library-based build system." 438 | ./04_build.sh $BUILD_ARGS 439 | else 440 | # Ensure BUILD_TYPE is in the environment for 04_build.sh 441 | if [ -n "${BUILD_TYPE:-}" ]; then 442 | echo "[INFO] Using build profile: $BUILD_TYPE" 443 | export BUILD_TYPE 444 | fi 445 | 446 | echo "[INFO] Running: ./04_build.sh" 447 | echo "[WARNING] Using direct build.sh approach is deprecated. Prefer library-based build system." 448 | ./04_build.sh 449 | fi 450 | else 451 | echo "ERROR: Build script 04_build.sh not found" 452 | echo "Please ensure the build directory is correctly mounted" 453 | return 1 454 | fi 455 | fi 456 | } 457 | 458 | # Check if we should run as root or as the builder user 459 | if [ "${RUN_AS_ROOT:-false}" = "true" ]; then 460 | echo "Running as root user (RUN_AS_ROOT=true)" 461 | if [ $# -eq 0 ]; then 462 | # Default command if none provided 463 | cd /onefilelinux/build && run_build 464 | else 465 | # Run whatever command was passed 466 | "$@" 467 | fi 468 | else 469 | echo "Running as builder user" 470 | if [ $# -eq 0 ]; then 471 | # Default command if none provided 472 | exec su-exec builder bash -c "cd /onefilelinux/build && run_build" 473 | else 474 | # Run whatever command was passed 475 | exec su-exec builder "$@" 476 | fi 477 | fi -------------------------------------------------------------------------------- /docs/USER_GUIDE.md: -------------------------------------------------------------------------------- 1 | # OneFileLinux User Guide 2 | 3 | This comprehensive guide explains how to build, install, and use OneFileLinux for system recovery operations. 4 | 5 | ## Table of Contents 6 | 7 | 1. [Overview](#overview) 8 | 2. [Building OneFileLinux](#building-onefilelinux) 9 | - [Using Docker](#using-docker-recommended) 10 | - [Building Natively](#building-natively) 11 | - [Build Options](#build-options) 12 | 3. [Installation](#installation) 13 | - [macOS Installation](#macos-installation) 14 | - [PC/Windows Installation](#pcwindows-installation) 15 | - [USB Flash Drive Installation](#usb-flash-drive-installation) 16 | 4. [Using OneFileLinux](#using-onefilelinux) 17 | - [Text User Interface](#text-user-interface) 18 | - [Common Recovery Operations](#common-recovery-operations) 19 | - [Working with Filesystems](#working-with-filesystems) 20 | - [Network Connectivity](#network-connectivity) 21 | 5. [Troubleshooting](#troubleshooting) 22 | - [Boot Issues](#boot-issues) 23 | - [Hardware Compatibility](#hardware-compatibility) 24 | - [Common Errors](#common-errors) 25 | 6. [Advanced Usage](#advanced-usage) 26 | - [Custom Configurations](#custom-configurations) 27 | - [Recovery Scenarios](#recovery-scenarios) 28 | - [Performance Considerations](#performance-considerations) 29 | 7. [Developer Documentation](#developer-documentation) 30 | - [Build System Architecture](#build-system-architecture) 31 | - [Feature Flag System](#feature-flag-system) 32 | - [Kernel Configuration System](#kernel-configuration-system) 33 | - [Build Environments](#build-environments) 34 | - [CI/CD System](#cicd-system) 35 | 36 | ## Overview 37 | 38 | OneFileLinux is a lightweight Linux distribution contained in a single EFI executable file that runs on any UEFI computer (PC or Mac) without installation. It provides a comprehensive set of tools for system recovery, data rescue, and hardware diagnostics. 39 | 40 | ### Key Features 41 | 42 | - **Single EFI File**: Boots directly from UEFI without additional bootloaders 43 | - **Advanced Filesystems**: Support for ZFS, Btrfs, ext4, XFS, and more 44 | - **Hardware Diagnostics**: Tools for hardware testing and analysis 45 | - **Network Support**: Ethernet, WiFi, and remote recovery capabilities 46 | - **Data Recovery**: Specialized tools for rescuing data from failed systems 47 | - **Boot Repair**: Tools to fix common boot problems across operating systems 48 | - **Text UI**: Full-featured text-based user interface for easy navigation 49 | - **Size Optimized**: Minimal builds under 50MB, full builds under 150MB 50 | 51 | ### Project Revival 52 | 53 | OneFileLinux has been revived and completely redesigned from the ground up, transforming a previously unmaintained project into a robust, modern recovery solution. Key improvements include: 54 | 55 | - **Modular Architecture**: Complete rebuild with a layered, maintainable design 56 | - **Error Resilience**: Comprehensive error handling and recovery mechanisms 57 | - **Modern Foundation**: Updated Linux kernel (6.12) and Alpine Linux (3.21) 58 | - **Advanced Storage Support**: Full ZFS and Btrfs integration 59 | - **Adaptive Building**: Flexible build system with multiple configuration options 60 | - **Streamlined Experience**: Automatic root login and intuitive text-based interface 61 | - **Size Optimization**: Ultra-compact builds as small as 4MB for minimal configurations 62 | - **Continuous Integration**: Automated build and test pipeline with GitHub Actions 63 | - **Docker Integration**: Containerized build environment for consistent results 64 | 65 | ## Building OneFileLinux 66 | 67 | ### Using Docker (Recommended) 68 | 69 | The easiest way to build OneFileLinux is using Docker, which provides a consistent build environment regardless of your host system. 70 | 71 | #### Prerequisites 72 | 73 | - Docker installed and running 74 | - Git 75 | - At least 4GB free RAM 76 | - At least 10GB free disk space 77 | 78 | #### Build Steps 79 | 80 | 1. Clone the repository: 81 | ```bash 82 | git clone https://github.com/zhovner/OneFileLinux.git 83 | cd OneFileLinux/docker 84 | ``` 85 | 86 | 2. Make the build script executable: 87 | ```bash 88 | chmod +x build-onefilelinux.sh 89 | ``` 90 | 91 | 3. Run the build with default settings: 92 | ```bash 93 | ./build-onefilelinux.sh 94 | ``` 95 | 96 | 4. For a full build with all features: 97 | ```bash 98 | ./build-onefilelinux.sh -b "--full" 99 | ``` 100 | 101 | 5. For a minimal build: 102 | ```bash 103 | ./build-onefilelinux.sh -b "--minimal" 104 | ``` 105 | 106 | #### Docker Build Options 107 | 108 | The `build-onefilelinux.sh` script supports several options: 109 | 110 | ``` 111 | Usage: ./build-onefilelinux.sh [options] 112 | 113 | Options: 114 | -h, --help Display this help message 115 | -c, --clean Clean the Docker environment before building 116 | -v, --verbose Enable verbose output 117 | -b, --build-args ARG Pass build arguments to the build script 118 | -e, --env-file FILE Specify a custom .env file 119 | -i, --interactive Run in interactive mode (shell inside container) 120 | -p, --pull Pull the latest base image before building 121 | --no-cache Build the Docker image without using cache 122 | ``` 123 | 124 | #### Build Artifacts 125 | 126 | After a successful build, the output file (`OneFileLinux.efi`) will be placed in the `output/` directory in the root of the repository. 127 | 128 | ### Building Natively 129 | 130 | If you prefer to build on your local system without Docker: 131 | 132 | #### Prerequisites 133 | 134 | For Debian/Ubuntu-based systems: 135 | ```bash 136 | sudo apt-get update 137 | sudo apt-get install build-essential git autoconf automake libtool \ 138 | util-linux libelf-dev libssl-dev zlib1g-dev libzstd-dev liblz4-dev \ 139 | upx xz-utils zstd curl wget sudo python3 gcc g++ make patch \ 140 | libncurses-dev e2fsprogs coreutils mtools xorriso squashfs-tools 141 | ``` 142 | 143 | For Alpine Linux: 144 | ```bash 145 | apk add build-base git autoconf automake libtool util-linux elfutils-dev \ 146 | openssl-dev zlib-dev zstd-dev lz4-dev upx xz zstd curl wget sudo \ 147 | python3 gcc g++ make patch ncurses-dev e2fsprogs coreutils mtools \ 148 | xorriso squashfs-tools 149 | ``` 150 | 151 | #### Build Steps 152 | 153 | 1. Clone the repository: 154 | ```bash 155 | git clone https://github.com/zhovner/OneFileLinux.git 156 | cd OneFileLinux 157 | ``` 158 | 159 | 2. Run the build scripts sequentially: 160 | ```bash 161 | cd build 162 | ./build.sh 163 | ``` 164 | 165 | 3. Or run each build step manually: 166 | ```bash 167 | ./00_prepare.sh # Prepare the build environment 168 | ./01_get.sh # Download and extract sources 169 | ./02_chrootandinstall.sh # Set up chroot and install packages 170 | ./03_conf.sh # Configure the system 171 | ./04_build.sh # Build the final EFI file 172 | ``` 173 | 174 | 4. After successful completion, the `OneFileLinux.efi` file will be created in the repository root directory. 175 | 176 | 5. Optional: Clean up build artifacts: 177 | ```bash 178 | ./99_cleanup.sh 179 | ``` 180 | 181 | ### Build Options 182 | 183 | OneFileLinux offers several build configurations to balance features and size: 184 | 185 | #### Build Types 186 | 187 | | Build Type | Description | Size | Command | 188 | |------------|-------------|------|---------| 189 | | Minimal | Core functionality only | ~30-50MB | `--minimal` | 190 | | Standard | Basic recovery features | ~60-90MB | (default) | 191 | | Full | All features and tools | ~100-150MB | `--full` | 192 | 193 | **Standard Build Capabilities:** 194 | - **Performance**: Balanced multi-core support with hardware crypto acceleration 195 | - **Hardware Support**: Extensive coverage for storage controllers (SATA, AHCI, NVMe, USB), input devices, and basic framebuffer graphics 196 | - **Filesystems**: Complete support for ZFS, Ext4, and other common filesystems (BTRFS optional) 197 | - **Networking**: Full TCP/IP stack with routing, firewall capabilities, and diagnostics 198 | - **Security**: Comprehensive cryptography with LUKS disk encryption and LVM support 199 | - **System Footprint**: Moderately sized with broad hardware compatibility for effective recovery operations 200 | 201 | #### Advanced Package Groups 202 | 203 | You can customize your build with these package groups: 204 | 205 | | Package Group | Size Impact | Description | Flag | Included Packages | 206 | |---------------|-------------|-------------|------|-------------------| 207 | | Advanced FS | ~10MB | Extra filesystem tools | `--with-advanced-fs` | ntfs-3g, xfsprogs, gptfdisk, exfatprogs, f2fs-tools | 208 | | Disk Diagnostics | ~15MB | Hardware testing tools | `--with-disk-diag` | smartmontools, hdparm, nvme-cli, dmidecode, lshw | 209 | | Network Diagnostics | ~12MB | Network diagnostics | `--with-network-diag` | ethtool, nmap, wireguard-tools, openvpn | 210 | | System Tools | ~8MB | Advanced system utilities | `--with-system-tools` | htop, strace, pciutils, usbutils | 211 | | Data Recovery | ~20MB | Data rescue utilities | `--with-data-recovery` | testdisk (includes photorec) | 212 | | Boot Repair | ~15MB | Bootloader repair tools | `--with-boot-repair` | grub | 213 | | Advanced Editors | ~5MB | Text editors and tools | `--with-editors` | vim, tmux, jq | 214 | | Security Tools | ~10MB | Security analysis tools | `--with-security` | openssl | 215 | 216 | #### Detailed Build Script Options 217 | 218 | The `build.sh` script accepts numerous options to customize your build. Here's a comprehensive list of all available options: 219 | 220 | ##### Build Types 221 | ``` 222 | --minimal Minimal build optimized for size (~30-50% smaller) 223 | --full Full build with all available components 224 | ``` 225 | 226 | ##### Size Optimization Options 227 | ``` 228 | --with-compression Enable EFI file compression (default: yes) 229 | --without-compression Disable EFI file compression (faster boot) 230 | --compression-tool=TOOL Select compression tool (upx, xz, zstd) (default: upx) 231 | ``` 232 | 233 | ##### Build Performance Options 234 | ``` 235 | --use-cache Enable source and build caching (default: yes) 236 | --no-cache Disable source and build caching 237 | --cache-dir=DIR Set cache directory (default: ~/.onefilelinux/cache) 238 | --jobs=N Set number of parallel build jobs (default: CPU cores) 239 | --keep-ccache Keep compiler cache between builds (default: yes) 240 | --no-keep-ccache Clear compiler cache between builds 241 | --use-swap Create swap file if memory is low (default: no) 242 | --no-swap Do not create swap file even if memory is low 243 | --interactive-config Use interactive kernel configuration (menuconfig) 244 | --no-interactive-config Use non-interactive kernel config (default) 245 | ``` 246 | 247 | ##### Security Options 248 | ``` 249 | --password=PASS Set custom root password (CAUTION: visible in process list) 250 | --random-password Generate random root password (default) 251 | --no-password Create root account with no password (unsafe) 252 | --password-length=N Set length of random password (default: 12) 253 | ``` 254 | 255 | ##### Optional Modules 256 | ``` 257 | --with-zfs Include ZFS filesystem support (default: yes) 258 | --without-zfs Exclude ZFS filesystem support 259 | --with-btrfs Include Btrfs filesystem support (default: no) 260 | --without-btrfs Exclude Btrfs filesystem support 261 | --with-recovery-tools Include data recovery tools (default: yes) 262 | --without-recovery-tools Exclude data recovery tools 263 | --with-network-tools Include network tools (default: yes) 264 | --without-network-tools Exclude network tools 265 | --with-crypto Include encryption support (default: yes) 266 | --without-crypto Exclude encryption support 267 | --with-tui Include Text User Interface (default: yes) 268 | --without-tui Exclude Text User Interface 269 | ``` 270 | 271 | ##### Advanced Package Groups 272 | ``` 273 | --with-advanced-fs Include advanced filesystem tools 274 | --without-advanced-fs Exclude advanced filesystem tools 275 | --with-disk-diag Include disk and hardware diagnostics 276 | --without-disk-diag Exclude disk and hardware diagnostics 277 | --with-network-diag Include network diagnostics and VPN tools 278 | --without-network-diag Exclude network diagnostics and VPN tools 279 | --with-system-tools Include advanced system utilities 280 | --without-system-tools Exclude advanced system utilities 281 | --with-data-recovery Include data recovery utilities 282 | --without-data-recovery Exclude data recovery utilities 283 | --with-boot-repair Include boot repair tools 284 | --without-boot-repair Exclude boot repair tools 285 | --with-editors Include advanced text editors 286 | --without-editors Exclude advanced text editors 287 | --with-security Include security tools 288 | --without-security Exclude security tools 289 | --with-all-advanced Include all advanced package groups 290 | --without-all-advanced Exclude all advanced package groups 291 | ``` 292 | 293 | ##### Configuration Management 294 | ``` 295 | --save-config Save current configuration as default 296 | --show-config Display current build configuration 297 | ``` 298 | 299 | #### Common Build Command Examples 300 | 301 | ```bash 302 | # Minimal build with only ZFS support 303 | ./build.sh --minimal --with-zfs --without-all-advanced 304 | 305 | # Standard build with advanced filesystem tools and data recovery 306 | ./build.sh --with-advanced-fs --with-data-recovery 307 | 308 | # Full featured build with everything included 309 | ./build.sh --full 310 | 311 | # Custom build with specific tools 312 | ./build.sh --with-zfs --with-btrfs --with-network-tools --with-disk-diag 313 | 314 | # Minimal build with high compression 315 | ./build.sh --minimal --compression-tool=xz 316 | 317 | # Build without compression for faster boot time 318 | ./build.sh --without-compression 319 | 320 | # Custom build with specific performance settings 321 | ./build.sh --jobs=8 --cache-dir=/tmp/cache --use-swap 322 | 323 | # Build with interactive kernel configuration 324 | ./build.sh --interactive-config 325 | 326 | # Build with a custom root password 327 | ./build.sh --password=mypassword 328 | 329 | # Build with a specific random password length 330 | ./build.sh --random-password --password-length=16 331 | ``` 332 | 333 | #### EFI Partition Size Considerations 334 | 335 | When planning to use OneFileLinux, keep in mind these EFI partition size guidelines: 336 | 337 | - **Minimal build**: Even small 100MB EFI partitions are more than sufficient 338 | - **Standard build**: Standard 100MB EFI partition is recommended 339 | - **Full build**: Standard 100MB EFI partition is typically sufficient 340 | 341 | Most modern systems have EFI partitions of 100MB or larger, which is adequate for any OneFileLinux build. 342 | 343 | ## Installation 344 | 345 | ### MacOS Installation 346 | 347 | 1. **Download OneFileLinux.efi** 348 | From the releases page or build it yourself. 349 | 350 | 2. **Mount the EFI System Partition** 351 | ```bash 352 | diskutil list # Identify your EFI partition (typically disk0s1) 353 | diskutil mount disk0s1 # Replace with your EFI partition identifier 354 | ``` 355 | 356 | 3. **Copy OneFileLinux.efi to the EFI Partition** 357 | ```bash 358 | cp ~/Downloads/OneFileLinux.efi /Volumes/EFI/ 359 | ``` 360 | 361 | 4. **Configure Boot Options** 362 | 363 | Since macOS El Capitan, System Integrity Protection (SIP) requires boot option changes to be made from Recovery Mode: 364 | 365 | 1. Check SIP status: `csrutil status` (Enabled by default) 366 | 2. Restart and hold **CMD+R** during startup to enter Recovery Mode 367 | 3. Open Terminal from Utilities menu 368 | 4. Mount the EFI partition (step 2) 369 | 5. Set the boot option: 370 | ```bash 371 | bless --mount /Volumes/EFI --setBoot --nextonly --file /Volumes/EFI/OneFileLinux.efi 372 | ``` 373 | 374 | This configures a one-time boot of OneFileLinux, preserving your default boot order. 375 | 376 | 5. **Reboot to Start OneFileLinux** 377 | 378 | After using OneFileLinux, type `reboot` in the Linux console to return to macOS. Repeat steps 2 and 4 from Recovery Mode for subsequent uses. 379 | 380 | ### PC (Windows/Linux) Installation 381 | 382 | There are multiple methods to boot OneFileLinux on PC systems. The following procedure works for most systems without built-in UEFI Shell access. 383 | 384 | 1. **Access the EFI System Partition** 385 | 386 | Windows 10+ systems installed in UEFI mode typically have a 100MB EFI partition. 387 | You will need either: 388 | - A Linux live USB to access this partition 389 | - An existing installation of OneFileLinux via USB 390 | 391 | 2. **Configure NVRAM Boot Option** 392 | 393 | Using Linux, add a boot entry with efibootmgr: 394 | ```bash 395 | efibootmgr --disk /dev/sda --part 1 --create --label "OneFileLinux" --loader /OneFileLinux.efi 396 | ``` 397 | 398 | Replace `/dev/sda` with your disk path and `--part 1` with your EFI partition number. 399 | 400 | 3. **Boot OneFileLinux** 401 | 402 | Boot into your computer's boot menu (typically F12, F10, or Esc during startup) and select "OneFileLinux". 403 | 404 | ### USB Flash Drive Installation 405 | 406 | For portable use or when direct EFI partition access is difficult: 407 | 408 | 1. **Format a USB Drive with GPT Partition Scheme** 409 | 410 | In Windows: 411 | ``` 412 | 1. Open Administrator Command Prompt 413 | 2. Run diskpart 414 | 3. list disk 415 | 4. select disk N (replace N with your USB drive number) 416 | 5. clean 417 | 6. convert gpt 418 | 7. create partition primary 419 | 8. format fs=fat32 quick 420 | 9. assign 421 | 10. exit 422 | ``` 423 | 424 | In macOS: 425 | ```bash 426 | diskutil list # Find your USB drive 427 | diskutil eraseDisk FAT32 ONEFILELINUX GPT /dev/diskN # Replace diskN with your USB 428 | ``` 429 | 430 | In Linux: 431 | ```bash 432 | sudo gdisk /dev/sdX # Replace sdX with your USB drive 433 | # Create a new GPT table (o), create a partition (n), write changes (w) 434 | sudo mkfs.vfat -F 32 /dev/sdX1 # Format the partition 435 | ``` 436 | 437 | 2. **Install OneFileLinux** 438 | 439 | Create the directory structure and copy the file: 440 | 441 | Windows: 442 | ``` 443 | mkdir -p X:\EFI\BOOT # Replace X: with your USB drive letter 444 | copy OneFileLinux.efi X:\EFI\BOOT\BOOTx64.EFI 445 | ``` 446 | 447 | macOS/Linux: 448 | ```bash 449 | mkdir -p /Volumes/ONEFILELINUX/EFI/BOOT # macOS 450 | # OR 451 | mkdir -p /mnt/usb/EFI/BOOT # Linux (mount point may vary) 452 | 453 | cp OneFileLinux.efi /Volumes/ONEFILELINUX/EFI/BOOT/BOOTx64.EFI # macOS 454 | # OR 455 | cp OneFileLinux.efi /mnt/usb/EFI/BOOT/BOOTx64.EFI # Linux 456 | ``` 457 | 458 | 3. **Boot from USB** 459 | 460 | Select the USB drive from your computer's boot menu. 461 | 462 | ## Using OneFileLinux 463 | 464 | ### Text User Interface 465 | 466 | When you boot OneFileLinux, it automatically logs in as root and launches the text-based user interface (TUI). The TUI provides an easy-to-use menu system for common recovery operations. 467 | 468 | #### Login Information 469 | 470 | - **Username**: root 471 | - **Password**: 472 | - For GitHub Actions release builds: The default password is `onefilelinux` 473 | - For local builds: The password is randomly generated during build and saved in `onefilelinux-password.txt` in the build directory 474 | - If you specified a custom password during build with `--password=PASS`, use that password 475 | 476 | #### Main Menu 477 | 478 | The main menu provides access to the following functions: 479 | 480 | 1. **System Information**: Hardware details, disk information, and system status 481 | 2. **Filesystem Tools**: Mount, unmount, check, and repair filesystems 482 | 3. **Data Recovery**: Tools for rescuing lost or damaged data 483 | 4. **Disk Management**: Partition, format, and manage disks 484 | 5. **Network Tools**: Configure network interfaces and run diagnostics 485 | 6. **Boot Repair**: Fix boot issues on Windows, Linux, and macOS 486 | 7. **Advanced Tools**: Additional system utilities and diagnostic tools 487 | 8. **Help**: Documentation and usage information 488 | 489 | Navigate the menu using arrow keys, Tab, and Enter. Press 'q' or Escape to go back or exit menus. 490 | 491 | ### Common Recovery Operations 492 | 493 | #### Mounting Filesystems 494 | 495 | 1. From the main menu, select "Filesystem Tools" 496 | 2. Choose "Mount Filesystem" 497 | 3. Select the partition to mount 498 | 4. Specify the mount point (or use the default) 499 | 5. Select filesystem type (if not automatically detected) 500 | 501 | Example command-line alternative: 502 | ```bash 503 | mount /dev/sda1 /mnt 504 | ``` 505 | 506 | #### Checking and Repairing Filesystems 507 | 508 | 1. From the main menu, select "Filesystem Tools" 509 | 2. Choose "Check/Repair Filesystem" 510 | 3. Select the partition to check 511 | 4. Choose between "Check Only" or "Check and Repair" 512 | 513 | Example command-line alternatives: 514 | ```bash 515 | # For ext2/3/4 516 | fsck.ext4 -f /dev/sda1 517 | 518 | # For ZFS 519 | zpool import -f poolname 520 | zpool scrub poolname 521 | 522 | # For Btrfs 523 | btrfs check /dev/sda1 524 | ``` 525 | 526 | #### Recovering Deleted Files 527 | 528 | 1. From the main menu, select "Data Recovery" 529 | 2. Choose "Recover Deleted Files" 530 | 3. Select the partition to scan 531 | 4. Select file types to recover 532 | 5. Specify a destination for recovered files 533 | 534 | Example command-line alternative: 535 | ```bash 536 | testdisk /dev/sda 537 | ``` 538 | 539 | #### Disk Partitioning 540 | 541 | 1. From the main menu, select "Disk Management" 542 | 2. Choose "Partition Disk" 543 | 3. Select the disk to partition 544 | 4. Follow the interactive prompts 545 | 546 | Example command-line alternatives: 547 | ```bash 548 | fdisk /dev/sda 549 | # OR 550 | gdisk /dev/sda # For GPT partitioning 551 | ``` 552 | 553 | #### Fixing Boot Issues 554 | 555 | 1. From the main menu, select "Boot Repair" 556 | 2. Choose the operating system type (Windows, Linux, macOS) 557 | 3. Follow the guided repair process 558 | 559 | ### Working with Filesystems 560 | 561 | #### ZFS Operations 562 | 563 | OneFileLinux includes comprehensive ZFS support. Common operations: 564 | 565 | ```bash 566 | # Import pool 567 | zpool import -f poolname 568 | 569 | # Check pool status 570 | zpool status poolname 571 | 572 | # Repair pool (scrub) 573 | zpool scrub poolname 574 | 575 | # Export pool cleanly 576 | zpool export poolname 577 | 578 | # Mount ZFS dataset 579 | zfs mount poolname/dataset 580 | 581 | # List all datasets 582 | zfs list 583 | 584 | # Take a snapshot 585 | zfs snapshot poolname/dataset@snapshot1 586 | ``` 587 | 588 | #### Btrfs Operations 589 | 590 | If your build includes Btrfs support: 591 | 592 | ```bash 593 | # Mount Btrfs filesystem 594 | mount -t btrfs /dev/sda1 /mnt 595 | 596 | # Check filesystem 597 | btrfs check /dev/sda1 598 | 599 | # Repair filesystem 600 | btrfs check --repair /dev/sda1 601 | 602 | # List subvolumes 603 | btrfs subvolume list /mnt 604 | 605 | # Mount specific subvolume 606 | mount -t btrfs -o subvol=subvolname /dev/sda1 /mnt 607 | ``` 608 | 609 | #### Working with Encrypted Volumes 610 | 611 | ```bash 612 | # Open LUKS encrypted volume 613 | cryptsetup luksOpen /dev/sda1 mydisk 614 | 615 | # Mount the decrypted volume 616 | mount /dev/mapper/mydisk /mnt 617 | 618 | # Close encrypted volume 619 | umount /mnt 620 | cryptsetup luksClose mydisk 621 | ``` 622 | 623 | ### Network Connectivity 624 | 625 | #### Configuring Wired Network 626 | 627 | 1. From the main menu, select "Network Tools" 628 | 2. Choose "Configure Network Interface" 629 | 3. Select the Ethernet interface 630 | 4. Choose between DHCP or Static IP configuration 631 | 632 | Example command-line alternative: 633 | ```bash 634 | # Using DHCP 635 | dhclient eth0 636 | 637 | # Static IP configuration 638 | ip addr add 192.168.1.100/24 dev eth0 639 | ip route add default via 192.168.1.1 640 | echo "nameserver 8.8.8.8" > /etc/resolv.conf 641 | ``` 642 | 643 | #### Configuring Wireless Network 644 | 645 | If your build includes wireless tools: 646 | 647 | 1. From the main menu, select "Network Tools" 648 | 2. Choose "Configure Wireless Network" 649 | 3. Select the wireless interface 650 | 4. Scan for networks and select one 651 | 5. Enter the network password 652 | 653 | Example command-line alternative: 654 | ```bash 655 | # Scan for networks 656 | iwlist wlan0 scan 657 | 658 | # Connect to WPA/WPA2 network 659 | wpa_passphrase MyNetwork MyPassword > /etc/wpa_supplicant.conf 660 | wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf 661 | dhclient wlan0 662 | ``` 663 | 664 | #### Remote Access 665 | 666 | If your build includes SSH: 667 | 668 | 1. From the main menu, select "Network Tools" 669 | 2. Choose "Enable SSH Server" 670 | 3. Set a root password when prompted 671 | 672 | The system will display the IP address and connection instructions. 673 | 674 | Example command-line alternative: 675 | ```bash 676 | # Start SSH server 677 | passwd root # Set a password 678 | /etc/init.d/sshd start 679 | 680 | # Check your IP address 681 | ip addr show 682 | ``` 683 | 684 | ## Troubleshooting 685 | 686 | ### Boot Issues 687 | 688 | #### System Doesn't Boot OneFileLinux 689 | 690 | 1. Verify that your system boots in UEFI mode, not legacy BIOS 691 | 2. Check that the EFI file is in the correct location 692 | 3. For USB boot, ensure the drive is formatted as GPT with FAT32 693 | 4. Try using the UEFI boot menu (F12, F10, Esc, etc. during startup) 694 | 695 | #### Black Screen After Booting 696 | 697 | 1. Try booting with basic video mode (add `nomodeset` to kernel parameters) 698 | 2. If using NVIDIA graphics, try the `nouveau.modeset=0` kernel parameter 699 | 700 | #### No Keyboard or Mouse Input 701 | 702 | 1. Check that USB ports are working 703 | 2. Try different USB ports, particularly USB 2.0 ports 704 | 3. For exotic hardware, try a PS/2 keyboard if available 705 | 706 | ### Hardware Compatibility 707 | 708 | #### Storage Devices Not Detected 709 | 710 | 1. Check SATA/NVMe controller mode in BIOS (AHCI mode is preferred) 711 | 2. For NVMe drives, ensure your build includes NVMe support 712 | 3. For unusual storage controllers, load additional drivers: 713 | ```bash 714 | modprobe driver_name 715 | ``` 716 | 717 | #### Network Interfaces Not Working 718 | 719 | 1. Check if the interface is detected: 720 | ```bash 721 | ip link show 722 | ``` 723 | 2. For wireless adapters, verify driver loading: 724 | ```bash 725 | lspci -k | grep -A 3 Network 726 | ``` 727 | 3. Load additional drivers if needed: 728 | ```bash 729 | modprobe driver_name 730 | ``` 731 | 732 | ### Common Errors 733 | 734 | #### "No such file or directory" when mounting 735 | 736 | The specified device doesn't exist or has a different name. Check available devices: 737 | ```bash 738 | fdisk -l 739 | # OR 740 | lsblk 741 | ``` 742 | 743 | #### "Unknown filesystem type" when mounting 744 | 745 | Your build may not include support for that filesystem. Try specifying the filesystem type: 746 | ```bash 747 | mount -t filesystem_type /dev/device /mount_point 748 | ``` 749 | 750 | #### "Can't read superblock" when checking filesystem 751 | 752 | The filesystem may be severely corrupted. Try alternative superblocks: 753 | ```bash 754 | # For ext filesystems, find backup superblocks 755 | mke2fs -n /dev/device 756 | 757 | # Then use a backup superblock 758 | fsck.ext4 -b 32768 /dev/device 759 | ``` 760 | 761 | #### ZFS pool can't be imported 762 | 763 | Try forcing the import: 764 | ```bash 765 | zpool import -f pool_name 766 | # If that fails, try with all pools 767 | zpool import -fA 768 | # For severe cases, try 769 | zpool import -fFX pool_name 770 | ``` 771 | 772 | ## Advanced Usage 773 | 774 | ### Custom Configurations 775 | 776 | #### Adding Custom Utilities 777 | 778 | If you've built OneFileLinux yourself, you can add custom utilities by: 779 | 780 | 1. Modifying the package list in `02_chrootandinstall.sh` 781 | 2. Adding custom scripts to the `zfiles/` directory 782 | 3. Rebuilding the system 783 | 784 | #### Creating Custom Recovery Scripts 785 | 786 | Create custom recovery scripts by adding them to the system: 787 | 788 | 1. Mount your root filesystem: 789 | ```bash 790 | mount /dev/sda1 /mnt 791 | ``` 792 | 793 | 2. Create a script in a persistent location: 794 | ```bash 795 | vi /mnt/usr/local/bin/my-recovery.sh 796 | chmod +x /mnt/usr/local/bin/my-recovery.sh 797 | ``` 798 | 799 | ### Recovery Scenarios 800 | 801 | #### Recovering from Deleted Partition Table 802 | 803 | 1. Boot into OneFileLinux 804 | 2. Use TestDisk to scan for lost partitions: 805 | ```bash 806 | testdisk /dev/sda 807 | ``` 808 | 3. Follow the prompts to search for lost partitions 809 | 4. Write the recovered partition table 810 | 811 | #### Rescuing Files from Failed Drive 812 | 813 | 1. Boot into OneFileLinux 814 | 2. If the drive is physically failing, create a disk image: 815 | ```bash 816 | ddrescue /dev/failed_drive /mnt/backup/disk.img /mnt/backup/logfile 817 | ``` 818 | 3. Mount the image and recover files: 819 | ```bash 820 | mount -o loop /mnt/backup/disk.img /mnt/recovered 821 | ``` 822 | 823 | #### Fixing Boot Problems 824 | 825 | 1. Boot into OneFileLinux 826 | 2. For Linux boot issues: 827 | ```bash 828 | mount /dev/sda1 /mnt # Mount root filesystem 829 | mount /dev/sda2 /mnt/boot # Mount boot filesystem if separate 830 | mount --bind /dev /mnt/dev 831 | mount --bind /proc /mnt/proc 832 | mount --bind /sys /mnt/sys 833 | chroot /mnt 834 | grub-install /dev/sda 835 | update-grub 836 | exit 837 | ``` 838 | 839 | 3. For Windows boot issues, use the Boot Repair menu option 840 | 841 | ### Performance Considerations 842 | 843 | #### Working with Large Drives 844 | 845 | For large drives (>2TB), use these optimizations: 846 | 847 | 1. Set a larger block size when creating filesystems: 848 | ```bash 849 | mkfs.ext4 -b 4096 /dev/device 850 | ``` 851 | 852 | 2. For large file operations, adjust buffer size: 853 | ```bash 854 | cp --buffer-size=16M source destination 855 | ``` 856 | 857 | #### Memory Optimization 858 | 859 | If OneFileLinux is running slowly due to memory constraints: 860 | 861 | 1. Create and use a swap file: 862 | ```bash 863 | dd if=/dev/zero of=/tmp/swap bs=1M count=1024 864 | mkswap /tmp/swap 865 | swapon /tmp/swap 866 | ``` 867 | 868 | 2. Clear disk caches if needed: 869 | ```bash 870 | echo 3 > /proc/sys/vm/drop_caches 871 | ``` 872 | 873 | #### Speeding Up Filesystem Checks 874 | 875 | For large filesystems, speed up checks by: 876 | 877 | 1. Using multiple passes with optimized options: 878 | ```bash 879 | # For ext4 880 | fsck.ext4 -C0 -f -y /dev/device 881 | ``` 882 | 883 | 2. For ZFS scrubs, set a higher priority: 884 | ```bash 885 | zpool scrub -p high poolname 886 | ``` 887 | 888 | --- 889 | 890 | ## Developer Documentation 891 | 892 | This section provides technical documentation for developers who want to understand or contribute to the OneFileLinux build system. 893 | 894 | ### Build System Architecture 895 | 896 | OneFileLinux uses a modular build system designed to create a small, single-file EFI executable containing a complete Linux environment: 897 | 898 | #### Library Scripts (80-89 range) 899 | 900 | - **80_common.sh**: Core utilities, logging, and environment detection 901 | - **81_error_handling.sh**: Error handling and recovery mechanisms 902 | - **82_build_helper.sh**: File operations, environment adaptations, and feature flag parsing 903 | - **83_config_helper.sh**: Configuration management 904 | - **84_build_core.sh**: Kernel building, ZFS module building, and EFI file creation 905 | 906 | #### Build Scripts (00-10, 99 range) 907 | 908 | Sequential build steps: 909 | - **01_get.sh**: Download Alpine Linux, Linux kernel, and ZFS sources 910 | - **02_chrootandinstall.sh**: Configure Alpine Linux chroot and install packages 911 | - **03_conf.sh**: Configure system services and apply kernel configuration overlays 912 | - **04_build.sh**: Build Linux kernel and create EFI file 913 | 914 | #### Master Build Scripts 915 | 916 | - **build.sh**: Unified build script (local build, assumes Alpine environment) 917 | - **docker/build-onefilelinux.sh**: Docker-based build launcher (recommended for cross-platform) 918 | 919 | ### Feature Flag System 920 | 921 | OneFileLinux's feature flags control which components are included in the build, affecting size and functionality: 922 | 923 | #### High-Level Build Profiles 924 | 925 | | Profile | Flag | Description | Typical Size | 926 | |---------|------|-------------|--------------| 927 | | Minimal | `--minimal` | Essential functionality only | ~4MB | 928 | | Standard | (default) | Balanced configuration | ~20MB | 929 | | Full | `--full` | All features included | ~40-60MB | 930 | 931 | ##### Understanding Build Configurations 932 | 933 | ###### Minimal Build 934 | 935 | The minimal build creates an ultra-small EFI file with only essential functionality, optimized for emergency scenarios where space is extremely limited. 936 | 937 | What's Included: 938 | - Base system (openrc, bash, parted) 939 | - Basic EFI boot functionality 940 | - Essential filesystem support (ext4, FAT/vFAT) 941 | - Command-line interface 942 | 943 | What's Excluded: 944 | - ZFS and other advanced filesystem support 945 | - Recovery tools (testdisk, ddrescue) 946 | - Network tools and diagnostics 947 | - Encryption support 948 | - Text User Interface (TUI) 949 | - Hardware diagnostics 950 | - All advanced package groups 951 | 952 | Impact on Usage: 953 | - Command-line only interface (no TUI) 954 | - Limited recovery capabilities 955 | - Basic filesystem operations only 956 | - Reduced hardware support 957 | - Minimal network functionality 958 | 959 | Best Uses: 960 | - Emergency boot scenarios 961 | - Systems with very small EFI partitions 962 | - Creating a minimal recovery option 963 | - Base for custom minimal builds 964 | - Ultra-fast boot requirements 965 | 966 | ###### Standard Build 967 | 968 | The standard build provides a balanced configuration suitable for most recovery operations while maintaining reasonable size. 969 | 970 | What's Included: 971 | - Complete multi-core processor support 972 | - Hardware acceleration (Intel AES-NI, Padlock) 973 | - Comprehensive storage drivers (SATA, AHCI, NVMe, USB) 974 | - Full ZFS support with all compression options 975 | - Common filesystems (Ext4, vFAT, XFS) 976 | - Complete TCP/IP networking stack 977 | - Firewall capabilities (Netfilter/NFTables) 978 | - Disk encryption (LUKS/dm-crypt) 979 | - Logical Volume Management (LVM) 980 | - Text-based user interface 981 | 982 | Impact on System: 983 | - Moderate memory usage 984 | - Balanced boot time 985 | - Good hardware compatibility 986 | - Comprehensive recovery capabilities 987 | - Full filesystem support for data recovery 988 | - Network diagnostics for remote recovery 989 | 990 | Best Uses: 991 | - Standard recovery operations 992 | - Data rescue from most filesystem types 993 | - System repair on typical hardware 994 | - Network-based recovery scenarios 995 | - Boot repair operations 996 | 997 | #### Core Feature Flags 998 | 999 | ##### Core Package Groups 1000 | 1001 | These package groups are enabled by default in standard builds and can be individually controlled: 1002 | 1003 | | Package Group | Enabled By | Included Packages | 1004 | |---------------|------------|-------------------| 1005 | | Base System | (always included) | openrc, nano, mc, bash, parted, dropbear, dropbear-ssh, efibootmgr, e2fsprogs, e2fsprogs-extra, dosfstools, dmraid, fuse, gawk, grep, sed, util-linux, wget | 1006 | | ZFS Support | `INCLUDE_ZFS` | zfs, util-linux-dev, util-linux-misc, util-linux, util-linux-bash-completion | 1007 | | BTRFS Support | `INCLUDE_BTRFS` | btrfs-progs | 1008 | | Recovery Tools | `INCLUDE_RECOVERY_TOOLS` | testdisk, ddrescue, rsync, unzip, tar | 1009 | | Network Tools | `INCLUDE_NETWORK_TOOLS` | curl, rsync, iperf3, tcpdump, nftables | 1010 | | Crypto Support | `INCLUDE_CRYPTO` | cryptsetup, lvm2, mdadm | 1011 | | Text UI | `INCLUDE_TUI` | ncurses-terminfo-base, less | 1012 | 1013 | | Flag | Default | Description | 1014 | |------|---------|-------------| 1015 | | `--with-zfs` / `--without-zfs` | ON | ZFS filesystem support | 1016 | | `--with-network-tools` / `--without-network-tools` | ON | Network support | 1017 | | `--with-crypto` / `--without-crypto` | ON | Encryption support | 1018 | | `--with-tui` / `--without-tui` | ON | Text user interface | 1019 | | `--minimal-kernel` / `--standard-kernel` | standard | Kernel size optimization | 1020 | 1021 | #### Advanced Package Groups 1022 | 1023 | | Flag | Default | Description | 1024 | |------|---------|-------------| 1025 | | `--with-advanced-fs` / `--without-advanced-fs` | OFF | Advanced filesystem tools | 1026 | | `--with-disk-diag` / `--without-disk-diag` | OFF | Hardware diagnostics | 1027 | | `--with-data-recovery` / `--without-data-recovery` | OFF | Data recovery utilities | 1028 | | `--with-boot-repair` / `--without-boot-repair` | OFF | Boot repair tools | 1029 | 1030 | All features are controlled through the `parse_build_flags()` function in `82_build_helper.sh`, ensuring consistent behavior across build environments. 1031 | 1032 | ### Kernel Configuration System 1033 | 1034 | The kernel configuration system balances size with functionality: 1035 | 1036 | 1. Base configurations: 1037 | - **minimal.config**: Size-optimized minimal kernel 1038 | - **standard.config**: Balanced configuration with common drivers 1039 | 1040 | 2. Feature overlays: Conditionally applied based on feature flags 1041 | - **zfs-support.conf**: ZFS filesystem kernel support 1042 | - **network-tools.conf**: Network protocol and driver support 1043 | - **crypto-support.conf**: Encryption support 1044 | 1045 | The overlay system in `03_conf.sh` respects feature flags, particularly `INCLUDE_MINIMAL_KERNEL`, which skips most overlays for minimal builds. 1046 | 1047 | ### Build Environments 1048 | 1049 | OneFileLinux supports multiple build environments, with Docker being the recommended approach for cross-platform development: 1050 | 1051 | #### Docker Build (Recommended) 1052 | 1053 | ```bash 1054 | cd docker 1055 | ./build-onefilelinux.sh -b "--minimal" # or any other build flags 1056 | ``` 1057 | 1058 | The Docker approach: 1059 | - Works on any system that supports Docker (Linux, macOS, Windows) 1060 | - Handles all dependencies automatically 1061 | - Produces consistent results across different host systems 1062 | - Properly manages permissions and resource allocation 1063 | 1064 | #### Local Build 1065 | 1066 | ```bash 1067 | cd build 1068 | ./build.sh --minimal # or any other build flags 1069 | ``` 1070 | 1071 | Local builds: 1072 | - Assume an Alpine Linux-based environment 1073 | - Require all dependencies to be installed 1074 | - Need appropriate permissions for chroot operations 1075 | 1076 | ### CI/CD System 1077 | 1078 | GitHub Actions workflow in `.github/workflows/docker-build.yml`: 1079 | - Builds multiple configurations in parallel (minimal, standard, full) 1080 | - Uses the same Docker container as local builds 1081 | - Creates artifacts for each build configuration 1082 | - Creates release packages for tagged builds that match 'v*' pattern 1083 | - Uses a default root password of 'onefilelinux' for all GitHub Actions release builds, unlike local builds which generate random passwords by default 1084 | 1085 | ### Best Practices for Development 1086 | 1087 | 1. **Use Docker for Development**: 1088 | - Provides the most consistent build environment 1089 | - Works across all platforms 1090 | - Eliminates dependency and permission issues 1091 | 1092 | 2. **Maintain Small Image Size**: 1093 | - OneFileLinux's primary advantage is being a tiny, single-file EFI executable (minimal: ~4MB, standard: ~20MB) 1094 | - Make features optional with feature flags 1095 | - Consider size impact for all changes 1096 | 1097 | 3. **Follow the Library Pattern**: 1098 | - Use established library functions 1099 | - Maintain separation of concerns 1100 | - Respect feature flags throughout the codebase 1101 | 1102 | 4. **Test Across Environments**: 1103 | - Verify builds work in Docker and GitHub Actions 1104 | - Test both minimal and full configurations 1105 | - Boot test on real hardware 1106 | 1107 | This User Guide is continuously improved. Please refer to the official documentation repository for the latest version and additional information. --------------------------------------------------------------------------------