Scripts for running LXC systems in ramdisk
Go to file
2023-04-10 20:33:27 +02:00
bin v1 2023-04-10 20:33:27 +02:00
templates v1 2023-04-10 20:33:27 +02:00
ramdisk.service v1 2023-04-10 20:33:27 +02:00
README.md v1 2023-04-10 20:33:27 +02:00
setup.sh v1 2023-04-10 20:33:27 +02:00

lxc-ramdisk

Create ramdisks for use in LXC containers for instant startup and destroy. Running mkvm.sh bullseye lsblk (for testing purposes) takes 1.3s on RAM running at 800MHz.

The scripts create two different ramdisks when running ramdisk.sh start (or when the systemd service is started):

  • /ramdisk/sys/ for the base images of supported operating systems
  • /ramdisk/tmp/ for rootfs of the actual containers

When a container is started, it's rootfs is an overlay of /ramdisk/tmp/VM_NAME (read-write) over /ramdisk/sys/VM_TYPE (read-only). This setup allows to start many containers with the same base system without copying it over and over again.

The contents of /ramdisk/sys are copied from /ramdisk/persist when the service is started.

The following systems are supported:

  • bullseye: Debian 11 Bullseye
  • archlinux: Archlinux

Setup

The provided files are provided for Debian bullseye. They can be adpated to another system easily... mostly the LXC templates should be different in the lxc.include line. The size of the ramdisk is also hardcoded to 32GB for the base systems, and 32GB for the temporary systems. This can be adapted by editing bin/ramdisk.sh.

Network setup

Your containers may need to access the network. To give them access to your entire network, we recommend to create a bridged interface to your physical interface, then use a 'veth' interface in the LXC containers. Your /etc/network/interfaces would look like this :

auto lxcbr0
iface lxcbr0 inet dhcp
	bridge_ports eno1
	bridge_fd 1
	bridge_maxwait 0

This operation is not performed automatically by setup.sh because it has implications in regards to your current network configuration and to the devices exposed on your LAN. You should think it through.

Main setup

Run setup.sh to setup everything else:

  • ensuring LXC is setup via APT
  • symlinking bin/*.sh to /usr/sbin/
  • symlinking ramdisk.service to /etc/systemd/system
  • symlinking templates/*.template to /var/lib/lxc/

Setup other systems

By default, the setup.sh script will generate an image for your own system. If you'd like to generate an image for another system, you'll likely need to have that system running.

To create an Archlinux rootfs to later run on Debian, you'll have to supply your own Archlinux rootfs in the /ramdisk/persist/archlinux folder. Such rootfs can be created from an Archlinux system using:

mkdir /ramdisk/persist/archlinux
pacstrap /ramdisk/persist/archlinux base base-devel

To create a Debian rootfs to later run on Archlinux, you'll have to supply your own rootfs in the /ramdisk/persist/bullseye folder. Such rootfs can be created from a Debian system using:

mkdir /ramdisk/persist/bullseye
deboostrap bullseye /ramdisk/persist/bullseye http://deb.debian.org/debian

Usage

The mkvm.sh script takes the type of container to run as first argument. That type must be supported by a template (currently, archlinux and bullseye). If another argument is provided, it's the command run in the container, after which the container is stopped. Otherwise, the container is stopped when the container shell is exited.

Unless the --keep argument is passed, the container is also destroyed after running.

License

GNU aGPL v3