public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH installer 0/2] add stricter checks w.r.t. BIOS boot on 4Kn disks
@ 2023-08-10 10:31 Christoph Heiss
  2023-08-10 10:31 ` [pve-devel] [PATCH installer 1/2] raid setup: btrfs: do not allow legacy " Christoph Heiss
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christoph Heiss @ 2023-08-10 10:31 UTC (permalink / raw)
  To: pve-devel

Booting in legacy BIOS mode on 4Kn disks is generally unsupported, or
rather, simply does not work. The GUI installer already checks that
properly for LVM and ZFS, but is missing it for Btrfs, so extend the
check appropriately.

Further, the TUI installer only checked it for ZFS RAIDs, but not for
LVM and Btrfs. Add proper checks there as well, such that the user gets
immediate feedback early than during the install process.

Seems nobody noticed yet, but apparently 4Kn disks are pretty rare these
days anyway.

Prerequisites
-------------
This series is based on top of

  [PATCH installer 0/6] some small, assorted fixes & cleanups
  https://lists.proxmox.com/pipermail/pve-devel/2023-August/058708.html

which fixes another 4Kn disk issue.

Testing
-------
Tested by creating a block device with 4K sectorsize using
the following QEMU args:
  -device virtio-blk,drive=testdrive4k,logical_block_size=4096,physical_block_size=4096
  -drive file=/path/to/4k-testdisk.img,if=none,id=testdrive4k

The 4k-testdisk.img was created with:
  qemu-img create -f qcow2 /path/to/4k-testdisk.img 16G

Christoph Heiss (2):
  raid setup: btrfs: do not allow legacy BIOS boot on 4Kn disks
  tui: disallow legacy BIOS boot from 4Kn disks for all filesystems

 Proxmox/Install.pm                          |   4 +
 proxmox-tui-installer/src/main.rs           |   2 +-
 proxmox-tui-installer/src/setup.rs          |   2 +-
 proxmox-tui-installer/src/views/bootdisk.rs | 171 ++++++++------------
 4 files changed, 74 insertions(+), 105 deletions(-)

--
2.41.0





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH installer 1/2] raid setup: btrfs: do not allow legacy BIOS boot on 4Kn disks
  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 ` Christoph Heiss
  2023-08-10 10:31 ` [pve-devel] [PATCH installer 2/2] tui: disallow legacy BIOS boot from 4Kn disks for all filesystems Christoph Heiss
  2023-08-23  8:37 ` [pve-devel] applied-series: [PATCH installer 0/2] add stricter checks w.r.t. BIOS boot on 4Kn disks Wolfgang Bumiller
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Heiss @ 2023-08-10 10:31 UTC (permalink / raw)
  To: pve-devel

This is already checked for LVM and ZFS setups, but not for Btrfs. Add
it there too, as it doesn't work anyway.

Tested by creating a block device with 4K sectorsize using
the following QEMU args:
  -device virtio-blk,drive=testdrive4k,logical_block_size=4096,physical_block_size=4096
  -drive file=/path/to/4k-testdisk.img,if=none,id=testdrive4k

The 4k-testdisk.img was created with:
  qemu-img create -f qcow2 /path/to/4k-testdisk.img 16G

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 Proxmox/Install.pm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Proxmox/Install.pm b/Proxmox/Install.pm
index 1c4811d..1117fc4 100644
--- a/Proxmox/Install.pm
+++ b/Proxmox/Install.pm
@@ -299,6 +299,10 @@ sub get_btrfs_raid_setup {
     my $diskcount = scalar(@$devlist);
     die "$filesys needs at least one device\n" if $diskcount < 1;
 
+    foreach my $hd (@$devlist) {
+	legacy_bios_4k_check(@$hd[4]);
+    }
+
     my $mode;
 
     if ($diskcount == 1) {
-- 
2.41.0





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH installer 2/2] tui: disallow legacy BIOS boot from 4Kn disks for all filesystems
  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
  2023-08-23  8:37 ` [pve-devel] applied-series: [PATCH installer 0/2] add stricter checks w.r.t. BIOS boot on 4Kn disks Wolfgang Bumiller
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Heiss @ 2023-08-10 10:31 UTC (permalink / raw)
  To: pve-devel

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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] applied-series: [PATCH installer 0/2] add stricter checks w.r.t. BIOS boot on 4Kn disks
  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 ` [pve-devel] [PATCH installer 2/2] tui: disallow legacy BIOS boot from 4Kn disks for all filesystems Christoph Heiss
@ 2023-08-23  8:37 ` Wolfgang Bumiller
  2 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Bumiller @ 2023-08-23  8:37 UTC (permalink / raw)
  To: Christoph Heiss; +Cc: pve-devel

applied both patches, thanks




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-23  8:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [pve-devel] [PATCH installer 2/2] tui: disallow legacy BIOS boot from 4Kn disks for all filesystems Christoph Heiss
2023-08-23  8:37 ` [pve-devel] applied-series: [PATCH installer 0/2] add stricter checks w.r.t. BIOS boot on 4Kn disks Wolfgang Bumiller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal