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.
This commit is contained in:
Lennart Poettering
2023-02-21 18:19:38 +01:00
parent b469b969f3
commit c56be2c294
7 changed files with 140 additions and 42 deletions
+19 -1
View File
@@ -341,6 +341,22 @@
<command>systemd-boot</command> being installed.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-R</option></term>
<term><option>--print-root-device</option></term>
<listitem><para>Print the path to the block device node backing the root file system of the local
OS. This prints a path such as <filename>/dev/nvme0n1p5</filename>. If the root file system is backed
by dm-crypt/LUKS or dm-verity the underlying block device is returned. If the root file system is
backed by multiple block devices (as supported by btrfs) the operation will fail. If the switch is
specified twice (i.e. <option>-RR</option>) and the discovered block device is a partition device the
"whole" block device it belongs to is determined and printed
(e.g. <filename>/dev/nvme0n1</filename>). If the root file system is <literal>tmpfs</literal> (or a
similar in-memory file system), the block device backing <filename>/usr/</filename> is returned if
applicable. If the root file system is a network file system (e.g. NFS, CIFS) the operation will
fail.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--no-variables</option></term>
<listitem><para>Do not touch the firmware's boot loader list stored in EFI variables.</para></listitem>
@@ -462,7 +478,9 @@
<refsect1>
<title>Exit status</title>
<para>On success, 0 is returned, a non-zero failure code otherwise.</para>
<para>On success, 0 is returned, a non-zero failure code otherwise. <command>bootctl
--print-root-device</command> returns exit status 80 in case the root file system is not backed by single
block device, and other non-zero exit statusses on other errors.</para>
</refsect1>
<refsect1>