Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpt-auto-generator: Use volatile-root by default and automatic logic as fallback #20578

Merged
merged 1 commit into from Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions man/systemd-gpt-auto-generator.xml
Expand Up @@ -228,6 +228,11 @@
For more information, see <citerefentry><refentrytitle>bootup</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
</para>

<para>The root partition can be specified by symlinking <filename>/run/systemd/volatile-root</filename>
to <filename>/dev/block/$major:$minor</filename>. This is especially useful if the root mount has been
replaced by some form of volatile file system (overlayfs).
</para>

<para>Mount and automount units for the EFI System Partition (ESP) are generated on EFI systems. The ESP
is mounted to <filename>/boot/</filename> (except if an Extended Boot Loader partition exists, see
below), unless a mount point directory <filename>/efi/</filename> exists, in which case it is mounted
Expand Down
53 changes: 24 additions & 29 deletions src/gpt-auto-generator/gpt-auto-generator.c
Expand Up @@ -764,41 +764,36 @@ static int enumerate_partitions(dev_t devnum) {
}

static int add_mounts(void) {
dev_t devno;
_cleanup_free_ char *p = NULL;
int r;
dev_t devno;

r = get_block_device_harder("/", &devno);
if (r == -EUCLEAN)
return btrfs_log_dev_root(LOG_ERR, r, "root file system");
if (r < 0)
return log_error_errno(r, "Failed to determine block device of root file system: %m");
if (r == 0) { /* Not backed by block device */
r = get_block_device_harder("/usr", &devno);
/* If the root mount has been replaced by some form of volatile file system (overlayfs), the
* original root block device node is symlinked in /run/systemd/volatile-root. Let's read that
* here. */
r = readlink_malloc("/run/systemd/volatile-root", &p);
if (r == -ENOENT) { /* volatile-root not found */
r = get_block_device_harder("/", &devno);
if (r == -EUCLEAN)
return btrfs_log_dev_root(LOG_ERR, r, "/usr");
return btrfs_log_dev_root(LOG_ERR, r, "root file system");
if (r < 0)
return log_error_errno(r, "Failed to determine block device of /usr file system: %m");
if (r == 0) {
_cleanup_free_ char *p = NULL;
mode_t m;

/* If the root mount has been replaced by some form of volatile file system (overlayfs), the
* original root block device node is symlinked in /run/systemd/volatile-root. Let's read that
* here. */
r = readlink_malloc("/run/systemd/volatile-root", &p);
if (r == -ENOENT) {
log_debug("Neither root nor /usr file system are on a (single) block device.");
return 0;
}
return log_error_errno(r, "Failed to determine block device of root file system: %m");
if (r == 0) { /* Not backed by block device */
r = get_block_device_harder("/usr", &devno);
if (r == -EUCLEAN)
return btrfs_log_dev_root(LOG_ERR, r, "/usr");
if (r < 0)
return log_error_errno(r, "Failed to read symlink /run/systemd/volatile-root: %m");

r = device_path_parse_major_minor(p, &m, &devno);
if (r < 0)
return log_error_errno(r, "Failed to parse major/minor device node: %m");
if (!S_ISBLK(m))
return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK), "Volatile root device is of wrong type.");
return log_error_errno(r, "Failed to determine block device of /usr file system: %m");
}
} else if (r < 0)
return log_error_errno(r, "Failed to read symlink /run/systemd/volatile-root: %m");
else {
mode_t m;
r = device_path_parse_major_minor(p, &m, &devno);
if (r < 0)
return log_error_errno(r, "Failed to parse major/minor device node: %m");
if (!S_ISBLK(m))
return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK), "Volatile root device is of wrong type.");
}

return enumerate_partitions(devno);
Expand Down