On Tue Apr 22, 2025 at 6:27 PM CEST, Michael Köppl wrote:
> Check that the configured swapsize is not greater than the total size
> of the disk and that maxroot is at most hdsize / 4. Define the
> behavior for the auto-installer as well as the TUI and GUI installers.
>
> Signed-off-by: Michael Köppl <m.koe...@proxmox.com>
> ---
> The changes implemented in this patch regarding swap size only avoid
> rather obvious misconfigurations. However, users could still configure a
> 32GB swap volume on a 32GB hard disk and the installer would fail later
> on. Users could benefit another check that ensures the swap volume size
> does not go beyond a certain threshold. One option could be to set the
> limit similar to the 8GB maximum when the swap volume size is calculated
> from the size of the memory. OTOH, this might also be
> considered too restrictive. Would love some input on this.

I'd limit the swapsize to hdsize/8, as we state in the admin guide [0].
Although I'm not sure if we actually check this somewhere currently.

[0] https://pve.proxmox.com/pve-docs/pve-admin-guide.html#advanced_lvm_options

> [..]
> diff --git a/proxmox-auto-installer/src/utils.rs 
> b/proxmox-auto-installer/src/utils.rs
> index d6bc6e3..85a1f52 100644
> --- a/proxmox-auto-installer/src/utils.rs
> +++ b/proxmox-auto-installer/src/utils.rs
> @@ -396,6 +396,19 @@ pub fn verify_disks_settings(answer: &Answer) -> 
> Result<()> {
>              );
>          }
>      }
> +
> +    if let answer::FsOptions::LVM(lvm) = &answer.disks.fs_options {
> +        if lvm.swapsize > lvm.hdsize {
> +            bail!("LVM swapsize cannot be greater than hdsize");
> +        }
> +
> +        if let Some((maxroot, hdsize)) = lvm.maxroot.zip(lvm.hdsize) {
> +            if maxroot > hdsize / 4.0 {
> +                bail!("LVM maxroot cannot be greater than hdsize / 4");
> +            }
> +        }
> +    }

If feasible, could these checks be de-duplicated with the ones below?
Since they do check the exact same things.

> +
>      Ok(())
>  }
>
> diff --git a/proxmox-installer-common/src/disk_checks.rs 
> b/proxmox-installer-common/src/disk_checks.rs
> index 1d17e2c..bb33baf 100644
> --- a/proxmox-installer-common/src/disk_checks.rs
> +++ b/proxmox-installer-common/src/disk_checks.rs
> [..]
> @@ -49,6 +49,24 @@ pub fn check_disks_4kn_legacy_boot(boot_type: BootType, 
> disks: &[Disk]) -> Result
>      Ok(())
>  }
>
> +/// Checks whether a user-supplied LVM setup is valid or not, such as the 
> swapsize or maxroot not
> +/// exceeding certain thresholds.
> +///
> +/// # Arguments
> +///
> +/// * `bootdisk_opts` - The LVM options set by the user.
> +pub fn check_lvm_bootdisk_opts(bootdisk_opts: &LvmBootdiskOptions) -> 
> Result<(), &str> {
> +    if bootdisk_opts.swap_size > Some(bootdisk_opts.total_size) {
> +        return Err("Swap size cannot be greater than total size");

I'd include the actual value of the swap size and total size here, for
better feedback to the user, e.g.

"Swap (32 GiB) cannot be bigger than total harddisk size (16 GiB)"

> +    }
> +
> +    if bootdisk_opts.max_root_size > Some(bootdisk_opts.total_size / 4.0) {
> +        return Err("Max root size cannot be greater than (total size / 4)");

Similar here, e.g.

"Maximum root volume size (16 GiB) cannot be bigger than (hard size size / 4 = 
8 GiB)"

> +    }
> +
> +    Ok(())
> +}
> +
> diff --git a/proxmox-tui-installer/src/views/bootdisk.rs 
> b/proxmox-tui-installer/src/views/bootdisk.rs
> index 313a3c9..60d5316 100644
> --- a/proxmox-tui-installer/src/views/bootdisk.rs
> +++ b/proxmox-tui-installer/src/views/bootdisk.rs
> [..]
> @@ -264,6 +264,8 @@ impl AdvancedBootdiskOptionsView {
>                  .get_values()
>                  .ok_or("Failed to retrieve advanced bootdisk options")?;
>
> +            check_lvm_bootdisk_opts(&advanced).map_err(|err| 
> format!("{fstype}: {err}"))?;

Can be:

check_lvm_bootdisk_opts(&advanced).with_context(|| fstype.to_string())



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to