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:
@@ -22,3 +22,20 @@ command -v jq >/dev/null || {
|
||||
|
||||
"$bootctl" list --json=pretty | jq . >/dev/null
|
||||
"$bootctl" list --json=short | jq . >/dev/null
|
||||
|
||||
# bootctl --print-root-device should either succeed or fail with exit status 80
|
||||
# (because not backed by a single block device), but not fail otherwise.
|
||||
"$bootctl" -R || test "$?" -eq 80
|
||||
"$bootctl" -RR || test "$?" -eq 80
|
||||
|
||||
if "$bootctl" -R > /dev/null ; then
|
||||
P=$("$bootctl" -R)
|
||||
PP=$("$bootctl" -RR)
|
||||
|
||||
echo "$P vs $PP"
|
||||
test -b "$P"
|
||||
test -b "$PP"
|
||||
|
||||
# $P must be a prefix of $PP
|
||||
[[ $P = $PP* ]]
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user