-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
virt/incus: Add support for building and running incus containers
- Loading branch information
1 parent
d9bd2b2
commit 33f71fd
Showing
12 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Containerized: Incus | ||
|
||
This package builds a SkiffOS system for use as a Incus container image. | ||
|
||
[Incus](https://linuxcontainers.org/incus/) containers are versatile system containers that, as opposed to application containers like docker, emulate a full init system by default ([more details here](https://linuxcontainers.org/incus/docs/main/explanation/containers_and_vms/)) and are therefore well suited for multi service/container deployments. Incus utilizes the [LXC](https://linuxcontainers.org/) APIs internally and provides a powerful toolset on top of them. | ||
|
||
Building and starting the container requires incus to be installed and running on the host and the executing user to be in the `incus-admin` group. | ||
|
||
## Example | ||
|
||
```bash | ||
SKIFF_CONFIG=virt/incus make configure compile # Compile the system | ||
make cmd/virt/incus/buildimage | ||
make cmd/virt/incus/run | ||
``` | ||
|
||
Executing a shell in the container: | ||
|
||
```sh | ||
$ make cmd/virt/incus/exec | ||
# alternatively | ||
$ incus exec skiff -- sh | ||
``` | ||
|
||
## Persistence | ||
|
||
When using the included command `cmd/virt/incus/run` for creating the container, a persistence volume will be created in the first incus storage pool available and attached to the container. If you want to reset the persistence volume, just delete it, so it will be recreated: | ||
|
||
```sh | ||
# You can find the right storage pool with: | ||
# incus storage list -c n -f csv | head -n 1 | ||
incus volume delete "${STORAGE_POOL}" skiff-persist | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# BR2_PACKAGE_LINUX_FIRMWARE is not set | ||
# BR2_PACKAGE_RTL8812AU_AIRCRACK_NG is not set | ||
# BR2_PACKAGE_RTL8821CU is not set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# We don't need a kernel for Docker. | ||
# BR2_LINUX_KERNEL is not set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BR2_TARGET_ROOTFS_TAR=y | ||
# BR2_TARGET_ROOTFS_ISO9660 is not set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
BR2_PACKAGE_BASH=y | ||
BR2_PACKAGE_WHICH=y | ||
BR2_SYSTEM_BIN_SH_BASH=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
buildimage: | ||
@$(SKIFF_CURRENT_CONF_DIR)/scripts/buildimage.sh | ||
run: | ||
@$(SKIFF_CURRENT_CONF_DIR)/scripts/run.sh | ||
exec: | ||
@$(SKIFF_CURRENT_CONF_DIR)/scripts/exec.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
run Start the incus container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
util/rootlogin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Run Skiff in an inucs container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
set -ex | ||
|
||
IMAGE_NAME=skiffos/testing | ||
CONTAINER=skiff | ||
OUTPUT_PATH="$BUILDROOT_DIR/output" | ||
IMAGES_PATH="$BUILDROOT_DIR/images" | ||
WORKING_PATH="${BUILDROOT_DIR}/nspawn-run" | ||
PERSIST_PATH="${WORKING_PATH}/nspawn-persist" | ||
INCUS_IMAGE_PATH="${IMAGE_PATH}/incus.tar.gz" | ||
roottar="${IMAGES_PATH}/rootfs.tar" | ||
|
||
if ! command -v incus > /dev/null 2>&1 | ||
then | ||
echo "Failed to find the incus command. Is incus installed on your host system?" | ||
exit 1 | ||
fi | ||
|
||
mkdir -p "${PERSIST_PATH}" | ||
TMPDIR="${WORKING_PATH}/incus-tmp" | ||
trap 'rm -rf "$TMPDIR";' EXIT | ||
rm -rf "$TMPDIR" | ||
mkdir -p "${TMPDIR}/rootfs" | ||
tar -xf "$roottar" -C "$TMPDIR/rootfs" | ||
pushd "$TMPDIR" | ||
creationtime="$(date +%s)" | ||
default_metadata="architecture: x86_64 | ||
creation_date: $creationtime | ||
properties: | ||
description: SkiffOS | ||
os: Linux x86 | ||
release: unknown" | ||
echo "${INCUS_METADATA:-"${default_metadata}"}" > "${TMPDIR}/metadata.yaml" | ||
tar caf "${INCUS_IMAGE_PATH}" rootfs metadata.yaml | ||
popd | ||
|
||
echo "Incus image generated successfully as ${IMAGE_NAME}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
command -v incus > /dev/null 2>&1 || { | ||
echo "Failed to find the incus command. Is incus installed on your host system?" | ||
exit 1 | ||
} | ||
|
||
incus show skiff > /dev/null || { | ||
echo "Failed to find the skiff container. Did you execute \`make cmd/virt/incus/run\`?" | ||
exit 1 | ||
} | ||
|
||
incus exec skiff -- sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
IMAGE_NAME=skiffos/testing | ||
CONTAINER=skiff | ||
IMAGES_PATH="$BUILDROOT_DIR/images" | ||
INCUS_IMAGE_PATH="${IMAGE_PATH}/incus.tar.gz" | ||
|
||
if ! command -v incus > /dev/null 2>&1 | ||
then | ||
echo "Failed to find the incus command. Is incus installed on your host system?" | ||
exit 1 | ||
fi | ||
|
||
if ! [[ -f "${INCUS_IMAGE_PATH}" ]] > /dev/null | ||
then | ||
echo "${INCUS_IMAGE_PATH} not found. Did you execute \`make cmd/virt/incus/buildimage\`?" | ||
exit 1 | ||
fi | ||
|
||
if incus image show "${IMAGE_NAME}" >/dev/null 2>&1 | ||
then | ||
incus image delete "${IMAGE_NAME}" | ||
fi | ||
incus image import --alias "${IMAGE_NAME}" "${INCUS_IMAGE_PATH}" | ||
|
||
storage_pool="$(incus storage list -c n -f csv | head -n 1)" | ||
|
||
if ! incus storage volume show "$storage_pool" skiff-persist >/dev/null 2>&1 | ||
then | ||
incus storage volume create "$storage_pool" "skiff-persist" | ||
fi | ||
|
||
if incus show "${CONTAINER}" | ||
then | ||
incus stop "${CONTAINER}" ||: | ||
incus rm -f "${CONTAINER}" ||: | ||
fi | ||
|
||
incus create "${IMAGE_NAME}" "${CONTAINER}" | ||
incus storage volume attach "$storage_pool" skiff-persist skiff /mnt/persist | ||
#incus config device add "${CONTAINER}" images-disk source="${IMAGES_PATH}" path=/mnt/rootfs | ||
incus start "${CONTAINER}" | ||
|
||
echo "Incus container started as ${CONTAINER}." |