From 6045b1b8a0d8ed6a94d06cdfc994bf1a5fa9dbb5 Mon Sep 17 00:00:00 2001 From: Jim Gauld Date: Thu, 6 May 2021 11:58:34 -0400 Subject: [PATCH] Provide utility script is-rootdisk-device.sh This provides a utility script to determine which disk contains the root filesystem. This can also be used as a helper function for io-scheduler udev rules that require specific configuration for root disk. Example usage: /usr/local/bin/is-rootdisk-device.sh ROOTDISK_DEVICE=sda /usr/local/bin/is-rootdisk-device.sh /dev/sda ROOTDISK_DEVICE=sda /usr/local/bin/is-rootdisk-device.sh /dev/sdb (i.e., no output) Partial-Bug: 1927515 Signed-off-by: Jim Gauld Change-Id: Ib0d4a161a407b08d294c5ff9aa0b7590961e18c9 --- .../platform-util/centos/platform-util.spec | 2 ++ .../scripts/is-rootdisk-device.sh | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100755 utilities/platform-util/scripts/is-rootdisk-device.sh diff --git a/utilities/platform-util/centos/platform-util.spec b/utilities/platform-util/centos/platform-util.spec index 124d39f9..55dc7761 100644 --- a/utilities/platform-util/centos/platform-util.spec +++ b/utilities/platform-util/centos/platform-util.spec @@ -60,6 +60,7 @@ install -d %{buildroot}%{local_bindir} install %{_buildsubdir}/scripts/tc_setup.sh %{buildroot}%{local_bindir} install %{_buildsubdir}/scripts/remotelogging_tc_setup.sh %{buildroot}%{local_bindir} install %{_buildsubdir}/scripts/connectivity_test %{buildroot}%{local_bindir} +install -m 555 %{_buildsubdir}/scripts/is-rootdisk-device.sh %{buildroot}%{local_bindir} install -m 555 %{_buildsubdir}/scripts/update-iso.sh %{buildroot}%{local_bindir} install -m 555 %{_buildsubdir}/scripts/gen-bootloader-iso.sh %{buildroot}%{local_bindir} install -m 555 %{_buildsubdir}/scripts/stx-iso-utils.sh %{buildroot}%{local_bindir} @@ -95,6 +96,7 @@ systemctl enable opt-platform.service %{local_bindir}/tc_setup.sh %{local_bindir}/remotelogging_tc_setup.sh %{local_bindir}/connectivity_test +%{local_bindir}/is-rootdisk-device.sh %{local_bindir}/set_keystone_user_option.sh %{local_sbindir}/patch-restart-mtce %{local_sbindir}/patch-restart-processes diff --git a/utilities/platform-util/scripts/is-rootdisk-device.sh b/utilities/platform-util/scripts/is-rootdisk-device.sh new file mode 100755 index 00000000..69cb4628 --- /dev/null +++ b/utilities/platform-util/scripts/is-rootdisk-device.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +# Usage: +# is-rootdisk-device +# +# If no arguments are provided, this shows which disk contains the +# root filesystem. If the optional device parameter is specified, +# output is only generated when the device matches the root disk. + +dev=$1 + +rootdev=$(lsblk --ascii -oPKNAME -n $(findmnt -n -T / -o SOURCE)) +if [ $# -eq 0 ]; then + echo "ROOTDISK_DEVICE=${rootdev}" +else + if [ "${dev}" == "/dev/${rootdev}" ] || \ + [ "/dev/${dev}" == "/dev/${rootdev}" ]; then + echo "ROOTDISK_DEVICE=${rootdev}" + else + exit 1 + fi +fi + +exit 0