summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am5
-rw-r--r--src/efi-boot-generator/efi-boot-generator.c71
-rw-r--r--src/fstab-generator/fstab-generator.c133
-rw-r--r--src/gpt-auto-generator/gpt-auto-generator.c155
-rw-r--r--src/shared/generator.c84
-rw-r--r--src/shared/generator.h26
-rw-r--r--src/shared/gpt.h28
7 files changed, 334 insertions, 168 deletions
diff --git a/Makefile.am b/Makefile.am
index f99cef7a17..6cc83162dd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -792,7 +792,10 @@ libsystemd_shared_la_SOURCES = \
src/shared/condition-util.c \
src/shared/condition-util.h \
src/shared/bus-label.c \
- src/shared/bus-label.h
+ src/shared/bus-label.h \
+ src/shared/gpt.h \
+ src/shared/generator.h \
+ src/shared/generator.c
nodist_libsystemd_shared_la_SOURCES = \
src/shared/errno-from-name.h \
diff --git a/src/efi-boot-generator/efi-boot-generator.c b/src/efi-boot-generator/efi-boot-generator.c
index 606d35bf79..270dc226ef 100644
--- a/src/efi-boot-generator/efi-boot-generator.c
+++ b/src/efi-boot-generator/efi-boot-generator.c
@@ -27,15 +27,18 @@
#include "util.h"
#include "mkdir.h"
#include "unit-name.h"
+#include "virt.h"
+#include "generator.h"
+#include "special.h"
static const char *arg_dest = "/tmp";
int main(int argc, char *argv[]) {
+ _cleanup_free_ char *what = NULL;
+ _cleanup_fclose_ FILE *f = NULL;
int r = EXIT_SUCCESS;
sd_id128_t id;
- _cleanup_free_ char *what = NULL, *fsck = NULL;
char *name;
- _cleanup_fclose_ FILE *f = NULL, *f2 = NULL;
if (argc > 1 && argc != 4) {
log_error("This program takes three or no arguments.");
@@ -51,16 +54,30 @@ int main(int argc, char *argv[]) {
umask(0022);
- if (!is_efi_boot())
+ if (in_initrd()) {
+ log_debug("In initrd, exiting.");
return EXIT_SUCCESS;
+ }
+ if (detect_container(NULL) > 0) {
+ log_debug("In a container, exiting.");
+ return EXIT_SUCCESS;
+ }
- if (dir_is_empty("/boot") <= 0)
+ if (!is_efi_boot()) {
+ log_debug("Not an EFI boot, exiting.");
return EXIT_SUCCESS;
+ }
+
+ if (dir_is_empty("/boot") <= 0) {
+ log_debug("/boot already populated, exiting.");
+ return EXIT_SUCCESS;
+ }
r = efi_loader_get_device_part_uuid(&id);
- if (r == -ENOENT)
+ if (r == -ENOENT) {
+ log_debug("EFI loader partition unknown exiting.");
return EXIT_SUCCESS;
- if (r < 0) {
+ } else if (r < 0) {
log_error("Failed to read ESP partition UUID: %s", strerror(-r));
return EXIT_FAILURE;
}
@@ -80,28 +97,34 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
- fsck = unit_name_from_path_instance("systemd-fsck", what, ".service");
- if (!fsck) {
- log_oom();
- return EXIT_FAILURE;
- }
-
fprintf(f,
"# Automatially generated by systemd-efi-boot-generator\n\n"
"[Unit]\n"
- "Description=EFI System Partition\n"
- "Requires=%s\n"
- "After=%s\n"
+ "Description=EFI System Partition\n");
+
+ r = generator_write_fsck_deps(f, arg_dest, what, "/boot", "vfat");
+ if (r < 0)
+ return EXIT_FAILURE;
+
+ fprintf(f,
"\n"
"[Mount]\n"
- "Where=/boot\n"
"What=%s\n"
+ "Where=/boot\n"
+ "Type=vfat\n"
"Options=umask=0077,noauto\n",
- fsck, fsck, what);
+ what);
+
+ fflush(f);
+ if (ferror(f)) {
+ log_error("Failed to write mount unit file: %m");
+ return EXIT_FAILURE;
+ }
name = strappenda(arg_dest, "/boot.automount");
- f2 = fopen(name, "wxe");
- if (!f2) {
+ fclose(f);
+ f = fopen(name, "wxe");
+ if (!f) {
log_error("Failed to create automount unit file %s: %m", name);
return EXIT_FAILURE;
}
@@ -110,9 +133,15 @@ int main(int argc, char *argv[]) {
"[Unit]\n"
"Description=EFI System Partition Automount\n\n"
"[Automount]\n"
- "Where=/boot\n", f2);
+ "Where=/boot\n", f);
+
+ fflush(f);
+ if (ferror(f)) {
+ log_error("Failed to write automount unit file: %m");
+ return EXIT_FAILURE;
+ }
- name = strappenda(arg_dest, "/local-fs.target.wants/boot.automount");
+ name = strappenda(arg_dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/boot.automount");
mkdir_parents(name, 0755);
if (symlink("../boot.automount", name) < 0) {
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 5521a864df..aac1a436ec 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -33,9 +33,10 @@
#include "special.h"
#include "mkdir.h"
#include "fileio.h"
+#include "generator.h"
static const char *arg_dest = "/tmp";
-static bool arg_enabled = true;
+static bool arg_fstab_enabled = true;
static int mount_find_pri(struct mntent *me, int *ret) {
char *end, *pri;
@@ -146,57 +147,6 @@ static bool mount_in_initrd(struct mntent *me) {
streq(me->mnt_dir, "/usr");
}
-static int add_fsck(FILE *f, const char *what, const char *where, const char *type, int passno) {
- assert(f);
-
- if (passno == 0)
- return 0;
-
- if (!is_device_path(what)) {
- log_warning("Checking was requested for \"%s\", but it is not a device.", what);
- return 0;
- }
-
- if (type && !streq(type, "auto")) {
- int r;
- const char *checker;
-
- checker = strappenda("/sbin/fsck.", type);
- r = access(checker, X_OK);
- if (r < 0) {
- log_warning("Checking was requested for %s, but %s cannot be used: %m", what, checker);
-
- /* treat missing check as essentially OK */
- return errno == ENOENT ? 0 : -errno;
- }
- }
-
- if (streq(where, "/")) {
- char *lnk;
-
- lnk = strappenda(arg_dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service");
- mkdir_parents_label(lnk, 0755);
- if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) {
- log_error("Failed to create symlink %s: %m", lnk);
- return -errno;
- }
- } else {
- _cleanup_free_ char *fsck = NULL;
-
- fsck = unit_name_from_path_instance("systemd-fsck", what, ".service");
- if (!fsck)
- return log_oom();
-
- fprintf(f,
- "RequiresOverridable=%s\n"
- "After=%s\n",
- fsck,
- fsck);
- }
-
- return 0;
-}
-
static int add_mount(
const char *what,
const char *where,
@@ -208,6 +158,7 @@ static int add_mount(
bool automount,
const char *post,
const char *source) {
+
_cleanup_free_ char
*name = NULL, *unit = NULL, *lnk = NULL,
*automount_name = NULL, *automount_unit = NULL;
@@ -232,6 +183,12 @@ static int add_mount(
mount_point_ignore(where))
return 0;
+ if (path_equal(where, "/")) {
+ automount = false;
+ noauto = false;
+ nofail = false;
+ }
+
name = unit_name_from_path(where, ".mount");
if (!name)
return log_oom();
@@ -260,9 +217,11 @@ static int add_mount(
"Before=%s\n",
post);
- r = add_fsck(f, what, where, type, passno);
- if (r < 0)
- return r;
+ if (passno != 0) {
+ r = generator_write_fsck_deps(f, arg_dest, what, where, type);
+ if (r < 0)
+ return r;
+ }
fprintf(f,
"\n"
@@ -274,8 +233,7 @@ static int add_mount(
where,
type);
- if (!isempty(opts) &&
- !streq(opts, "defaults"))
+ if (!isempty(opts) && !streq(opts, "defaults"))
fprintf(f,
"Options=%s\n",
opts);
@@ -300,7 +258,7 @@ static int add_mount(
}
}
- if (automount && !path_equal(where, "/")) {
+ if (automount) {
automount_name = unit_name_from_path(where, ".automount");
if (!automount_name)
return log_oom();
@@ -324,7 +282,7 @@ static int add_mount(
if (post)
fprintf(f,
- "Before= %s\n",
+ "Before=%s\n",
post);
fprintf(f,
@@ -353,19 +311,19 @@ static int add_mount(
return 0;
}
-static int parse_fstab(const char *prefix, bool initrd) {
- char *fstab_path;
+static int parse_fstab(bool initrd) {
_cleanup_endmntent_ FILE *f;
- int r = 0;
+ const char *fstab_path;
struct mntent *me;
+ int r = 0;
- fstab_path = strappenda(strempty(prefix), "/etc/fstab");
- f = setmntent(fstab_path, "r");
+ fstab_path = initrd ? "/sysroot/etc/fstab" : "/etc/fstab";
+ f = setmntent(fstab_path, "re");
if (!f) {
if (errno == ENOENT)
return 0;
- log_error("Failed to open %s/etc/fstab: %m", strempty(prefix));
+ log_error("Failed to open %s: %m", fstab_path);
return -errno;
}
@@ -377,8 +335,11 @@ static int parse_fstab(const char *prefix, bool initrd) {
continue;
what = fstab_node_to_udev_node(me->mnt_fsname);
- where = strjoin(strempty(prefix), me->mnt_dir, NULL);
- if (!what || !where)
+ if (!what)
+ return log_oom();
+
+ where = initrd ? strappend("/sysroot/", me->mnt_dir) : strdup(me->mnt_dir);
+ if (!where)
return log_oom();
if (is_path(where))
@@ -398,15 +359,14 @@ static int parse_fstab(const char *prefix, bool initrd) {
hasmntopt(me, "comment=systemd.automount") ||
hasmntopt(me, "x-systemd.automount");
- if (initrd) {
+ if (initrd)
post = SPECIAL_INITRD_FS_TARGET;
- } else if (mount_in_initrd(me)) {
+ else if (mount_in_initrd(me))
post = SPECIAL_INITRD_ROOT_FS_TARGET;
- } else if (mount_is_network(me)) {
+ else if (mount_is_network(me))
post = SPECIAL_REMOTE_FS_TARGET;
- } else {
+ else
post = SPECIAL_LOCAL_FS_TARGET;
- }
k = add_mount(what, where, me->mnt_type, me->mnt_opts,
me->mnt_passno, noauto, nofail, automount,
@@ -505,11 +465,12 @@ static int parse_proc_cmdline_word(const char *word) {
int r;
if (startswith(word, "fstab=")) {
+
r = parse_boolean(word + 6);
if (r < 0)
log_warning("Failed to parse fstab switch %s. Ignoring.", word + 6);
else
- arg_enabled = r;
+ arg_fstab_enabled = r;
} else if (startswith(word, "rd.fstab=")) {
@@ -518,7 +479,7 @@ static int parse_proc_cmdline_word(const char *word) {
if (r < 0)
log_warning("Failed to parse fstab switch %s. Ignoring.", word + 9);
else
- arg_enabled = r;
+ arg_fstab_enabled = r;
}
} else if (startswith(word, "fstab.") ||
@@ -531,7 +492,7 @@ static int parse_proc_cmdline_word(const char *word) {
}
int main(int argc, char *argv[]) {
- int r = 0, k, l = 0;
+ int r = 0;
if (argc > 1 && argc != 4) {
log_error("This program takes three or no arguments.");
@@ -550,16 +511,26 @@ int main(int argc, char *argv[]) {
if (parse_proc_cmdline(parse_proc_cmdline_word) < 0)
return EXIT_FAILURE;
+ /* Always honour root= in the kernel command line if we are in an initrd */
if (in_initrd())
r = parse_new_root_from_proc_cmdline();
- if (!arg_enabled)
- return (r < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
+ /* Honour /etc/fstab only when that's enabled */
+ if (arg_fstab_enabled) {
+ int k;
- k = parse_fstab(NULL, false);
+ /* Parse the local /etc/fstab, possibly from the initrd */
+ k = parse_fstab(false);
+ if (k < 0)
+ r = k;
- if (in_initrd())
- l = parse_fstab("/sysroot", true);
+ /* If running in the initrd also parse the /etc/fstab from the host */
+ if (in_initrd()) {
+ k = parse_fstab(true);
+ if (k < 0)
+ r = k;
+ }
+ }
- return (r < 0) || (k < 0) || (l < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
+ return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index 05934da82f..f34cd030c2 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -40,6 +40,8 @@
#include "special.h"
#include "unit-name.h"
#include "virt.h"
+#include "generator.h"
+#include "gpt.h"
/* TODO:
*
@@ -49,9 +51,6 @@
*
*/
-#define GPT_SWAP SD_ID128_MAKE(06,57,fd,6d,a4,ab,43,c4,84,e5,09,33,c8,4b,4f,4f)
-#define GPT_HOME SD_ID128_MAKE(93,3a,c7,e1,2e,b4,4f,13,b8,44,0e,14,e2,ae,f9,15)
-
static const char *arg_dest = "/tmp";
DEFINE_TRIVIAL_CLEANUP_FUNC(blkid_probe, blkid_free_probe);
@@ -152,10 +151,6 @@ static int add_swap(const char *path, const char *fstype) {
fprintf(f,
"# Automatically generated by systemd-gpt-auto-generator\n\n"
- "[Unit]\n"
- "DefaultDependencies=no\n"
- "Conflicts=" SPECIAL_UMOUNT_TARGET "\n"
- "Before=" SPECIAL_UMOUNT_TARGET " " SPECIAL_SWAP_TARGET "\n\n"
"[Swap]\n"
"What=%s\n",
path);
@@ -179,42 +174,49 @@ static int add_swap(const char *path, const char *fstype) {
return 0;
}
-static int add_home(const char *path, const char *fstype) {
- _cleanup_free_ char *unit = NULL, *lnk = NULL, *fsck = NULL;
+static int add_mount(const char *what, const char *where, const char *fstype, const char *description) {
+ _cleanup_free_ char *unit = NULL, *lnk = NULL, *p = NULL;
_cleanup_fclose_ FILE *f = NULL;
+ int r;
- if (dir_is_empty("/home") <= 0)
+ if (dir_is_empty(where) <= 0) {
+ log_debug("%s already populated, ignoring.", where);
return 0;
+ }
- log_debug("Adding home: %s %s", path, fstype);
+ log_debug("Adding %s: %s %s", where, what, fstype);
- unit = strappend(arg_dest, "/home.mount");
+ unit = unit_name_from_path(where, ".mount");
if (!unit)
return log_oom();
- f = fopen(unit, "wxe");
+ p = strjoin(arg_dest, "/", unit, NULL);
+ if (!p)
+ return log_oom();
+
+ f = fopen(p, "wxe");
if (!f) {
log_error("Failed to create unit file %s: %m", unit);
return -errno;
}
- fsck = unit_name_from_path_instance("systemd-fsck", path, ".service");
- if (!fsck)
- return log_oom();
-
fprintf(f,
"# Automatically generated by systemd-gpt-auto-generator\n\n"
"[Unit]\n"
- "DefaultDependencies=no\n"
- "Requires=%s\n"
- "After=" SPECIAL_LOCAL_FS_PRE_TARGET " %s\n"
- "Conflicts=" SPECIAL_UMOUNT_TARGET "\n"
- "Before=" SPECIAL_UMOUNT_TARGET " " SPECIAL_LOCAL_FS_TARGET "\n\n"
+ "Description=%s\n",
+ description);
+
+ r = generator_write_fsck_deps(f, arg_dest, what, where, fstype);
+ if (r < 0)
+ return r;
+
+ fprintf(f,
+ "\n"
"[Mount]\n"
"What=%s\n"
- "Where=/home\n"
+ "Where=%s\n"
"Type=%s\n",
- fsck, fsck, path, fstype);
+ what, where, fstype);
fflush(f);
if (ferror(f)) {
@@ -222,7 +224,7 @@ static int add_home(const char *path, const char *fstype) {
return -errno;
}
- lnk = strjoin(arg_dest, "/" SPECIAL_LOCAL_FS_TARGET ".requires/home.mount", NULL);
+ lnk = strjoin(arg_dest, "/" SPECIAL_LOCAL_FS_TARGET ".requires/", unit, NULL);
if (!lnk)
return log_oom();
@@ -236,12 +238,12 @@ static int add_home(const char *path, const char *fstype) {
}
static int enumerate_partitions(struct udev *udev, dev_t dev) {
- struct udev_device *parent = NULL;
_cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL;
_cleanup_udev_device_unref_ struct udev_device *d = NULL;
+ _cleanup_free_ char *home = NULL, *home_fstype = NULL, *srv = NULL, *srv_fstype = NULL;
+ unsigned home_nr = (unsigned) -1, srv_nr = (unsigned )-1;
struct udev_list_entry *first, *item;
- unsigned home_nr = (unsigned) -1;
- _cleanup_free_ char *home = NULL, *home_fstype = NULL;
+ struct udev_device *parent = NULL;
int r;
e = udev_enumerate_new(udev);
@@ -266,16 +268,15 @@ static int enumerate_partitions(struct udev *udev, dev_t dev) {
r = udev_enumerate_scan_devices(e);
if (r < 0) {
- log_error("Failed to enumerate partitions on /dev/block/%u:%u: %s",
- major(dev), minor(dev), strerror(-r));
+ log_error("Failed to enumerate partitions on /dev/block/%u:%u: %s", major(dev), minor(dev), strerror(-r));
return r;
}
first = udev_enumerate_get_list_entry(e);
udev_list_entry_foreach(item, first) {
+ _cleanup_udev_device_unref_ struct udev_device *q;
_cleanup_free_ char *fstype = NULL;
const char *node = NULL;
- _cleanup_udev_device_unref_ struct udev_device *q;
sd_id128_t type_id;
unsigned nr;
@@ -298,8 +299,7 @@ static int enumerate_partitions(struct udev *udev, dev_t dev) {
/* skip child devices which are not detected properly */
if (r == -EBADSLT)
continue;
- log_error("Failed to verify GPT partition %s: %s",
- node, strerror(-r));
+ log_error("Failed to verify GPT partition %s: %s", node, strerror(-r));
return r;
}
if (r == 0)
@@ -307,24 +307,48 @@ static int enumerate_partitions(struct udev *udev, dev_t dev) {
if (sd_id128_equal(type_id, GPT_SWAP))
add_swap(node, fstype);
+
else if (sd_id128_equal(type_id, GPT_HOME)) {
- if (!home || nr < home_nr) {
- free(home);
- home = strdup(node);
- if (!home)
- return log_oom();
-
- home_nr = nr;
-
- free(home_fstype);
- home_fstype = fstype;
- fstype = NULL;
- }
+
+ /* We only care for the first /home partition */
+ if (home && nr >= home_nr)
+ continue;
+
+ home_nr = nr;
+
+ free(home);
+ home = strdup(node);
+ if (!home)
+ return log_oom();
+
+ free(home_fstype);
+ home_fstype = fstype;
+ fstype = NULL;
+
+ } else if (sd_id128_equal(type_id, GPT_SRV)) {
+
+ /* We only care for the first /srv partition */
+ if (srv && nr >= srv_nr)
+ continue;
+
+ srv_nr = nr;
+
+ free(srv);
+ srv = strdup(node);
+ if (!srv)
+ return log_oom();
+
+ free(srv_fstype);
+ srv_fstype = fstype;
+ fstype = NULL;
}
}
if (home && home_fstype)
- add_home(home, home_fstype);
+ add_mount(home, "/home", home_fstype, "Home Partition");
+
+ if (srv && srv_fstype)
+ add_mount(srv, "/srv", srv_fstype, "Server Data Partition");
return r;
}
@@ -384,7 +408,7 @@ static int get_block_device(const char *path, dev_t *dev) {
assert(path);
assert(dev);
- if (lstat("/", &st))
+ if (lstat(path, &st))
return -errno;
if (major(st.st_dev) != 0) {
@@ -392,7 +416,7 @@ static int get_block_device(const char *path, dev_t *dev) {
return 1;
}
- if (statfs("/", &sfs) < 0)
+ if (statfs(path, &sfs) < 0)
return -errno;
if (F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC))
@@ -423,15 +447,14 @@ static int devno_to_devnode(struct udev *udev, dev_t devno, char **ret) {
}
int main(int argc, char *argv[]) {
- _cleanup_free_ char *node = NULL;
_cleanup_udev_unref_ struct udev *udev = NULL;
+ _cleanup_free_ char *node = NULL;
dev_t devno;
int r = 0;
if (argc > 1 && argc != 4) {
log_error("This program takes three or no arguments.");
- r = -EINVAL;
- goto finish;
+ return EXIT_FAILURE;
}
if (argc > 1)
@@ -445,34 +468,33 @@ int main(int argc, char *argv[]) {
if (in_initrd()) {
log_debug("In initrd, exiting.");
- goto finish;
+ return EXIT_SUCCESS;
}
if (detect_container(NULL) > 0) {
log_debug("In a container, exiting.");
- goto finish;
+ return EXIT_SUCCESS;
}
r = get_block_device("/", &devno);
if (r < 0) {
log_error("Failed to determine block device of root file system: %s", strerror(-r));
- goto finish;
- }
- if (r == 0) {
+ return EXIT_FAILURE;
+ } else if (r == 0) {
log_debug("Root file system not on a (single) block device.");
- goto finish;
+ return EXIT_SUCCESS;
}
udev = udev_new();
if (!udev) {
- r = log_oom();
- goto finish;
+ log_oom();
+ return EXIT_FAILURE;
}
r = devno_to_devnode(udev, devno, &node);
if (r < 0) {
log_error("Failed to determine block device node from major/minor: %s", strerror(-r));
- goto finish;
+ return EXIT_FAILURE;
}
log_debug("Root device %s.", node);
@@ -480,13 +502,16 @@ int main(int argc, char *argv[]) {
r = verify_gpt_partition(node, NULL, NULL, NULL);
if (r < 0) {
log_error("Failed to verify GPT partition %s: %s", node, strerror(-r));
- goto finish;
+ return EXIT_FAILURE;
+ }
+ if (r == 0) {
+ log_debug("Not a GPT disk, exiting.");
+ return EXIT_SUCCESS;
}
- if (r == 0)
- goto finish;
r = enumerate_partitions(udev, devno);
+ if (r < 0)
+ return EXIT_FAILURE;
-finish:
- return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
diff --git a/src/shared/generator.c b/src/shared/generator.c
new file mode 100644
index 0000000000..49647c1ab6
--- /dev/null
+++ b/src/shared/generator.c
@@ -0,0 +1,84 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <unistd.h>
+
+#include "util.h"
+#include "special.h"
+#include "mkdir.h"
+#include "unit-name.h"
+#include "generator.h"
+
+int generator_write_fsck_deps(
+ FILE *f,
+ const char *dest,
+ const char *what,
+ const char *where,
+ const char *type) {
+
+ assert(f);
+
+ if (!is_device_path(what)) {
+ log_warning("Checking was requested for \"%s\", but it is not a device.", what);
+ return 0;
+ }
+
+ if (type && !streq(type, "auto")) {
+ const char *checker;
+ int r;
+
+ checker = strappenda("/sbin/fsck.", type);
+ r = access(checker, X_OK);
+ if (r < 0) {
+ log_warning("Checking was requested for %s, but %s cannot be used: %m", what, checker);
+
+ /* treat missing check as essentially OK */
+ return errno == ENOENT ? 0 : -errno;
+ }
+ }
+
+ if (streq(where, "/")) {
+ char *lnk;
+
+ lnk = strappenda(dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service");
+
+ mkdir_parents(lnk, 0755);
+ if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) {
+ log_error("Failed to create symlink %s: %m", lnk);
+ return -errno;
+ }
+
+ } else {
+ _cleanup_free_ char *fsck = NULL;
+
+ fsck = unit_name_from_path_instance("systemd-fsck", what, ".service");
+ if (!fsck)
+ return log_oom();
+
+ fprintf(f,
+ "RequiresOverridable=%s\n"
+ "After=%s\n",
+ fsck,
+ fsck);
+ }
+
+ return 0;
+}
diff --git a/src/shared/generator.h b/src/shared/generator.h
new file mode 100644
index 0000000000..0140aa943f
--- /dev/null
+++ b/src/shared/generator.h
@@ -0,0 +1,26 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <stdio.h>
+
+int generator_write_fsck_deps(FILE *f, const char *dest, const char *what, const char *where, const char *type);
diff --git a/src/shared/gpt.h b/src/shared/gpt.h
new file mode 100644
index 0000000000..2956377b48
--- /dev/null
+++ b/src/shared/gpt.h
@@ -0,0 +1,28 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "sd-id128.h"
+
+#define GPT_ESP SD_ID128_MAKE(c1,2a,73,28,f8,1f,11,d2,ba,4b,00,a0,c9,3e,c9,3b)
+#define GPT_ROOT SD_ID128_MAKE(4f,68,bc,e3,e8,cd,4d,b1,96,e7,fb,ca,f9,84,b7,09)
+#define GPT_SWAP SD_ID128_MAKE(06,57,fd,6d,a4,ab,43,c4,84,e5,09,33,c8,4b,4f,4f)
+#define GPT_HOME SD_ID128_MAKE(93,3a,c7,e1,2e,b4,4f,13,b8,44,0e,14,e2,ae,f9,15)
+#define GPT_SRV SD_ID128_MAKE(3b,8f,84,25,20,e0,4f,3b,90,7f,1a,25,a7,6f,98,e8)