mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 06:25:37 +03:00
c56be2c294
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.
42 lines
970 B
Bash
Executable File
42 lines
970 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
set -e
|
|
set -o pipefail
|
|
|
|
bootctl="${1:?}"
|
|
|
|
"$bootctl" --no-pager list >/dev/null || {
|
|
echo "$bootctl list failed, skipping tests" 1>&2
|
|
exit 77
|
|
}
|
|
|
|
set -x
|
|
|
|
"$bootctl" list --json=pretty | python3 -m json.tool >/dev/null
|
|
"$bootctl" list --json=short | python3 -m json.tool >/dev/null
|
|
|
|
command -v jq >/dev/null || {
|
|
echo "jq is not available, skipping jq tests" 1>&2
|
|
exit 0
|
|
}
|
|
|
|
"$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
|