• Stars
    star
    563
  • Rank 79,150 (Top 2 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 6 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Systemd unit generator for zram devices

[email protected] generator for zram devices

Packaging status

This generator provides a simple and fast mechanism to configure swap on /dev/zram* devices.

The main use case is create swap devices, but devices with a file system can be created too, see below.

Configuration

A default config file may be located in /usr. This generator checks the following locations:

  • /run/systemd/zram-generator.conf
  • /etc/systemd/zram-generator.conf
  • /usr/local/lib/systemd/zram-generator.conf
  • /usr/lib/systemd/zram-generator.conf

… and the first file found in that list wins.

In addition, "drop-ins" will be loaded from .conf files in /etc/systemd/zram-generator.conf.d/, /usr/lib/systemd/zram-generator.conf.d/, etc.

The main configuration file is read before any of the drop-ins and has the lowest precedence; entries in the drop-in files override entries in the main configuration file.

See systemd.unit(5) for a detailed description of this logic.

See zram-generator.conf.example for a list of available settings.

Swap devices

Create /etc/systemd/zram-generator.conf:

# /etc/systemd/zram-generator.conf
[zram0]
zram-size = ram / 2

A zram device will be created for each section. No actual configuration is necessary (the default of zram-size = min(ram / 2, 4096) will be used unless overriden), but the configuration file with at least one section must exist.

Mount points

# /etc/systemd/zram-generator.conf
[zram1]
mount-point = /var/compressed

This will set up a /dev/zram1 with ext2 and generate a mount unit for /var/compressed.

In case you want this path to be user-writable, since util-linux v2.39 you can use

[zram1]
options = X-mount.mode=1777

(and/or the relevant X.mount.{owner,group}= arguments, cf. mount(8)).

Otherwise, you can use the following "high-quality hack": for the above example, create an override for [email protected], for example with systemctl edit, containing the following (note the sticky bit as required for [/var]/tmp):

[Service]
ExecStartPost=/bin/sh -c 'd=$(mktemp -d); mount "$1" "$d"; chmod 1777 "$d"; umount "$d"; rmdir "$d"' _ /dev/%i

Rust

The second purpose of this program is to serve as an example of a systemd generator in rust.

Installation

It is recommended to use an existing package:

To install directly from sources, execute make build && sudo make install NOBUILD=true:

  • zram-generator binary is installed in the systemd system generator directory (usually /usr/lib/systemd/system-generators/)
  • zram-generator(8) and zram-generator.conf(5) manpages are installed into /usr/share/man/manN/, this requires ronn.
  • units/[email protected] is copied into the systemd system unit directory (usually /usr/lib/systemd/system/)
  • zram-generator.conf.example is copied into /usr/share/doc/zram-generator/ You need though create your own config file at one of the locations listed above.

To install and configure with puppet puppet-zram_generator is available.

tl;dr

  • Install zram-generator using one of the methods listed above.
  • Create a zram-generator.conf config file.
  • Run systemctl daemon-reload to create new device units.
  • Run systemctl start /dev/zram0 (adjust the name as appropriate to match the config).
  • Call zramctl or swapon to confirm that the device has been created and is in use.

Once installed and configured, the generator will be invoked by systemd early at boot, there is no need to do anything else.

Testing

The tests require either the zram module to be loaded, or root to run modprobe zram.

Set the ZRAM_GENERATOR_ROOT environment variable to use that instead of / as root.

The "{generator}" template in units/[email protected]/binary-location.conf can be substituted for a non-standard location of the binary for testing.

Authors

Written by Zbigniew JÄ™drzejewski-Szmek <[email protected]>, Igor Raits <[email protected]>, наб <[email protected]>, and others. See https://github.com/systemd/zram-generator/graphs/contributors for the full list.

More Repositories

1

systemd

The systemd System and Service Manager
C
12,965
star
2

casync

Content-Addressable Data Synchronization Tool
C
1,492
star
3

mkosi

💽 Build Bespoke OS Images
Python
1,128
star
4

python-systemd

Python wrappers for systemd functionality
C
465
star
5

pystemd

A thin Cython-based wrapper on top of libsystemd, focused on exposing the dbus API via sd-bus in an automated and easy to consume way.
Python
413
star
6

systemd-stable

Backports of patches from systemd git to stable distributions
C
125
star
7

systemd-netlogd

Forwards messages from the journal to other hosts over the network using syslog format RFC 5424 and RFC 3164
C
68
star
8

journal2gelf

Ships new systemd journal entries to a remote destination in Graylog Extended Log Format (GELF)
Python
64
star
9

node-systemd

V8 engine extension for Node allowing native interaction with systemd and its journal
JavaScript
57
star
10

systemd-bootchart

Boot performance graphing tool
C
53
star
11

kdbus

Out-of-tree kdbus module
C
49
star
12

php-systemd

PHP extension allowing native interaction with systemd and its journal
C
45
star
13

portable-walkthrough-go

A simple yet complete example for a trivial portable service — Go Edition
Go
43
star
14

node-sd-notify

wrapper around sd_notify for using systemd as a node process manager
C++
42
star
15

mkosi-initrd

Build initrd images using mkosi and distro packages
Python
40
star
16

portable-walkthrough

A simple yet complete example for a trivial portable service
C
37
star
17

ejournald

A Erlang binding to the systemd journal C API
Erlang
32
star
18

erlang-sd_notify

Erlang Bindings for sd_notify()
Erlang
18
star
19

package-notes

Tools to add packaging metadata to ELF files
Python
16
star
20

brand.systemd.io

Website with systemd brand assets
HTML
13
star
21

systemd-centos-ci

CI scripts for systemd upstream/downstream testing using the CentOS CI infrastructure
Shell
8
star
22

systemd-coredump-python

Log Python exceptions in the journal via systemd-coredump
Python
8
star
23

journald-cat

Tool to take piped JSON and log the fields to the systemd journal
Python
5
star
24

oci-runtime-tests

Test configs to validate OCI runtime config support in systemd
Shell
5
star
25

systemd-initctl

initctl support for systemd
C
4
star
26

systemd-rhel-testsuite

RHEL downstream testsuite (in progress)
Shell
3
star
27

particleos

Shell
3
star
28

systemd-centos-ci-specs

Spec files for systemd CentOS CI build dependencies
2
star
29

systemd-dfuzzer

Fork of https://github.com/matusmarhefka/dfuzzer/ with custom functionality & improvements. It was moved back to the original repository.
C
1
star
30

systemd-fedora-ci

This project contains code to test systemd
Python
1
star