summaryrefslogtreecommitdiff
path: root/src/gpt-auto-generator
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-02-20 17:25:14 +0100
committerLennart Poettering <lennart@poettering.net>2023-02-21 18:19:38 +0100
commitc56be2c294f55545ea34417a2ec4f6ad2cd1df6f (patch)
tree93cee6bbda623c51da5ff8d4c9ea16cf776c6a90 /src/gpt-auto-generator
parentb469b969f30dbb4d4aeeccab79ec8f3782e769aa (diff)
downloadsystemd-c56be2c294f55545ea34417a2ec4f6ad2cd1df6f.tar.gz
bootctl: add new --print-root-device option
We already have this nice code in system that determines the block device backing the root file system, but it's only used internally in systemd-gpt-generator. Let's make this more accessible and expose it directly in bootctl. It doesn't fit immediately into the topic of bootctl, but I think it's close enough and behaves very similar to the existing "bootctl --print-boot-path" and "--print-esp-path" tools. If --print-root-device (or -R) is specified once, will show the block device backing the root fs, and if specified twice (probably easier: -RR) it will show the whole block device that block device belongs to in case it is a partition block device. Suggested use: # cfdisk `bootctl -RR` To get access to the partition table, behind the OS install, for whatever it might be.
Diffstat (limited to 'src/gpt-auto-generator')
-rw-r--r--src/gpt-auto-generator/gpt-auto-generator.c39
1 files changed, 7 insertions, 32 deletions
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index 21b9284f8a..34f67b7fcb 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -773,40 +773,15 @@ static int enumerate_partitions(dev_t devnum) {
}
static int add_mounts(void) {
- _cleanup_free_ char *p = NULL;
- int r;
dev_t devno;
+ int r;
- /* 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, "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 a single block device. (Could be NFS or so, or could be multi-device RAID or so) */
- 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 determine block device of /usr/ file system: %m");
- if (r == 0) { /* /usr/ not backed by single block device, either. */
- log_debug("Neither root nor /usr/ file system are on a (single) block device.");
- return 0;
- }
- }
- } 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.");
+ r = blockdev_get_root(LOG_ERR, &devno);
+ if (r < 0)
+ return r;
+ if (r == 0) {
+ log_debug("Skipping automatic GPT dissection logic, root file system not backed by a (single) whole block device.");
+ return 0;
}
return enumerate_partitions(devno);