vm broke, lost some work

This commit is contained in:
robojerk 2025-07-24 06:58:49 +00:00
parent f1fd92df62
commit ec1a4f9e01
2 changed files with 194 additions and 1071 deletions

View file

@ -57,6 +57,32 @@ OUTPUT_DIR="$SCRIPT_DIR/output"
CONTAINER_NAME="particleos-builder"
SYSTEM_IMAGE="particleos-system.oci"
# apt-cacher-ng configuration
APT_CACHER_NG_HOST="192.168.1.79"
APT_CACHER_NG_PORT="3142"
APT_CACHER_NG_URL="http://${APT_CACHER_NG_HOST}:${APT_CACHER_NG_PORT}"
# Variables to track cacher usage
CACHER_CONTAINER_BUILD_USED="No (Fallback to direct)"
# Safety check: Ensure BUILD_DIR is within SCRIPT_DIR
if [[ ! "$BUILD_DIR" =~ ^"$SCRIPT_DIR" ]]; then
print_error "BUILD_DIR ($BUILD_DIR) is not within SCRIPT_DIR ($SCRIPT_DIR). Aborting for safety."
fi
# Check if apt-cacher-ng is reachable
check_proxy_reachable() {
print_status "Checking if apt-cacher-ng at $APT_CACHER_NG_HOST:$APT_CACHER_NG_PORT is reachable..."
# Use netcat to check if the port is open
if nc -zv "$APT_CACHER_NG_HOST" "$APT_CACHER_NG_PORT" &>/dev/null; then
print_success "apt-cacher-ng at $APT_CACHER_NG_HOST:$APT_CACHER_NG_PORT is reachable."
return 0 # Reachable
else
print_warning "apt-cacher-ng at $APT_CACHER_NG_HOST:$APT_CACHER_NG_PORT is NOT reachable."
return 1 # Not reachable
fi
}
# Check prerequisites
check_prerequisites() {
print_header "Phase 1: Check Prerequisites"
@ -73,7 +99,7 @@ check_prerequisites() {
# Check for build tools
local missing_packages=()
for package in squashfs-tools xorriso grub-pc-bin grub-efi-amd64-bin isolinux; do
for package in squashfs-tools xorriso grub-pc-bin grub-efi-amd64-bin isolinux syslinux-common netcat-openbsd; do
if ! dpkg -s "$package" &>/dev/null; then
missing_packages+=("$package")
fi
@ -92,6 +118,19 @@ check_prerequisites() {
sudo apt install -y casper
fi
# Check disk space (need at least 10GB free)
local available_space=$(df "$SCRIPT_DIR" | awk 'NR==2 {print $4}')
local required_space=$((10 * 1024 * 1024)) # 10GB in KB
if [ "$available_space" -lt "$required_space" ]; then
print_error "Insufficient disk space. Need at least 10GB free, have $(($available_space / 1024 / 1024))GB"
fi
# Check network connectivity
if ! ping -c 1 archive.ubuntu.com &>/dev/null; then
print_error "Cannot reach Ubuntu archives. Check your internet connection."
fi
print_success "All prerequisites satisfied"
}
@ -102,16 +141,28 @@ clean_build() {
# Clean build directories
if [ -d "$BUILD_DIR" ]; then
print_status "Removing previous build directory: $BUILD_DIR..."
rm -rf "$BUILD_DIR" || print_error "Failed to remove previous build directory."
fi
if [[ "$BUILD_DIR" == "/" ]] || [[ "$BUILD_DIR" == "/home" ]] || [[ "$BUILD_DIR" == "/opt" ]] || \
[[ "$BUILD_DIR" == "/usr" ]] || [[ "$BUILD_DIR" == "/var" ]] || [[ "$BUILD_DIR" == "/etc" ]]; then
print_error "BUILD_DIR ($BUILD_DIR) is a critical system directory. Aborting for safety."
fi
# Remove any existing container
if podman container exists "$CONTAINER_NAME" 2>/dev/null; then
print_status "Removing existing container: $CONTAINER_NAME"
podman container rm "$CONTAINER_NAME" || print_warning "Failed to remove container"
# Force remove any existing container first
if podman container exists "$CONTAINER_NAME" 2>/dev/null; then
print_status "Removing existing container: $CONTAINER_NAME"
podman container rm -f "$CONTAINER_NAME" 2>/dev/null || print_warning "Failed to remove container"
fi
# Force remove any existing images
if podman image exists "$SYSTEM_IMAGE" 2>/dev/null; then
print_status "Removing existing image: $SYSTEM_IMAGE"
podman image rm -f "$SYSTEM_IMAGE" 2>/dev/null || print_warning "Failed to remove image"
fi
sudo rm -rf "$BUILD_DIR" || print_error "Failed to remove previous build directory."
fi
mkdir -p "$BUILD_DIR" "$OUTPUT_DIR" || print_error "Failed to create build directories."
chmod 755 "$OUTPUT_DIR" || print_error "Failed to set permissions on output directory."
print_success "Build environment cleaned"
}
@ -202,8 +253,17 @@ build_bootc_system() {
print_status "Building system using bootc container workflow..."
# Try to use apt-cacher-ng if available for container build
if check_proxy_reachable; then
print_status "Container build will use apt-cacher-ng: $APT_CACHER_NG_URL"
CACHER_CONTAINER_BUILD_USED="Yes"
else
print_warning "apt-cacher-ng not reachable. Container build will proceed without proxy."
CACHER_CONTAINER_BUILD_USED="No (Fallback to direct)"
fi
# Create a Dockerfile that bootc can build from
cat > "$BUILD_DIR/Dockerfile" << 'EOF'
cat > "$BUILD_DIR/Dockerfile" << EOF
# Start with Ubuntu 24.04 base
FROM ubuntu:24.04
@ -211,17 +271,23 @@ FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC
# Configure apt proxy if available
$(if check_proxy_reachable; then
echo "RUN echo 'Acquire::http::Proxy \"$APT_CACHER_NG_URL\";' > /etc/apt/apt.conf.d/01proxy && \\"
echo " echo 'Acquire::https::Proxy \"$APT_CACHER_NG_URL\";' >> /etc/apt/apt.conf.d/01proxy"
fi)
# Update and install base packages
RUN apt update && apt install -y \
systemd \
systemd-sysv \
dbus \
curl \
ca-certificates \
gnupg \
gpgv \
locales \
resolvconf \
RUN apt update && apt install -y \\
systemd \\
systemd-sysv \\
dbus \\
curl \\
ca-certificates \\
gnupg \\
gpgv \\
locales \\
resolvconf \\
&& rm -rf /var/lib/apt/lists/*
# Configure locales
@ -397,6 +463,11 @@ extract_filesystem() {
# Remove the temporary container
podman container rm "$CONTAINER_NAME" || print_warning "Failed to remove container"
# Verify extraction was successful
if [ ! -f "$extract_dir/etc/os-release" ]; then
print_error "Filesystem extraction failed - /etc/os-release not found"
fi
print_success "Filesystem extracted to: $extract_dir"
}
@ -502,26 +573,91 @@ LABEL check
APPEND boot=casper integrity-check initrd=/casper/initrd quiet splash ---
EOF
# Copy ISOLINUX boot files
# Copy ISOLINUX boot files - REVISED PATH DISCOVERY
print_status "Copying ISOLINUX boot files..."
ISOLINUX_BIN_PATH=""
if [ -f "/usr/lib/syslinux/isolinux.bin" ]; then
ISOLINUX_BIN_PATH="/usr/lib/syslinux"
elif [ -f "/usr/lib/ISOLINUX/isolinux.bin" ]; then
ISOLINUX_BIN_PATH="/usr/lib/ISOLINUX"
ISOLINUX_BASE_DIR=""
if [ -d "/usr/lib/syslinux" ]; then
ISOLINUX_BASE_DIR="/usr/lib/syslinux"
elif [ -d "/usr/lib/ISOLINUX" ]; then
ISOLINUX_BASE_DIR="/usr/lib/ISOLINUX"
elif [ -d "/usr/share/syslinux" ]; then
ISOLINUX_BASE_DIR="/usr/share/syslinux"
fi
if [ -z "$ISOLINUX_BIN_PATH" ]; then
print_error "isolinux.bin not found. Please install isolinux."
if [ -z "$ISOLINUX_BASE_DIR" ]; then
print_error "Syslinux base directory not found. Please ensure 'syslinux-utils' or 'isolinux' is installed."
fi
cp "$ISOLINUX_BIN_PATH/isolinux.bin" "$iso_dir/isolinux/" || print_error "Failed to copy isolinux.bin."
ISOLINUX_BIN_SRC=""
LDLINUX_C32_SRC=""
MEMDISK_C32_SRC=""
MBOOT_C32_SRC=""
LIBUTIL_C32_SRC=""
# Copy ldlinux.c32 from the correct location
if [ -f "/usr/lib/syslinux/modules/bios/ldlinux.c32" ]; then
cp "/usr/lib/syslinux/modules/bios/ldlinux.c32" "$iso_dir/isolinux/" || print_error "Failed to copy ldlinux.c32."
else
print_error "ldlinux.c32 not found in /usr/lib/syslinux/modules/bios/."
# Search for isolinux.bin
if [ -f "$ISOLINUX_BASE_DIR/isolinux.bin" ]; then
ISOLINUX_BIN_SRC="$ISOLINUX_BASE_DIR/isolinux.bin"
elif [ -f "$ISOLINUX_BASE_DIR/bios/isolinux.bin" ]; then
ISOLINUX_BIN_SRC="$ISOLINUX_BASE_DIR/bios/isolinux.bin"
fi
# Search for ldlinux.c32 and other common .c32 modules
if [ -f "$ISOLINUX_BASE_DIR/ldlinux.c32" ]; then
LDLINUX_C32_SRC="$ISOLINUX_BASE_DIR/ldlinux.c32"
elif [ -f "$ISOLINUX_BASE_DIR/modules/bios/ldlinux.c32" ]; then
LDLINUX_C32_SRC="$ISOLINUX_BASE_DIR/modules/bios/ldlinux.c32"
elif [ -f "$ISOLINUX_BASE_DIR/isolinux/ldlinux.c32" ]; then
LDLINUX_C32_SRC="$ISOLINUX_BASE_DIR/isolinux/ldlinux.c32"
fi
# Search for other critical .c32 files
if [ -f "$ISOLINUX_BASE_DIR/memdisk/memdisk.c32" ]; then
MEMDISK_C32_SRC="$ISOLINUX_BASE_DIR/memdisk/memdisk.c32"
elif [ -f "$ISOLINUX_BASE_DIR/modules/bios/memdisk.c32" ]; then
MEMDISK_C32_SRC="$ISOLINUX_BASE_DIR/modules/bios/memdisk.c32"
fi
if [ -f "$ISOLINUX_BASE_DIR/mboot.c32" ]; then
MBOOT_C32_SRC="$ISOLINUX_BASE_DIR/mboot.c32"
elif [ -f "$ISOLINUX_BASE_DIR/modules/bios/mboot.c32" ]; then
MBOOT_C32_SRC="$ISOLINUX_BASE_DIR/modules/bios/mboot.c32"
fi
if [ -f "$ISOLINUX_BASE_DIR/libutil.c32" ]; then
LIBUTIL_C32_SRC="$ISOLINUX_BASE_DIR/libutil.c32"
elif [ -f "$ISOLINUX_BASE_DIR/modules/bios/libutil.c32" ]; then
LIBUTIL_C32_SRC="$ISOLINUX_BASE_DIR/modules/bios/libutil.c32"
fi
SYSLINUX_MODULES_PATH=""
if [ -d "/usr/lib/syslinux/modules/bios" ]; then
SYSLINUX_MODULES_PATH="/usr/lib/syslinux/modules/bios"
elif [ -d "/usr/share/syslinux/modules/bios" ]; then
SYSLINUX_MODULES_PATH="/usr/share/syslinux/modules/bios"
fi
if [ -z "$ISOLINUX_BIN_SRC" ]; then
print_error "isolinux.bin not found within detected syslinux paths. Please check your syslinux installation."
fi
if [ -z "$LDLINUX_C32_SRC" ]; then
print_error "ldlinux.c32 not found within detected syslinux paths. Ensure 'syslinux-common' is installed and up-to-date."
fi
cp "$ISOLINUX_BIN_SRC" "$iso_dir/isolinux/" || print_error "Failed to copy isolinux.bin."
cp "$LDLINUX_C32_SRC" "$iso_dir/isolinux/" || print_error "Failed to copy ldlinux.c32."
# Copy other essential .c32 modules that ldlinux.c32 might depend on
if [ -n "$MEMDISK_C32_SRC" ]; then
cp "$MEMDISK_C32_SRC" "$iso_dir/isolinux/" || print_warning "Failed to copy memdisk.c32, continuing anyway."
fi
if [ -n "$MBOOT_C32_SRC" ]; then
cp "$MBOOT_C32_SRC" "$iso_dir/isolinux/" || print_warning "Failed to copy mboot.c32, continuing anyway."
fi
if [ -n "$LIBUTIL_C32_SRC" ]; then
cp "$LIBUTIL_C32_SRC" "$iso_dir/isolinux/" || print_warning "Failed to copy libutil.c32, continuing anyway."
fi
if [ -f "$ISOLINUX_BASE_DIR/menu.c32" ]; then
cp "$ISOLINUX_BASE_DIR/menu.c32" "$iso_dir/isolinux/" || print_warning "Failed to copy menu.c32, continuing anyway."
elif [ -f "$SYSLINUX_MODULES_PATH/menu.c32" ]; then
cp "$SYSLINUX_MODULES_PATH/menu.c32" "$iso_dir/isolinux/" || print_warning "Failed to copy menu.c32, continuing anyway."
fi
# Create basic EFI structure (simplified for now)
@ -539,7 +675,7 @@ EOF
-c isolinux/boot.cat \
-boot-load-size 4 -boot-info-table \
-no-emul-boot \
-isohybrid-mbr "$ISOLINUX_BIN_PATH/isohdpfx.bin" \
-isohybrid-mbr "$ISOLINUX_BASE_DIR/isohdpfx.bin" \
-partition_offset 16 \
-part_like_isohybrid \
-isohybrid-gpt-basdat \
@ -554,7 +690,12 @@ cleanup() {
# Remove any remaining container
if podman container exists "$CONTAINER_NAME" 2>/dev/null; then
podman container rm "$CONTAINER_NAME" 2>/dev/null || true
podman container rm -f "$CONTAINER_NAME" 2>/dev/null || print_warning "Failed to remove container"
fi
# Remove any remaining images
if podman image exists "$SYSTEM_IMAGE" 2>/dev/null; then
podman image rm -f "$SYSTEM_IMAGE" 2>/dev/null || print_warning "Failed to remove image"
fi
print_success "Cleanup completed"
@ -592,6 +733,9 @@ main() {
echo "📁 Location: $OUTPUT_DIR/${PROJECT_NAME}-${BUILD_TIMESTAMP}.iso"
echo "🐳 Container Image: $SYSTEM_IMAGE"
echo ""
echo "Summary of Cacher Usage:"
echo " Container Build: $CACHER_CONTAINER_BUILD_USED"
echo ""
echo "🧪 Test the ISO:"
echo " qemu-system-x86_64 -m 4G -enable-kvm \\"
echo " -cdrom $OUTPUT_DIR/${PROJECT_NAME}-${BUILD_TIMESTAMP}.iso \\"

1047
todo.md

File diff suppressed because it is too large Load diff