@@ -13,10 +13,10 @@ AI_BUILD_DIR="${WORK_DIR}/ai_build"
1313ISO_NAME=" LuminOS-0.2.1-amd64.iso"
1414
1515# Cleanup
16- sudo umount " ${CHROOT_DIR} /sys " & > /dev/null || true
17- sudo umount " ${CHROOT_DIR} /proc" & > /dev/null || true
18- sudo umount " ${CHROOT_DIR} /dev/pts " & > /dev/null || true
19- sudo umount " ${CHROOT_DIR} /dev " & > /dev/null || true
16+ # Unmount in reverse order if they exist
17+ for mount_point in " ${CHROOT_DIR} /sys " " ${CHROOT_DIR} / proc" " ${CHROOT_DIR} /dev/pts " " ${CHROOT_DIR} /dev " ; do
18+ mountpoint -q " $mount_point " 2 > /dev/null && sudo umount " $mount_point " || true
19+ done
2020pkill -f " ollama serve" || true
2121sudo rm -rf " ${WORK_DIR} "
2222sudo rm -f " ${BASE_DIR} /${ISO_NAME} "
6969# 3b. CUT LARGE FILES (The Key Fix)
7070echo " --> Cutting large AI files into 1GB chunks..."
7171# Find files > 900MB (safety margin) inside the models directory
72- find " ${TARGET_MODEL_DIR} " -type f -size +900M | while read file; do
72+ while IFS= read -r -d ' ' file; do
7373 echo " Splitting $file ..."
7474 # Split into chunks named .partaa, .partab, etc.
7575 split -b 900M " $file " " $file .part"
7676 # Create a marker file to tell the OS this file needs reassembly
7777 touch " $file .is_split"
7878 # Remove the original giant file so it doesn't get into the ISO
7979 rm " $file "
80- done
80+ done < <( find " ${TARGET_MODEL_DIR} " -type f -size +900M -print0 )
8181
8282# --- 4. Bootstrap System ---
8383echo " --> Bootstrapping Debian..."
@@ -131,7 +131,7 @@ echo "--> Creating Layers..."
131131
132132# Layer 1: OS (Excluding models path)
133133echo " Layer 1 (OS)..."
134- mksquashfs " ${CHROOT_DIR} " " ${ISO_DIR} /live/01-filesystem.squashfs" -e boot -e usr/share/ollama/.ollama -comp zstd
134+ mksquashfs " ${CHROOT_DIR} " " ${ISO_DIR} /live/01-filesystem.squashfs" -e boot -e usr/share/ollama/.ollama -comp zstd -processors " $( nproc ) "
135135
136136# Prepare distribution directories
137137L2=" ${WORK_DIR} /layer2"
@@ -152,7 +152,7 @@ mkdir -p "$L3/usr/share/ollama/.ollama/blobs"
152152mkdir -p " $L4 /usr/share/ollama/.ollama/blobs"
153153
154154COUNT=0
155- find " ${TARGET_MODEL_DIR} /blobs " -type f | while read file; do
155+ while IFS= read -r -d ' ' file; do
156156 MOD=$(( COUNT % 3 ))
157157 if [ $MOD -eq 0 ]; then
158158 cp " $file " " $L2 /usr/share/ollama/.ollama/blobs/"
@@ -162,14 +162,14 @@ find "${TARGET_MODEL_DIR}/blobs" -type f | while read file; do
162162 cp " $file " " $L4 /usr/share/ollama/.ollama/blobs/"
163163 fi
164164 COUNT=$(( COUNT + 1 ))
165- done
165+ done < <( find " ${TARGET_MODEL_DIR} /blobs " -type f -print0 )
166166
167167echo " Layer 2..."
168- mksquashfs " $L2 " " ${ISO_DIR} /live/02-ai-part1.squashfs" -comp zstd
168+ mksquashfs " $L2 " " ${ISO_DIR} /live/02-ai-part1.squashfs" -comp zstd -processors " $( nproc ) "
169169echo " Layer 3..."
170- mksquashfs " $L3 " " ${ISO_DIR} /live/03-ai-part2.squashfs" -comp zstd
170+ mksquashfs " $L3 " " ${ISO_DIR} /live/03-ai-part2.squashfs" -comp zstd -processors " $( nproc ) "
171171echo " Layer 4..."
172- mksquashfs " $L4 " " ${ISO_DIR} /live/04-ai-part3.squashfs" -comp zstd
172+ mksquashfs " $L4 " " ${ISO_DIR} /live/04-ai-part3.squashfs" -comp zstd -processors " $( nproc ) "
173173
174174# --- 7. Bootloader & Final ISO ---
175175echo " --> Bootloader..."
0 commit comments