11#! /bin/bash
22set -e
33
4- echo " ====== LUMINOS MASTER BUILD SCRIPT (v6.6 - Split SquashFS Layers ) ======"
4+ echo " ====== LUMINOS MASTER BUILD SCRIPT (v7.1 - Multi-Layer AI ) ======"
55if [ " $( id -u) " -ne 0 ]; then echo " ERROR: This script must be run as root." ; exit 1; fi
66
77# --- 1. Define Directories & Vars ---
@@ -42,22 +42,15 @@ mkdir -p "${TARGET_MODEL_DIR}"
4242REAL_USER=" ${SUDO_USER:- $USER } "
4343USER_HOME=$( getent passwd " $REAL_USER " | cut -d: -f6)
4444
45- POSSIBLE_LOCATIONS=(
46- " ${USER_HOME} /.ollama/models"
47- " /usr/share/ollama/.ollama/models"
48- " /var/lib/ollama/.ollama/models"
49- " /root/.ollama/models"
50- )
51-
45+ # Search existing models
5246MODEL_FOUND=false
47+ POSSIBLE_LOCATIONS=(" ${USER_HOME} /.ollama/models" " /root/.ollama/models" " /usr/share/ollama/.ollama/models" )
5348
54- # Search existing models
55- echo " --> Searching for existing models..."
5649for LOC in " ${POSSIBLE_LOCATIONS[@]} " ; do
5750 if [ -d " $LOC " ]; then
5851 SIZE_CHECK=$( du -s " $LOC " | cut -f1)
5952 if [ " $SIZE_CHECK " -gt 1000000 ]; then
60- echo " SUCCESS: Found valid models at $LOC ! Copying..."
53+ echo " SUCCESS: Found models at $LOC ! Copying..."
6154 cp -r " ${LOC} /." " ${TARGET_MODEL_DIR} /"
6255 MODEL_FOUND=true
6356 break
@@ -92,8 +85,7 @@ debootstrap \
9285 " ${CHROOT_DIR} " \
9386 http://ftp.debian.org/debian/
9487
95- # --- 6. Apply Fixes & Prepare Environment ---
96- echo " --> Applying APT fixes..."
88+ # --- 6. Apply Fixes & Environment ---
9789mkdir -p " ${CHROOT_DIR} /etc/apt/apt.conf.d"
9890cat > " ${CHROOT_DIR} /etc/apt/apt.conf.d/99-no-contents" << EOF
9991Acquire::IndexTargets::deb::Contents-deb "false";
@@ -110,14 +102,12 @@ echo "--> Copying assets..."
110102mkdir -p " ${CHROOT_DIR} /usr/share/wallpapers/luminos"
111103cp " ${BASE_DIR} /assets/" * " ${CHROOT_DIR} /usr/share/wallpapers/luminos/"
112104
113- echo " --> Injecting AI Binary (Models come later via SquashFS) ..."
105+ echo " --> Injecting AI Binary..."
114106if [ ! -f " ${AI_BUILD_DIR} /ollama" ]; then
115107 curl -fL " https://github.com/ollama/ollama/releases/download/v0.1.32/ollama-linux-amd64" -o " ${AI_BUILD_DIR} /ollama"
116108 chmod +x " ${AI_BUILD_DIR} /ollama"
117109fi
118110cp " ${AI_BUILD_DIR} /ollama" " ${CHROOT_DIR} /usr/local/bin/"
119- # NOTE: We do NOT copy models into CHROOT here. We will build a separate SquashFS for them.
120-
121111
122112# --- 7. Run Customization Scripts ---
123113echo " --> Running customization scripts..."
@@ -131,19 +121,13 @@ cp "${BASE_DIR}/06-final-cleanup.sh" "${CHROOT_DIR}/tmp/"
131121
132122chmod +x " ${CHROOT_DIR} /tmp/" * .sh
133123
134- echo " :: Running 02-configure-system.sh "
124+ echo " :: Running scripts... "
135125chroot " ${CHROOT_DIR} " /tmp/02-configure-system.sh
136- echo " :: Running 03-install-desktop.sh"
137126chroot " ${CHROOT_DIR} " /tmp/03-install-desktop.sh
138- echo " :: Running 04-customize-desktop.sh"
139127chroot " ${CHROOT_DIR} " /tmp/04-customize-desktop.sh
140- echo " :: Running 05-install-ai.sh"
141128chroot " ${CHROOT_DIR} " /tmp/05-install-ai.sh
142- echo " :: Running 07-install-plymouth-theme.sh"
143129chroot " ${CHROOT_DIR} " /tmp/07-install-plymouth-theme.sh
144- echo " :: Running 08-install-software.sh"
145130chroot " ${CHROOT_DIR} " /tmp/08-install-software.sh
146- echo " :: Running 06-final-cleanup.sh"
147131chroot " ${CHROOT_DIR} " /tmp/06-final-cleanup.sh
148132
149133echo " --> Unmounting..."
@@ -152,22 +136,48 @@ umount "${CHROOT_DIR}/proc"
152136umount " ${CHROOT_DIR} /dev/pts"
153137umount " ${CHROOT_DIR} /dev"
154138
155- # --- 8. Build the ISO (Split Layers ) ---
139+ # --- 8. Build the ISO (Multi-Layer Strategy ) ---
156140
157- # Layer 1: The Main OS (excludes /usr/share/ollama/.ollama where models would be)
141+ # Layer 1: Main OS (Base + Desktop + Apps)
142+ # We EXCLUDE the heavy AI models path here
158143echo " --> Compressing Layer 1: Main OS..."
159144mksquashfs " ${CHROOT_DIR} " " ${ISO_DIR} /live/01-filesystem.squashfs" -e boot -e usr/share/ollama/.ollama -comp zstd
160145
161- # Layer 2: The AI Models
162- echo " --> Preparing Layer 2: AI Models..."
163- # We create a temporary structure to mimic the root filesystem for the second layer
164- AI_LAYER_DIR=" ${WORK_DIR} /ai_layer_root"
165- mkdir -p " ${AI_LAYER_DIR} /usr/share/ollama/.ollama"
166- # Copy models into this structure
167- cp -r " ${TARGET_MODEL_DIR} " " ${AI_LAYER_DIR} /usr/share/ollama/.ollama/"
146+ # Layer 2 & 3: AI Models (Split into chunks < 4GB)
147+ echo " --> Preparing AI Layers (Splitting models)..."
148+
149+ # Prepare temporary folders for layers
150+ AI_LAYER_1=" ${WORK_DIR} /ai_layer_1"
151+ AI_LAYER_2=" ${WORK_DIR} /ai_layer_2"
152+ mkdir -p " ${AI_LAYER_1} /usr/share/ollama/.ollama"
153+ mkdir -p " ${AI_LAYER_2} /usr/share/ollama/.ollama"
154+
155+ # Copy all models to Layer 1 first
156+ cp -r " ${TARGET_MODEL_DIR} /." " ${AI_LAYER_1} /usr/share/ollama/.ollama/"
157+
158+ # Move the heavy "blobs" folder to Layer 2 to balance size?
159+ # Better strategy: Move half of the blobs to Layer 2.
160+ BLOB_DIR_1=" ${AI_LAYER_1} /usr/share/ollama/.ollama/blobs"
161+ BLOB_DIR_2=" ${AI_LAYER_2} /usr/share/ollama/.ollama/blobs"
162+ mkdir -p " ${BLOB_DIR_2} "
163+
164+ echo " --> Distributing AI blobs across layers..."
165+ # Move roughly half the blobs to the second layer
166+ count=0
167+ for file in " ${BLOB_DIR_1} " /* ; do
168+ if [ -f " $file " ]; then
169+ if (( count % 2 == 0 )) ; then
170+ mv " $file " " ${BLOB_DIR_2} /"
171+ fi
172+ (( count++ ))
173+ fi
174+ done
175+
176+ echo " --> Compressing Layer 2: AI Part A..."
177+ mksquashfs " ${AI_LAYER_1} " " ${ISO_DIR} /live/02-ai-part-a.squashfs" -comp zstd
168178
169- echo " --> Compressing Layer 2 : AI Models ..."
170- mksquashfs " ${AI_LAYER_DIR } " " ${ISO_DIR} /live/02 -ai-models .squashfs" -comp zstd
179+ echo " --> Compressing Layer 3 : AI Part B ..."
180+ mksquashfs " ${AI_LAYER_2 } " " ${ISO_DIR} /live/03 -ai-part-b .squashfs" -comp zstd
171181
172182echo " --> Preparing Bootloader (GRUB)..."
173183cp " ${CHROOT_DIR} /boot" /vmlinuz* " ${ISO_DIR} /live/vmlinuz"
@@ -183,7 +193,7 @@ menuentry "LuminOS v0.2.1 Live" {
183193EOF
184194
185195echo " --> Generating ISO image..."
186- # No special flags needed now, as individual files are < 4GB !
196+ # No special flags needed now, individual squashfs files are small !
187197grub-mkrescue -o " ${BASE_DIR} /${ISO_NAME} " " ${ISO_DIR} "
188198
189199echo " --> Cleaning up work directory..."
0 commit comments