Overview
All IC-OS images (SetupOS, HostOS, and GuestOS) are built using Bazel. The build process uses a Docker-based approach to create reproducible disk images that can be deployed on bare metal or virtual machines.IC-OS images are first created as Docker images and then transformed into “bare-metal” or “virtual-metal” images that can boot outside containerization.
Prerequisites
Required Software
Building IC-OS images requires several packages and tools:Install Bazel
Follow the official Bazel installation guide for your platform.
Using Container for Building
Build Targets
Each IC-OS image has multiple build target variations:- SetupOS
- HostOS
- GuestOS
prod: Production image (no console access)dev: Development image (console enabled)
Production vs Development Images
The key differences betweenprod and dev targets:
| Feature | Production (prod) | Development (dev) |
|---|---|---|
| Console Access | Disabled | Enabled |
| Root Login | Disabled | Enabled (user: root, password: root) |
| Debugging | Minimal | Full debugging support |
| Use Case | Production deployments | Testing and development |
Building Images
Basic Build Command
Use the following command pattern to build IC-OS images:Build Examples
Build Output Location
All IC-OS image build outputs are stored in the Bazel output directory:Build Artifacts
The build process produces several artifacts:disk.img: Bootable disk imageupdate.tar: Update package for upgrading running nodesSHA256SUMS: Checksums for verification- Additional metadata files
Build Process Details
Understanding how IC-OS images are constructed helps with troubleshooting and customization.Two-Stage Docker Build
The Docker build process is split into two stages for reproducibility:Dockerfile.base
Base Image CreationLocation:
ic/ic-os/{setupos,hostos,guestos}/context/Dockerfile.base- Installs all upstream Ubuntu packages
- Versions can change as updates are published
- CI pipeline builds new base images weekly
- Published to DFINITY Docker Hub
Weekly base image updates ensure security patches are incorporated while maintaining build determinism through pinned versions.
Image Transformation
After Docker build, the image is transformed for bare-metal/VM use:Docker to Disk Image
Docker to Disk Image
The Docker container image is converted into a bootable disk image:
- Extracts filesystem from Docker layers
- Creates partition table
- Formats partitions (ext4, vfat)
- Installs bootloader (GRUB)
- Sets up A/B partition structure
Bootloader Configuration
Bootloader Configuration
GRUB bootloader is configured for:
- EFI boot
- A/B partition switching
- Secure boot (for production)
- Kernel parameters
Minimal Runtime
Minimal Runtime
The resulting system is minimal:
- Only essential systemd services
- No unnecessary packages
- Read-only root filesystem
- Optimized for IC workload
All pre-configuration is performed using Docker utilities. The system is actually operational as a Docker container, allowing some development and testing on the Docker image itself.
Binary Injection
As a caching optimization, IC services and binaries are injected late in the build:Binary Injection
IC-specific components are added after rootfs is complete:
- Replica binary
- Orchestrator
- IC tools and utilities
- Configuration scripts
defs.bzl file for each OS.
Build Configuration Files
Several configuration files control the build process:Package Lists
Packages to install are defined in:Base Image References
The base image hash is specified in:Component Files
IC-specific files and components are enumerated in:Bazel Build Macro
The main build logic is in:Adding Dependencies
To add a new package to an IC-OS image:Commit and Wait for CI
Commit the changes and wait for CI to build and publish the new base image:
The CI pipeline runs weekly to build new base images. You may need to wait for the next scheduled build.
Update Base Image Hash
Once the new base image is published, update the hash reference:The new hash will be available from the CI build output or Docker Hub.
Adding IC-OS Files
To add custom files or components to an IC-OS build:Add Files to Components Directory
Place your files in the appropriate location:Organize by:
components/guestos/- GuestOS-specific filescomponents/hostos/- HostOS-specific filescomponents/setupos/- SetupOS-specific filescomponents/common/- Shared files
Removing IC-OS Files
To remove files from an IC-OS build:Update All .bzl Files
Remove the file enumeration from ALL
.bzl files that referenced them:components/guestos.bzlcomponents/hostos.bzlcomponents/setupos.bzl
Troubleshooting Builds
Build fails with missing dependencies
Build fails with missing dependencies
Solution: Install required packages or use the container build environment:
Docker base image not found
Docker base image not found
Solution: Wait for CI to publish the base image, or build it locally:
Bazel cache issues
Bazel cache issues
Solution: Clean Bazel cache and rebuild:
Build is very slow
Build is very slow
Solution:
- Use
bazel buildwith--jobsflag to control parallelism - Ensure sufficient disk space for Bazel cache
- Use container build environment
- Consider building only the specific OS you need
Image fails to boot
Image fails to boot
Common causes:
- Missing bootloader configuration
- Incorrect partition layout
- Missing kernel or initrd
Testing Built Images
Testing GuestOS
Run GuestOS image locally with QEMU:Testing SetupOS
Write SetupOS image to USB and test on physical hardware:Testing HostOS
HostOS is typically tested as part of the full deployment with GuestOS.Build Optimization
Incremental Builds
Bazel caches build artifacts. To take advantage:- Keep Bazel output directory (
bazel-bin/) intact - Use
bazel buildinstead ofbazel cleanwhen possible - Only clean when necessary (dependency changes, build issues)
Parallel Builds
Control build parallelism:Remote Caching
If configured, Bazel can use remote caching to share build artifacts:Next Steps
GuestOS Details
Learn about GuestOS components and architecture
HostOS Details
Understand HostOS responsibilities
SetupOS Details
Learn about node installation process
Components Development
Deep dive into adding and modifying components