Skip to content
Kabouik edited this page Aug 2, 2020 · 10 revisions

All lxc commands below should be run as root using devel-su.

Creating a container

Creating a linux container on sailfishOS is as simple as:

# lxc-create -t sfos-download -n mycontainer

The download template will show you a list of distributions, versions and architectures to choose from. A good example would be "debian", "sid" (unstable) and "arm64".

It is possible to skip shell interaction by providing parameters to sfos-download as shown below:

# lxc-create -t sfos-download -n mycontainer -- --arch armhf --dist debian --release sid

For your first LXC experience, we recommend using a recent supported release, such as "debian sid/bullseye", "ubuntu bionic/cosmic".

After container's creation completed, you'll find the container config file on /var/lib/lxc/mycontainer/config and the container rootfs directory inside /home/.lxc/mycontainer.

sfos-download template is configured by default to store LXC's downloads cache inside /home/.lxc/lxc_cache, it is safe to delete this directory after creation in order to free up some storage.

Start your new container

You can start your freshly created container with:

# lxc-start -n mycontainer

Get container's information

It is possible to get useful information about your container such as state, pid, cpu usage, memory usage and kmem usage as follows:

# lxc-info -n mycontainer

Attach to your container

to start a shell session on "mycontainer"

# lxc-attach -n mycontainer

Stop your container

# lxc-stop -n mycontainer

Freeze your container

It is possible to freeze containers in order to save battery life when unused as shown below:

# lxc-freeze -n mycontainer

Unfreeze your container

You can then restore your session with:

# lxc-unfreeze -n mycontainer

Create a snapshot of your container

You can save the current state of your container as a snapshot to restore it later or create new containers from it:

# lxc-snapshot -n mycontainer mysnapshotname

Your first snapshot will be stored in a folder named snap0 in /var/lib/lxc/mycontainer/snaps. Additional snapshots will create new folders named snap1, snap2, etc.

List snapshots for your container

# lxc-snapshot -n mycontainer -L

Restore a snapshot of your container

To restore a previous snapshot (beware, this will overwrite the current state of your container unless you created another snapshot of it):

# lxc-snapshot -n mycontainer -r snapX

snapX is the name of the folder associated with the snapshot. The -r argument needs the folder name of the snapshot instead of the mysnapshot name you gave you snapshot when creating it. Use lxc-snapshot -n mycontainer -L to carefully check the correspondence between folder names and snapshot names.

Optionally, you can create a new container from the snapshot with the following command instead of altering the parent container:

# lxc-snapshot -n mycontainer -r snapX -N mycontainer2

snapX is the name of the folder associated with the snapshot. See above.

Destroy your container

# lxc-destroy -n mycontainer

References