Building Container-Optimized OS from the open-source respository

Container-Optimized OS is based on, and built using, tools from the open-source Chromium OS project. If you like, you can build a Container-Optimized OS image yourself directly from the Chromium source code.

Prerequisites

To build a Container-Optimized OS image, you'll need to install the following tools on your development machine:

  • git and curl
  • A package of Chromium scripts called depot_tools

Obtaining the Container-Optimized OS source code

You can download the source code for Container-Optimized OS using repo. First, create a directory to store the source code, and then download it using the following commands:

repo init -u https://chromium.googlesource.com/chromiumos/manifest.git --repo-url https://chromium.googlesource.com/external/repo.git
repo sync

Building a Container-Optimized OS image

To build any Chromium OS project, you must create a suitable chroot environment. You can use the cros_sdk tool included in depot_tools to create and enter a chroot that's ready for Chromium OS compilation by running the following command:

cros_sdk --enter

Once inside chroot, you can build the image. Building any Chromium OS project produces a disk image, which can be customized for different machines (called "boards"). To build Container-Optimized OS, specify lakitu for the board name as follows:

(cr) ~/trunk/src/scripts $ ./build_packages --board=lakitu
(cr) ~/trunk/src/scripts $ ./build_image --board=lakitu [base|dev|test]

You can build either a base, dev, or test image by passing the appropriate parameter to the ./build image script command. If you don't specify a parameter, the dev image is built by default.

The dev image contains some additional debug tools installed on top of the base image. The test image includes the debug tools from the dev image as well as tools necessary for running automatic Chromimum OS tests.

Running Your Image

Once you've built your Container-Optimized OS image, you can run the image using KVM, or import the image to a Compute Engine instance.

Running in KVM

To boot your image in KVM, run the following command:

~/cos $ kvm -m 1024 -nographic -net nic,model=virtio -net user,hostfwd=tcp:127.0.0.1:9222-:22 -hda src/build/images/lakitu/latest/chromiumos_test_image.bin

Booting in this manner leaves the VM's serial port connected to your console, letting you log in without using SSH. If you're running a test image, you can log in with the username/password pair "root/test0000".

Once the VM is started, you can access your dev or test image using SSH. To SSH into the image, use the key generated for that image, as follows:

~/cos $ ssh root@localhost -p 9222 -i src/build/images/lakitu/latest/id_rsa

Running on Compute Engine

To import your image to a Compute Engine instance, you must compress the image into a .tar file. To compress the image, run the following command:

~/cos $ tar -Sczf compressed-image.tar.gz images/lakitu/latest/chromiumos_image.bin --transform 's|images/lakitu/latest/chromiumos_image.bin|disk.raw|'

After you've created your .tar file, you can follow the instructions to import an existing image in the Compute Engine documentation.

Send feedback about...

Container-Optimized OS