b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen This file is part of systemd.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Copyright 2013 Lennart Poettering
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is free software; you can redistribute it and/or modify it
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen under the terms of the GNU Lesser General Public License as published by
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen (at your option) any later version.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is distributed in the hope that it will be useful, but
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Lesser General Public License for more details.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen You should have received a copy of the GNU Lesser General Public License
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersenstatic int add_cryptsetup(const char *id, const char *what, bool rw, char **device) {
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen _cleanup_free_ char *e = NULL, *n = NULL, *p = NULL, *d = NULL, *to = NULL;
99634696183dfabae20104e58157c69029a11594Tom Gundersen return log_error_errno(r, "Failed to generate unit name: %m");
6f08fb7b34b4eebf664de83c8bc7b9941658aeb4Tom Gundersen r = unit_name_build("systemd-cryptsetup", e, ".service", &n);
6f08fb7b34b4eebf664de83c8bc7b9941658aeb4Tom Gundersen return log_error_errno(r, "Failed to generate unit name: %m");
6f08fb7b34b4eebf664de83c8bc7b9941658aeb4Tom Gundersen return log_error_errno(errno, "Failed to create unit file %s: %m", p);
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen "# Automatically generated by systemd-gpt-auto-generator\n\n"
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen "Description=Cryptography Setup for %%I\n"
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen "Documentation=man:systemd-gpt-auto-generator(8) man:systemd-cryptsetup@.service(8)\n"
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen "DefaultDependencies=no\n"
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen "Conflicts=umount.target\n"
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen "BindsTo=dev-mapper-%%i.device %s\n"
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen "Before=umount.target cryptsetup.target\n"
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen "IgnoreOnIsolate=true\n"
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen "[Service]\n"
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen "Type=oneshot\n"
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen "RemainAfterExit=yes\n"
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen "TimeoutSec=0\n" /* the binary handles timeouts anyway */
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen "ExecStart=" SYSTEMD_CRYPTSETUP_PATH " attach '%s' '%s' '' '%s'\n"
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen "ExecStop=" SYSTEMD_CRYPTSETUP_PATH " detach '%s'\n",
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen return log_error_errno(r, "Failed to write file %s: %m", p);
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen to = strjoin(arg_dest, "/", d, ".wants/", n, NULL);
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen return log_error_errno(errno, "Failed to create symlink %s: %m", to);
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen to = strjoin(arg_dest, "/cryptsetup.target.requires/", n, NULL);
99634696183dfabae20104e58157c69029a11594Tom Gundersen return log_error_errno(errno, "Failed to create symlink %s: %m", to);
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen to = strjoin(arg_dest, "/dev-mapper-", e, ".device.requires/", n, NULL);
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen return log_error_errno(errno, "Failed to create symlink %s: %m", to);
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen p = strjoin(arg_dest, "/dev-mapper-", e, ".device.d/50-job-timeout-sec-0.conf", NULL);
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen "# Automatically generated by systemd-gpt-auto-generator\n\n"
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen "JobTimeoutSec=0\n",
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen WRITE_STRING_FILE_CREATE); /* the binary handles timeouts anyway */
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen return log_error_errno(r, "Failed to write device drop-in: %m");
4dc355680460fdc8e0d590d8572dff1b6a257d88Tom Gundersen const char *id,
bd57b45029ff25067704c9538e79f31e71c10045Tom Gundersen const char *post) {
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen _cleanup_free_ char *unit = NULL, *lnk = NULL, *crypto_what = NULL, *p = NULL;
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen log_debug("Adding %s: %s %s", where, what, strna(fstype));
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen r = add_cryptsetup(id, what, rw, &crypto_what);
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen r = unit_name_from_path(where, ".mount", &unit);
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen return log_error_errno(r, "Failed to generate unit name: %m");
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen return log_error_errno(errno, "Failed to create unit file %s: %m", unit);
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen "# Automatically generated by systemd-gpt-auto-generator\n\n"
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen "Description=%s\n"
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen "Documentation=man:systemd-gpt-auto-generator(8)\n",
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen r = generator_write_fsck_deps(f, arg_dest, what, where, fstype);
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen "Where=%s\n",
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen fprintf(f, "Options=%s,%s\n", options, rw ? "rw" : "ro");
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen return log_error_errno(r, "Failed to write unit file %s: %m", p);
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen lnk = strjoin(arg_dest, "/", post, ".requires/", unit, NULL);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen return log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen /* already a mountpoint; generators run during reload */
6f08fb7b34b4eebf664de83c8bc7b9941658aeb4Tom Gundersen r = path_is_mount_point(where, AT_SYMLINK_FOLLOW);
6f08fb7b34b4eebf664de83c8bc7b9941658aeb4Tom Gundersen return false;
be077570f779664ed87b50f60608df9fbe258821Tom Gundersen /* the directory might not exist on a stateless system */
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen return false;
const char *id,
const char *what,
const char *where,
bool rw,
const char *description,
const char *post) {
errno = 0;
if (errno == 0)
return log_oom();
errno = 0;
r = blkid_do_safeprobe(b);
return add_mount(
id,
what,
rw,
NULL,
post);
if (!unit)
return log_oom();
fprintf(f,
path);
r = fflush_and_check(f);
if (!lnk)
return log_oom();
#ifdef ENABLE_EFI
const char *id,
const char *what,
const char *where,
const char *fstype,
bool rw,
const char *options,
const char *description,
if (options)
if (!opt)
return log_oom();
what,
rw,
opt,
NULL);
return log_oom();
fprintf(f,
r = fflush_and_check(f);
if (!lnk)
return log_oom();
if (!is_efi_boot()) {
if (in_initrd()) {
if (detect_container() > 0) {
if (r == -ENOENT) {
errno = 0;
if (errno == 0)
return log_oom();
errno = 0;
r = blkid_do_safeprobe(b);
errno = 0;
what,
if (!udev)
return log_oom();
return log_oom();
if (!name)
if (!name) {
if (!parent) {
if (!devtype) {
if (!node) {
errno = 0;
if (errno == 0)
return log_oom();
errno = 0;
r = blkid_do_safeprobe(b);
errno = 0;
if (errno == 0)
errno = 0;
if (!pl) {
if (errno == 0)
return log_oom();
return log_oom();
return log_oom();
return log_oom();
r = udev_enumerate_scan_devices(e);
if (!subnode)
if (!pp)
if (nr < 0)
if (!stype)
return log_oom();
return log_oom();
return log_oom();
if (boot) {
if (home) {
if (srv) {
k = probe_and_add_mount("srv", srv, "/srv", srv_rw, "Server Data Partition", SPECIAL_LOCAL_FS_TARGET);
return -errno;
return -errno;
return -ENOMEM;
d = opendir(p);
goto fallback;
return -errno;
goto fallback;
if (!found)
goto fallback;
r = read_one_line_file(q, &t);
if (r == -ENOENT)
goto fallback;
return -EINVAL;
if (maj == 0)
goto fallback;
arg_enabled = r;
arg_root_rw = true;
arg_root_rw = false;
#ifdef ENABLE_EFI
if (!is_efi_boot()) {
if (r == -ENOENT) {
return add_mount(
"/dev/gpt-auto-root",
NULL,
NULL,
return EXIT_FAILURE;
log_open();
if (detect_container() > 0) {
return EXIT_SUCCESS;
if (!arg_enabled) {
return EXIT_SUCCESS;
if (arg_root_enabled)
r = add_root_mount();
if (!in_initrd()) {
k = add_mounts();