From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 2/2] tui: disallow legacy BIOS boot from 4Kn disks for all filesystems
Date: Thu, 10 Aug 2023 12:31:57 +0200 [thread overview]
Message-ID: <20230810103158.436341-3-c.heiss@proxmox.com> (raw)
In-Reply-To: <20230810103158.436341-1-c.heiss@proxmox.com>
The GUI installer already has the same rules in place, not allowing to
boot from 4Kn disks when booting in legacy BIOS mode. The TUI installer
currently only checks that for ZFS RAIDs, so extend that check to all
filesystem configurations.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
proxmox-tui-installer/src/main.rs | 2 +-
proxmox-tui-installer/src/setup.rs | 2 +-
proxmox-tui-installer/src/views/bootdisk.rs | 171 ++++++++------------
3 files changed, 70 insertions(+), 105 deletions(-)
diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 580cb34..23a4ead 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -431,7 +431,7 @@ fn bootdisk_dialog(siv: &mut Cursive) -> InstallerView {
InstallerView::new(
&state,
- BootdiskOptionsView::new(&state.runtime_info.disks, &state.options.bootdisk)
+ BootdiskOptionsView::new(siv, &state.runtime_info.disks, &state.options.bootdisk)
.with_name("bootdisk-options"),
Box::new(|siv| {
let options = siv.call_on_name("bootdisk-options", BootdiskOptionsView::get_values);
diff --git a/proxmox-tui-installer/src/setup.rs b/proxmox-tui-installer/src/setup.rs
index dec91cb..46b47cd 100644
--- a/proxmox-tui-installer/src/setup.rs
+++ b/proxmox-tui-installer/src/setup.rs
@@ -392,7 +392,7 @@ pub struct RuntimeInfo {
pub hvm_supported: bool,
}
-#[derive(Clone, Eq, Deserialize, PartialEq)]
+#[derive(Copy, Clone, Eq, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum BootType {
Bios,
diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs
index d01495e..dbd13ea 100644
--- a/proxmox-tui-installer/src/views/bootdisk.rs
+++ b/proxmox-tui-installer/src/views/bootdisk.rs
@@ -16,17 +16,18 @@ use crate::{
FsType, LvmBootdiskOptions, ZfsBootdiskOptions, ZfsRaidLevel, FS_TYPES,
ZFS_CHECKSUM_OPTIONS, ZFS_COMPRESS_OPTIONS,
},
- setup::{BootType, RuntimeInfo},
+ setup::BootType,
};
use crate::{setup::ProxmoxProduct, InstallerState};
pub struct BootdiskOptionsView {
view: LinearLayout,
advanced_options: Rc<RefCell<BootdiskOptions>>,
+ boot_type: BootType,
}
impl BootdiskOptionsView {
- pub fn new(disks: &[Disk], options: &BootdiskOptions) -> Self {
+ pub fn new(siv: &mut Cursive, disks: &[Disk], options: &BootdiskOptions) -> Self {
let bootdisk_form = FormView::new()
.child(
"Target harddisk",
@@ -53,9 +54,15 @@ impl BootdiskOptionsView {
.child(DummyView)
.child(advanced_button);
+ let boot_type = siv
+ .user_data::<InstallerState>()
+ .map(|state| state.runtime_info.boot_type)
+ .unwrap_or(BootType::Bios);
+
Self {
view,
advanced_options,
+ boot_type,
}
}
@@ -74,6 +81,7 @@ impl BootdiskOptionsView {
options.disks = vec![disk];
}
+ check_disks_4kn_legacy_boot(self.boot_type, &options.disks)?;
Ok(options)
}
}
@@ -168,7 +176,7 @@ impl AdvancedBootdiskOptionsView {
);
}
- fn get_values(&mut self, runinfo: &RuntimeInfo) -> Result<BootdiskOptions, String> {
+ fn get_values(&mut self) -> Result<BootdiskOptions, String> {
let fstype = self
.view
.get_child(1)
@@ -198,8 +206,7 @@ impl AdvancedBootdiskOptionsView {
.ok_or("Failed to retrieve advanced bootdisk options")?;
if let FsType::Zfs(level) = fstype {
- check_zfs_raid_config(runinfo, level, &disks)
- .map_err(|err| format!("{fstype}: {err}"))?;
+ check_zfs_raid_config(level, &disks).map_err(|err| format!("{fstype}: {err}"))?;
}
Ok(BootdiskOptions {
@@ -554,17 +561,11 @@ fn advanced_options_view(disks: &[Disk], options: Rc<RefCell<BootdiskOptions>>)
.button("Ok", {
let options_ref = options.clone();
move |siv| {
- let runinfo = siv
- .user_data::<InstallerState>()
- .unwrap()
- .runtime_info
- .clone();
-
let options = siv
.call_on_name("advanced-bootdisk-options-dialog", |view: &mut Dialog| {
view.get_content_mut()
.downcast_mut::<AdvancedBootdiskOptionsView>()
- .map(|v| v.get_values(&runinfo))
+ .map(AdvancedBootdiskOptionsView::get_values)
})
.flatten();
@@ -626,29 +627,33 @@ fn check_raid_min_disks(disks: &[Disk], min: usize) -> Result<(), String> {
}
}
-/// Checks whether a user-supplied ZFS RAID setup is valid or not, such as disk sizes, minimum
-/// number of disks and legacy BIOS compatibility.
+/// Checks all disks for legacy BIOS boot compatibility and reports an error as appropriate. 4Kn
+/// disks are generally broken with legacy BIOS and cannot be booted from.
///
/// # Arguments
///
/// * `runinfo` - `RuntimeInfo` instance of currently running system
+/// * `disks` - List of disks designated as bootdisk targets.
+fn check_disks_4kn_legacy_boot(boot_type: BootType, disks: &[Disk]) -> Result<(), &str> {
+ let is_blocksize_4096 = |disk: &Disk| disk.block_size.map(|s| s == 4096).unwrap_or(false);
+
+ if boot_type == BootType::Bios && disks.iter().any(is_blocksize_4096) {
+ return Err("Booting from 4Kn drive in legacy BIOS mode is not supported.");
+ }
+
+ Ok(())
+}
+
+/// Checks whether a user-supplied ZFS RAID setup is valid or not, such as disk sizes andminimum
+/// number of disks.
+///
+/// # Arguments
+///
/// * `level` - The targeted ZFS RAID level by the user.
/// * `disks` - List of disks designated as RAID targets.
-fn check_zfs_raid_config(
- runinfo: &RuntimeInfo,
- level: ZfsRaidLevel,
- disks: &[Disk],
-) -> Result<(), String> {
+fn check_zfs_raid_config(level: ZfsRaidLevel, disks: &[Disk]) -> Result<(), String> {
// See also Proxmox/Install.pm:get_zfs_raid_setup()
- for disk in disks {
- if runinfo.boot_type != BootType::Efi
- && disk.block_size.map(|v| v == 4096).unwrap_or_default()
- {
- return Err("Booting from 4Kn drive in legacy BIOS mode is not supported.".to_owned());
- }
- }
-
let check_mirror_size = |disk1: &Disk, disk2: &Disk| {
if (disk1.size - disk2.size).abs() > disk1.size / 10. {
Err(format!(
@@ -719,10 +724,7 @@ fn check_btrfs_raid_config(level: BtrfsRaidLevel, disks: &[Disk]) -> Result<(),
#[cfg(test)]
mod tests {
- use std::collections::HashMap;
-
use super::*;
- use crate::setup::{Dns, NetworkInfo};
fn dummy_disk(index: usize) -> Disk {
Disk {
@@ -738,24 +740,6 @@ mod tests {
(0..num).map(dummy_disk).collect()
}
- fn dummy_runinfo(boot_type: BootType) -> RuntimeInfo {
- RuntimeInfo {
- boot_type,
- country: Some("at".to_owned()),
- disks: dummy_disks(4),
- network: NetworkInfo {
- dns: Dns {
- domain: None,
- dns: vec![],
- },
- routes: None,
- interfaces: HashMap::new(),
- },
- total_memory: 1024 * 1024 * 1024 * 64,
- hvm_supported: true,
- }
- }
-
#[test]
fn duplicate_disks() {
assert!(check_for_duplicate_disks(&dummy_disks(2)).is_ok());
@@ -780,6 +764,19 @@ mod tests {
assert!(check_raid_min_disks(&disks, 1).is_ok());
}
+ #[test]
+ fn bios_boot_compat_4kn() {
+ for i in 0..10 {
+ let mut disks = dummy_disks(10);
+ disks[i].block_size = Some(4096);
+
+ // Must fail if /any/ of the disks are 4Kn
+ assert!(check_disks_4kn_legacy_boot(BootType::Bios, &disks).is_err());
+ // For UEFI, we allow it for every configuration
+ assert!(check_disks_4kn_legacy_boot(BootType::Efi, &disks).is_ok());
+ }
+ }
+
#[test]
fn btrfs_raid() {
let disks = dummy_disks(10);
@@ -800,66 +797,34 @@ mod tests {
}
#[test]
- fn zfs_raid_bios() {
- let runinfo = dummy_runinfo(BootType::Bios);
-
- let mut disks = dummy_disks(10);
- zfs_common_tests(&disks, &runinfo);
+ fn zfs_raid() {
+ let disks = dummy_disks(10);
- for disk in &mut disks {
- disk.block_size = None;
- }
- // Should behave the same as if an explicit block size of 512 was set
- zfs_common_tests(&disks, &runinfo);
+ assert!(check_zfs_raid_config(ZfsRaidLevel::Raid0, &[]).is_err());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::Raid0, &disks[..1]).is_ok());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::Raid0, &disks).is_ok());
- for i in 0..10 {
- let mut disks = dummy_disks(10);
- disks[i].block_size = Some(4096);
+ assert!(check_zfs_raid_config(ZfsRaidLevel::Raid1, &[]).is_err());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::Raid1, &disks[..2]).is_ok());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::Raid1, &disks).is_ok());
- // Must fail if /any/ of the disks are 4Kn
- assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid0, &disks).is_err());
- assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid1, &disks).is_err());
- assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::Raid10, &disks).is_err());
- assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ, &disks).is_err());
- assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ2, &disks).is_err());
- assert!(check_zfs_raid_config(&runinfo, ZfsRaidLevel::RaidZ3, &disks).is_err());
- }
- }
+ assert!(check_zfs_raid_config(ZfsRaidLevel::Raid10, &[]).is_err());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::Raid10, &dummy_disks(4)).is_ok());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::Raid10, &disks).is_ok());
- #[test]
- fn zfs_raid_efi() {
- let disks = dummy_disks(10);
- let runinfo = dummy_runinfo(BootType::Efi);
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ, &[]).is_err());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ, &disks[..2]).is_err());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ, &disks[..3]).is_ok());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ, &disks).is_ok());
- zfs_common_tests(&disks, &runinfo);
- }
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ2, &[]).is_err());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ2, &disks[..3]).is_err());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ2, &disks[..4]).is_ok());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ2, &disks).is_ok());
- fn zfs_common_tests(disks: &[Disk], runinfo: &RuntimeInfo) {
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::Raid0, &[]).is_err());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::Raid0, &disks[..1]).is_ok());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::Raid0, disks).is_ok());
-
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::Raid1, &[]).is_err());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::Raid1, &disks[..2]).is_ok());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::Raid1, disks).is_ok());
-
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::Raid10, &[]).is_err());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::Raid10, &dummy_disks(4)).is_ok());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::Raid10, disks).is_ok());
-
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ, &[]).is_err());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ, &disks[..2]).is_err());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ, &disks[..3]).is_ok());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ, disks).is_ok());
-
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ2, &[]).is_err());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ2, &disks[..3]).is_err());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ2, &disks[..4]).is_ok());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ2, disks).is_ok());
-
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ3, &[]).is_err());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ3, &disks[..4]).is_err());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ3, &disks[..5]).is_ok());
- assert!(check_zfs_raid_config(runinfo, ZfsRaidLevel::RaidZ3, disks).is_ok());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ3, &[]).is_err());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ3, &disks[..4]).is_err());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ3, &disks[..5]).is_ok());
+ assert!(check_zfs_raid_config(ZfsRaidLevel::RaidZ3, &disks).is_ok());
}
}
--
2.41.0
next prev parent reply other threads:[~2023-08-10 10:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-10 10:31 [pve-devel] [PATCH installer 0/2] add stricter checks w.r.t. BIOS boot on 4Kn disks Christoph Heiss
2023-08-10 10:31 ` [pve-devel] [PATCH installer 1/2] raid setup: btrfs: do not allow legacy " Christoph Heiss
2023-08-10 10:31 ` Christoph Heiss [this message]
2023-08-23 8:37 ` [pve-devel] applied-series: [PATCH installer 0/2] add stricter checks w.r.t. " Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230810103158.436341-3-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox