Shell helpers to setup LXC hypervisors
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Renovate Bot e54d5fb226
Update https://data.forgejo.org/actions/cascading-pr action to v2.3.0 (#46)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [https://data.forgejo.org/actions/cascading-pr](https://code.forgejo.org/actions/cascading-pr) | action | minor | `v2.2.0` -> `v2.3.0` |

---

### Release Notes

<details>
<summary>actions/cascading-pr (https://data.forgejo.org/actions/cascading-pr)</summary>

### [`v2.3.0`](https://code.forgejo.org/actions/cascading-pr/compare/v2.2.1...v2.3.0)

[Compare Source](https://code.forgejo.org/actions/cascading-pr/compare/v2.2.1...v2.3.0)

### [`v2.2.1`](https://code.forgejo.org/actions/cascading-pr/compare/v2.2.0...v2.2.1)

[Compare Source](https://code.forgejo.org/actions/cascading-pr/compare/v2.2.0...v2.2.1)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC), Automerge - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMTMuMyIsInVwZGF0ZWRJblZlciI6IjQxLjExMy4zIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Reviewed-on: forgejo/lxc-helpers#46
Co-authored-by: Renovate Bot <bot@kriese.eu>
Co-committed-by: Renovate Bot <bot@kriese.eu>
2025-09-16 06:58:00 +00:00
.forgejo Update https://data.forgejo.org/actions/cascading-pr action to v2.3.0 (#46) 2025-09-16 06:58:00 +00:00
.editorconfig chore(cleanup): shfmt and .editorconfig applied to all scripts (#28) 2025-01-28 11:25:57 +00:00
.gitignore initial implementation 2023-05-16 23:14:54 +02:00
LICENSE initial implementation 2023-05-16 23:14:54 +02:00
lxc-helpers-lib-test.sh fix(lxc): change ipv6 ula address space to recommend prefix (#32) 2025-01-29 09:13:13 +00:00
lxc-helpers-lib.sh feat: add support for debian trixie (#35) 2025-09-15 09:48:37 +00:00
lxc-helpers.sh feat: add support for debian trixie (#35) 2025-09-15 09:48:37 +00:00
README.md feat: add support for debian trixie (#35) 2025-09-15 09:48:37 +00:00
renovate.json Configure Renovate (#43) 2025-09-15 08:19:14 +00:00
tests.sh feat: add support for debian trixie (#35) 2025-09-15 09:48:37 +00:00

LXC helpers

A set of LXC shell functions to help with:

Install

version=vX.Y.Z # as found in https://code.forgejo.org/forgejo/lxc-helpers/tags
sudo wget -O /usr/local/bin/lxc-helpers-lib.sh https://code.forgejo.org/forgejo/lxc-helpers/raw/tag/$version/lxc-helpers-lib.sh
sudo wget -O /usr/local/bin/lxc-helpers.sh https://code.forgejo.org/forgejo/lxc-helpers/raw/tag/$version/lxc-helpers-lib.sh
sudo chmod +x /usr/local/bin/lxc-helpers*.sh

Example

Install LXC on a host

sudo lxc-helpers.sh lxc_install_lxc_inside 10.4.102 fd30

Create a container

$ git clone https://code.forgejo.org/forgejo/lxc-helpers
$ cd lxc-helpers
$ ./lxc-helpers.sh lxc_container_create mycontainer
$ ./lxc-helpers.sh lxc_container_start mycontainer
$ ./lxc-helpers.sh lxc_container_run mycontainer date
Mon May 29 10:46:57 CEST 2023
$ ./lxc-helpers.sh lxc_container_stop mycontainer
$ ./lxc-helpers.sh lxc_container_destroy mycontainer

Usage

lxc-helpers.sh - LXC container management helpers

SYNOPSIS

   lxc-helpers.sh [-v|--verbose] [-h|--help]
		  [-o|--os {trixie|bookworm|bullseye} (default bookworm)]
		  command [arguments]

   lxc-helpers.sh [-v|--verbose] [-h|--help]
		  [-o|--os {trixie|bookworm|bullseye} (default bookworm)]
		  [-c|--config {unprivileged lxc libvirt docker k8s} (default "lxc libvirt docker")]
		  lxc_container_create [arguments]

DESCRIPTION

   A thin shell based layer on top of LXC to create, populate, run and
   destroy LXC containers. A container is created from a copy of an
   existing container.

   The LXC network is configured to provide a NAT'ed IP address (IPv4
   and IPv6) to each container, in a configurable private range.

CREATE AND DESTROY

   lxc_prepare_environment

       Install LXC dependencies.

   lxc_container_create `name`

       Create the `name` container.

   lxc_container_mount `name` `path`

       Configure `name` container to bind mount `path` so that it is
       also accessible at `path` from within the container.

   lxc_container_start `name`

       Start the `name` container.

   lxc_container_stop `name`

       Stop the `name` container.

   lxc_container_destroy `name`

       Call lxc_container_stop `name` and destroy the container.

   lxc_template_release

       Echo the name of the container for the Operating System
       specified with `--os`.

   lxc_build_template `existing_container` `new_container`

       Copy `existing_container` into `new_container`. If
       `existing_container` is equal to $(lxc-helpers.sh lxc_template_release) it
       will be created on demand.

CONFIGURATION

   The `--config` option provides preset configurations appended to the `/var/lib/lxc/name/config`
   file when the container is created with the `lxc_container_create` command. They are required
   to run the corresponding subsystem:

     * `docker` https://www.docker.com/
     * `lxc` https://linuxcontainers.org/lxc/
     * `libvirt` https://libvirt.org/
     * `k8s` https://kubernetes.io/
     * `unprivileged` none of the above

   Example: lxc-helpers.sh --config "docker libvirt" lxc_container_create mycontainer

   The `unprivileged` configuration does not add anything.

ACTIONS IN THE CONTAINER

   For some command lxc_something `name` that can be called from outside the container
   there is an equivalent function lxc_something_inside that can be called from inside
   the container.

   lxc_install_lxc `name` `prefix` [`prefixv6`]
   lxc_install_lxc_inside `prefix` [`prefixv6`]

      Install LXC in the `name` container to allow the creation of
      named containers. `prefix` is a class C IP prefix from which
      containers will obtain their IP (for instance 10.40.50). `prefixv6`
      is an optional IPv6 private address prefix that defaults to fd15.

   lxc_container_run `name` command [options...]

      Run the `command` within the `name` container.

   lxc_container_run_script `name` `path`
   lxc_container_run_script_as `name` `user` `path`

      Run the script found at `path` within the `name` container. The
      environment is cleared before running the script. The first form
      will run as root, the second form will impersonate `user`.

   lxc_container_user_install `name` `user_id` `user` [`homedir` default `/home`]

      Create the `user` with `user_id` in the `name` container with a
      HOME at `/homedir/user`. Passwordless sudo permissions are
      granted to `user`. It is made a member of the groups docker, kvm
      and libvirt if they exist already. A SSH key is created.

      Example: lxc_container_user_install mycontainer $(id -u) $USER