* [pbs-devel] [PATCH v6 proxmox 1/5] sys: add helper to get bootmode and secureboot status
2023-11-29 13:28 [pbs-devel] [PATCH v6 proxmox{, -backup} 0/5] Add boot_mode, improve kernel version Gabriel Goller
@ 2023-11-29 13:28 ` Gabriel Goller
2023-11-29 13:58 ` [pbs-devel] applied: " Wolfgang Bumiller
2023-11-29 13:28 ` [pbs-devel] [PATCH v6 proxmox-backup 2/5] node: status: added bootmode Gabriel Goller
` (5 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: Gabriel Goller @ 2023-11-29 13:28 UTC (permalink / raw)
To: pbs-devel
Helper that return the current boot_mode and secureboot status.
Detection works the same as in pve, we use `/sys/firmware/efi` and
the `efivars/SecureBoot-xxx..` file.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
proxmox-sys/src/boot_mode.rs | 60 ++++++++++++++++++++++++++++++++++++
proxmox-sys/src/lib.rs | 1 +
2 files changed, 61 insertions(+)
create mode 100644 proxmox-sys/src/boot_mode.rs
diff --git a/proxmox-sys/src/boot_mode.rs b/proxmox-sys/src/boot_mode.rs
new file mode 100644
index 0000000..390618c
--- /dev/null
+++ b/proxmox-sys/src/boot_mode.rs
@@ -0,0 +1,60 @@
+use std::{io::Read, sync::OnceLock};
+
+/// The SecureBoot status
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub enum SecureBoot {
+ /// SecureBoot is enabled
+ Enabled,
+ /// SecureBoot is disabled
+ Disabled,
+}
+
+/// The possible BootModes
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub enum BootMode {
+ /// The BootMode is EFI/UEFI
+ Efi,
+ /// The BootMode is Legacy BIOS
+ Bios,
+}
+
+static BOOT_MODE: OnceLock<BootMode> = OnceLock::new();
+static SECURE_BOOT: OnceLock<SecureBoot> = OnceLock::new();
+
+impl BootMode {
+ /// Returns the current bootmode (BIOS or EFI)
+ pub fn query() -> BootMode {
+ let value: &BootMode = BOOT_MODE.get_or_init(|| {
+ if std::path::Path::new("/sys/firmware/efi").exists() {
+ BootMode::Efi
+ } else {
+ BootMode::Bios
+ }
+ });
+ *value
+ }
+}
+
+impl SecureBoot {
+ /// Checks if secure boot is enabled
+ pub fn query() -> SecureBoot {
+ let value: &SecureBoot = SECURE_BOOT.get_or_init(|| {
+ // Check if SecureBoot is enabled
+ // Attention: this file is not seekable!
+ // Spec: https://uefi.org/specs/UEFI/2.10/03_Boot_Manager.html?highlight=8be4d#globally-defined-variables
+ let mut buf = [0; 5];
+ if std::fs::File::open(
+ "/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c",
+ )
+ .and_then(|mut file| file.read_exact(&mut buf))
+ .is_ok()
+ && buf[4] == 1
+ {
+ SecureBoot::Enabled
+ } else {
+ SecureBoot::Disabled
+ }
+ });
+ *value
+ }
+}
diff --git a/proxmox-sys/src/lib.rs b/proxmox-sys/src/lib.rs
index 7e59058..8ea7073 100644
--- a/proxmox-sys/src/lib.rs
+++ b/proxmox-sys/src/lib.rs
@@ -1,5 +1,6 @@
use std::os::unix::ffi::OsStrExt;
+pub mod boot_mode;
pub mod command;
#[cfg(feature = "crypt")]
pub mod crypt;
--
2.39.2
^ permalink raw reply [flat|nested] 11+ messages in thread
* [pbs-devel] [PATCH v6 proxmox-backup 2/5] node: status: added bootmode
2023-11-29 13:28 [pbs-devel] [PATCH v6 proxmox{, -backup} 0/5] Add boot_mode, improve kernel version Gabriel Goller
2023-11-29 13:28 ` [pbs-devel] [PATCH v6 proxmox 1/5] sys: add helper to get bootmode and secureboot status Gabriel Goller
@ 2023-11-29 13:28 ` Gabriel Goller
2023-11-29 13:40 ` Lukas Wagner
2023-11-29 13:28 ` [pbs-devel] [PATCH v6 proxmox-backup 3/5] ui: dashboard: show the bootmode Gabriel Goller
` (4 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: Gabriel Goller @ 2023-11-29 13:28 UTC (permalink / raw)
To: pbs-devel
Added field that shows the bootmode of the node. The bootmode is either
Legacy Bios, EFI, or EFI (Secure Boot). To detect the mode we use the
exact same method as in pve: We check if the `/sys/firmware/efi` folder
exists, then check if the `SecureBoot-xx...` file in the `efivars`
directory has the SecureBoot flag enabled.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
pbs-api-types/src/node.rs | 30 +++++++++++++++++++++++++++---
src/api2/node/status.rs | 29 +++++++++++++++++++++++++++--
2 files changed, 54 insertions(+), 5 deletions(-)
diff --git a/pbs-api-types/src/node.rs b/pbs-api-types/src/node.rs
index 704215bb..ab626157 100644
--- a/pbs-api-types/src/node.rs
+++ b/pbs-api-types/src/node.rs
@@ -1,9 +1,8 @@
-use serde::{Deserialize, Serialize};
use proxmox_schema::*;
+use serde::{Deserialize, Serialize};
use crate::StorageStatus;
-
#[api]
#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "kebab-case")]
@@ -39,6 +38,29 @@ pub struct NodeInformation {
pub fingerprint: String,
}
+
+#[api]
+#[derive(Serialize, Deserialize, Copy, Clone)]
+#[serde(rename_all = "kebab-case")]
+/// The possible BootModes
+pub enum BootMode {
+ /// The BootMode is EFI/UEFI
+ Efi,
+ /// The BootMode is Legacy BIOS
+ LegacyBios,
+}
+
+#[api]
+#[derive(Serialize, Deserialize, Clone)]
+#[serde(rename_all = "lowercase")]
+/// Holds the Bootmodes
+pub struct BootModeInformation {
+ /// The BootMode, either Efi or Bios
+ pub mode: BootMode,
+ /// SecureBoot status
+ pub secureboot: bool,
+}
+
#[api]
#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "kebab-case")]
@@ -78,7 +100,7 @@ pub struct NodeCpuInformation {
}
},
)]
-#[derive(Serialize, Deserialize, Default)]
+#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
/// The Node status
pub struct NodeStatus {
@@ -97,4 +119,6 @@ pub struct NodeStatus {
pub wait: f64,
pub cpuinfo: NodeCpuInformation,
pub info: NodeInformation,
+ /// Current boot mode
+ pub boot_info: BootModeInformation,
}
diff --git a/src/api2/node/status.rs b/src/api2/node/status.rs
index 639d7211..17b9aff3 100644
--- a/src/api2/node/status.rs
+++ b/src/api2/node/status.rs
@@ -1,16 +1,18 @@
-use std::os::unix::prelude::OsStrExt;
+use std::os::unix::ffi::OsStrExt;
use std::process::Command;
use anyhow::{bail, format_err, Error};
use serde_json::Value;
+use proxmox_sys::boot_mode;
use proxmox_sys::linux::procfs;
use proxmox_router::{ApiMethod, Permission, Router, RpcEnvironment};
use proxmox_schema::api;
use pbs_api_types::{
- NodePowerCommand, StorageStatus, NODE_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_POWER_MANAGEMENT,
+ BootModeInformation, NodePowerCommand, StorageStatus, NODE_SCHEMA, PRIV_SYS_AUDIT,
+ PRIV_SYS_POWER_MANAGEMENT,
};
use pbs_api_types::{
@@ -25,6 +27,26 @@ fn procfs_to_node_cpu_info(info: procfs::ProcFsCPUInfo) -> NodeCpuInformation {
}
}
+fn boot_mode_to_info(bm: boot_mode::BootMode, sb: boot_mode::SecureBoot) -> BootModeInformation {
+ use boot_mode::BootMode;
+ use boot_mode::SecureBoot;
+
+ match (bm, sb) {
+ (BootMode::Efi, SecureBoot::Enabled) => BootModeInformation {
+ mode: pbs_api_types::BootMode::Efi,
+ secureboot: true,
+ },
+ (BootMode::Efi, SecureBoot::Disabled) => BootModeInformation {
+ mode: pbs_api_types::BootMode::Efi,
+ secureboot: false,
+ },
+ (BootMode::Bios, _) => BootModeInformation {
+ mode: pbs_api_types::BootMode::LegacyBios,
+ secureboot: false,
+ },
+ }
+}
+
#[api(
input: {
properties: {
@@ -79,6 +101,8 @@ async fn get_status(
let disk = crate::tools::fs::fs_info_static(proxmox_lang::c_str!("/")).await?;
+ let boot_info = boot_mode_to_info(boot_mode::BootMode::query(), boot_mode::SecureBoot::query());
+
Ok(NodeStatus {
memory,
swap,
@@ -96,6 +120,7 @@ async fn get_status(
info: NodeInformation {
fingerprint: crate::cert_info()?.fingerprint()?,
},
+ boot_info,
})
}
--
2.39.2
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [pbs-devel] [PATCH v6 proxmox-backup 2/5] node: status: added bootmode
2023-11-29 13:28 ` [pbs-devel] [PATCH v6 proxmox-backup 2/5] node: status: added bootmode Gabriel Goller
@ 2023-11-29 13:40 ` Lukas Wagner
2023-11-29 13:50 ` Lukas Wagner
0 siblings, 1 reply; 11+ messages in thread
From: Lukas Wagner @ 2023-11-29 13:40 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Gabriel Goller
On 11/29/23 14:28, Gabriel Goller wrote:
> Added field that shows the bootmode of the node. The bootmode is either
> Legacy Bios, EFI, or EFI (Secure Boot). To detect the mode we use the
> exact same method as in pve: We check if the `/sys/firmware/efi` folder
> exists, then check if the `SecureBoot-xx...` file in the `efivars`
> directory has the SecureBoot flag enabled.
>
> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
This one does not apply anymore on latest master :)
--
- Lukas
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [pbs-devel] [PATCH v6 proxmox-backup 2/5] node: status: added bootmode
2023-11-29 13:40 ` Lukas Wagner
@ 2023-11-29 13:50 ` Lukas Wagner
0 siblings, 0 replies; 11+ messages in thread
From: Lukas Wagner @ 2023-11-29 13:50 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Gabriel Goller
On 11/29/23 14:40, Lukas Wagner wrote:
> On 11/29/23 14:28, Gabriel Goller wrote:
>> Added field that shows the bootmode of the node. The bootmode is either
>> Legacy Bios, EFI, or EFI (Secure Boot). To detect the mode we use the
>> exact same method as in pve: We check if the `/sys/firmware/efi` folder
>> exists, then check if the `SecureBoot-xx...` file in the `efivars`
>> directory has the SecureBoot flag enabled.
>>
>> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
>
> This one does not apply anymore on latest master :)
>
meh, works with `git am -3`, my bad. :)
--
- Lukas
^ permalink raw reply [flat|nested] 11+ messages in thread
* [pbs-devel] [PATCH v6 proxmox-backup 3/5] ui: dashboard: show the bootmode
2023-11-29 13:28 [pbs-devel] [PATCH v6 proxmox{, -backup} 0/5] Add boot_mode, improve kernel version Gabriel Goller
2023-11-29 13:28 ` [pbs-devel] [PATCH v6 proxmox 1/5] sys: add helper to get bootmode and secureboot status Gabriel Goller
2023-11-29 13:28 ` [pbs-devel] [PATCH v6 proxmox-backup 2/5] node: status: added bootmode Gabriel Goller
@ 2023-11-29 13:28 ` Gabriel Goller
2023-11-29 13:29 ` [pbs-devel] [PATCH v6 proxmox-backup 4/5] node: status: declutter kernel-version Gabriel Goller
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Gabriel Goller @ 2023-11-29 13:28 UTC (permalink / raw)
To: pbs-devel
Shows the bootmode of the instance. Options are Legacy BIOS,
EFI, or EFI(Secure Boot).
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
www/panel/NodeInfo.js | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/www/panel/NodeInfo.js b/www/panel/NodeInfo.js
index 2551c9a5..cba6d2a1 100644
--- a/www/panel/NodeInfo.js
+++ b/www/panel/NodeInfo.js
@@ -147,6 +147,21 @@ Ext.define('PBS.NodeInfoPanel', {
textField: 'kversion',
value: '',
},
+ {
+ colspan: 2,
+ title: gettext('Boot Mode'),
+ printBar: false,
+ textField: 'boot-info',
+ renderer: boot => {
+ if (boot.mode === 'legacy-bios') {
+ return 'Legacy BIOS';
+ } else if (boot.mode === 'efi') {
+ return `EFI${boot.secureboot ? ' (Secure Boot)' : ''}`;
+ }
+ return Proxmox.Utils.unknownText;
+ },
+ value: '',
+ },
{
xtype: 'pmxNodeInfoRepoStatus',
itemId: 'repositoryStatus',
--
2.39.2
^ permalink raw reply [flat|nested] 11+ messages in thread
* [pbs-devel] [PATCH v6 proxmox-backup 4/5] node: status: declutter kernel-version
2023-11-29 13:28 [pbs-devel] [PATCH v6 proxmox{, -backup} 0/5] Add boot_mode, improve kernel version Gabriel Goller
` (2 preceding siblings ...)
2023-11-29 13:28 ` [pbs-devel] [PATCH v6 proxmox-backup 3/5] ui: dashboard: show the bootmode Gabriel Goller
@ 2023-11-29 13:29 ` Gabriel Goller
2023-11-29 13:29 ` [pbs-devel] [PATCH v6 proxmox-backup 5/5] ui: dashboard: nicely display kernel version Gabriel Goller
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Gabriel Goller @ 2023-11-29 13:29 UTC (permalink / raw)
To: pbs-devel
Return a struct with all the components of the kernel version like it
has been done in pve. Also return the legacy `kversion` to keep
backwards compat.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
pbs-api-types/src/node.rs | 40 ++++++++++++++++++++++++++++++++++++++-
src/api2/node/status.rs | 18 +++++++++---------
2 files changed, 48 insertions(+), 10 deletions(-)
diff --git a/pbs-api-types/src/node.rs b/pbs-api-types/src/node.rs
index ab626157..c4e9a179 100644
--- a/pbs-api-types/src/node.rs
+++ b/pbs-api-types/src/node.rs
@@ -1,3 +1,5 @@
+use std::ffi::OsStr;
+
use proxmox_schema::*;
use serde::{Deserialize, Serialize};
@@ -38,6 +40,40 @@ pub struct NodeInformation {
pub fingerprint: String,
}
+#[api]
+#[derive(Serialize, Deserialize, Default)]
+#[serde(rename_all = "lowercase")]
+/// The current kernel version (output of `uname`)
+pub struct KernelVersionInformation {
+ /// The systemname/nodename
+ pub sysname: String,
+ /// The kernel release number
+ pub release: String,
+ /// The kernel version
+ pub version: String,
+ /// The machine architecture
+ pub machine: String,
+}
+
+impl KernelVersionInformation {
+ pub fn from_uname_parts(
+ sysname: &OsStr,
+ release: &OsStr,
+ version: &OsStr,
+ machine: &OsStr,
+ ) -> Self {
+ KernelVersionInformation {
+ sysname: sysname.to_str().map(String::from).unwrap_or_default(),
+ release: release.to_str().map(String::from).unwrap_or_default(),
+ version: version.to_str().map(String::from).unwrap_or_default(),
+ machine: machine.to_str().map(String::from).unwrap_or_default(),
+ }
+ }
+
+ pub fn get_legacy(&self) -> String {
+ format!("{} {} {}", self.sysname, self.release, self.version)
+ }
+}
#[api]
#[derive(Serialize, Deserialize, Copy, Clone)]
@@ -111,7 +147,9 @@ pub struct NodeStatus {
pub uptime: u64,
/// Load for 1, 5 and 15 minutes.
pub loadavg: [f64; 3],
- /// The current kernel version.
+ /// The current kernel version (NEW struct type).
+ pub current_kernel: KernelVersionInformation,
+ /// The current kernel version (LEGACY string type).
pub kversion: String,
/// Total CPU usage since last query.
pub cpu: f64,
diff --git a/src/api2/node/status.rs b/src/api2/node/status.rs
index 17b9aff3..07c20444 100644
--- a/src/api2/node/status.rs
+++ b/src/api2/node/status.rs
@@ -1,4 +1,3 @@
-use std::os::unix::ffi::OsStrExt;
use std::process::Command;
use anyhow::{bail, format_err, Error};
@@ -11,8 +10,8 @@ use proxmox_router::{ApiMethod, Permission, Router, RpcEnvironment};
use proxmox_schema::api;
use pbs_api_types::{
- BootModeInformation, NodePowerCommand, StorageStatus, NODE_SCHEMA, PRIV_SYS_AUDIT,
- PRIV_SYS_POWER_MANAGEMENT,
+ BootModeInformation, KernelVersionInformation, NodePowerCommand, StorageStatus, NODE_SCHEMA,
+ PRIV_SYS_AUDIT, PRIV_SYS_POWER_MANAGEMENT,
};
use pbs_api_types::{
@@ -92,11 +91,11 @@ async fn get_status(
let cpuinfo = procfs_to_node_cpu_info(cpuinfo);
let uname = nix::sys::utsname::uname()?;
- let kversion = format!(
- "{} {} {}",
- std::str::from_utf8(uname.sysname().as_bytes())?,
- std::str::from_utf8(uname.release().as_bytes())?,
- std::str::from_utf8(uname.version().as_bytes())?
+ let kernel_version = KernelVersionInformation::from_uname_parts(
+ uname.sysname(),
+ uname.release(),
+ uname.version(),
+ uname.machine(),
);
let disk = crate::tools::fs::fs_info_static(proxmox_lang::c_str!("/")).await?;
@@ -113,7 +112,8 @@ async fn get_status(
},
uptime: procfs::read_proc_uptime()?.0 as u64,
loadavg,
- kversion,
+ kversion: kernel_version.get_legacy(),
+ current_kernel: kernel_version,
cpuinfo,
cpu,
wait,
--
2.39.2
^ permalink raw reply [flat|nested] 11+ messages in thread
* [pbs-devel] [PATCH v6 proxmox-backup 5/5] ui: dashboard: nicely display kernel version
2023-11-29 13:28 [pbs-devel] [PATCH v6 proxmox{, -backup} 0/5] Add boot_mode, improve kernel version Gabriel Goller
` (3 preceding siblings ...)
2023-11-29 13:29 ` [pbs-devel] [PATCH v6 proxmox-backup 4/5] node: status: declutter kernel-version Gabriel Goller
@ 2023-11-29 13:29 ` Gabriel Goller
2023-11-29 13:55 ` [pbs-devel] [PATCH v6 proxmox{, -backup} 0/5] Add boot_mode, improve " Lukas Wagner
2023-11-29 14:31 ` [pbs-devel] applied-series: " Wolfgang Bumiller
6 siblings, 0 replies; 11+ messages in thread
From: Gabriel Goller @ 2023-11-29 13:29 UTC (permalink / raw)
To: pbs-devel
Extract and display the build version and kernel
release nicely.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
www/panel/NodeInfo.js | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/www/panel/NodeInfo.js b/www/panel/NodeInfo.js
index cba6d2a1..72f97c7c 100644
--- a/www/panel/NodeInfo.js
+++ b/www/panel/NodeInfo.js
@@ -140,11 +140,20 @@ Ext.define('PBS.NodeInfoPanel', {
value: '',
},
{
- itemId: 'kversion',
colspan: 2,
title: gettext('Kernel Version'),
printBar: false,
- textField: 'kversion',
+ // TODO: remove with next major and only use newish current-kernel textfield
+ multiField: true,
+ //textField: 'current-kernel',
+ renderer: ({ data }) => {
+ if (!data['current-kernel']) {
+ return data.kversion;
+ }
+ let kernel = data['current-kernel'];
+ let buildDate = kernel.version.match(/\((.+)\)\s*$/)[1] ?? 'unknown';
+ return `${kernel.sysname} ${kernel.release} (${buildDate})`;
+ },
value: '',
},
{
--
2.39.2
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [pbs-devel] [PATCH v6 proxmox{, -backup} 0/5] Add boot_mode, improve kernel version
2023-11-29 13:28 [pbs-devel] [PATCH v6 proxmox{, -backup} 0/5] Add boot_mode, improve kernel version Gabriel Goller
` (4 preceding siblings ...)
2023-11-29 13:29 ` [pbs-devel] [PATCH v6 proxmox-backup 5/5] ui: dashboard: nicely display kernel version Gabriel Goller
@ 2023-11-29 13:55 ` Lukas Wagner
2023-11-29 14:31 ` [pbs-devel] applied-series: " Wolfgang Bumiller
6 siblings, 0 replies; 11+ messages in thread
From: Lukas Wagner @ 2023-11-29 13:55 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Gabriel Goller
On 11/29/23 14:28, Gabriel Goller wrote:
> Ported the recent changes from the PVE NodeSummary (done by @Thomas) to
> the PBS NodeDashboard.
>
> It consists of:
> * Adding the bootmode field, shows either Legacy BIOS, EFI, or EFI
> (Secure Boot)
> * Declutter the kernel-version field and only show the release version
> and build-date.
>
Gave these another quick test, on Legacy BIOS as well as on a secure
boot EFI install. Works fine. :)
Tested-by: Lukas Wagner <l.wagner@proxmox.com>
--
- Lukas
^ permalink raw reply [flat|nested] 11+ messages in thread
* [pbs-devel] applied-series: [PATCH v6 proxmox{, -backup} 0/5] Add boot_mode, improve kernel version
2023-11-29 13:28 [pbs-devel] [PATCH v6 proxmox{, -backup} 0/5] Add boot_mode, improve kernel version Gabriel Goller
` (5 preceding siblings ...)
2023-11-29 13:55 ` [pbs-devel] [PATCH v6 proxmox{, -backup} 0/5] Add boot_mode, improve " Lukas Wagner
@ 2023-11-29 14:31 ` Wolfgang Bumiller
6 siblings, 0 replies; 11+ messages in thread
From: Wolfgang Bumiller @ 2023-11-29 14:31 UTC (permalink / raw)
To: Gabriel Goller; +Cc: pbs-devel
applied series
^ permalink raw reply [flat|nested] 11+ messages in thread