all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH installer 0/2] auto: add option to poweroff system after installation
@ 2025-03-31 12:20 Christoph Heiss
  2025-03-31 12:20 ` [pve-devel] [PATCH installer 1/2] auto: answer: add option to poweroff the machine instead of reboot Christoph Heiss
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christoph Heiss @ 2025-03-31 12:20 UTC (permalink / raw)
  To: pve-devel

Fixes #5880 [0].

This can be useful for certain scenarios, such as being able to
provision a stack of servers using the auto-installer and afterwards
being able to work on the servers without time pressure, such as e.g.
removing the installation medium, before booting them into the OS for
the first time [1].

[0] https://bugzilla.proxmox.com/show_bug.cgi?id=5880
[1] https://forum.proxmox.com/threads/deploying-multiple-proxmox-host-easily.156129/post-721166

Christoph Heiss (2):
  auto: answer: add option to poweroff the machine instead of reboot
  post-hook: add `reboot_mode` field

 proxmox-auto-installer/src/answer.rs          | 10 ++++++
 .../src/bin/proxmox-auto-installer.rs         | 12 ++++++-
 proxmox-low-level-installer                   |  3 +-
 proxmox-post-hook/src/main.rs                 |  7 +++--
 unconfigured.sh                               | 31 ++++++++++++++++---
 5 files changed, 54 insertions(+), 9 deletions(-)

-- 
2.48.1



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


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

* [pve-devel] [PATCH installer 1/2] auto: answer: add option to poweroff the machine instead of reboot
  2025-03-31 12:20 [pve-devel] [PATCH installer 0/2] auto: add option to poweroff system after installation Christoph Heiss
@ 2025-03-31 12:20 ` Christoph Heiss
  2025-03-31 12:20 ` [pve-devel] [PATCH installer 2/2] post-hook: add `reboot_mode` field Christoph Heiss
  2025-04-04  9:04 ` [pve-devel] applied-series: [PATCH installer 0/2] auto: add option to poweroff system after installation Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Heiss @ 2025-03-31 12:20 UTC (permalink / raw)
  To: pve-devel

Fixes #5880 [0].

Add a new option `global.reboot_mode` to the answer file, which allows
users to optionally power off the machine after a successful
installation, instead of rebooting.

The option is completely backwards-compatible, i.e. defaults to
"reboot", keeping the current behaviour.

This can be useful for certain scenarios, such as being able to
provision a stack of servers using the auto-installer and afterwards
being able to work on the servers without time pressure, such as e.g.
removing the installation medium, before booting them into the OS for
the first time [1].

[0] https://bugzilla.proxmox.com/show_bug.cgi?id=5880
[1] https://forum.proxmox.com/threads/deploying-multiple-proxmox-host-easily.156129/post-721166

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-auto-installer/src/answer.rs          | 10 ++++++
 .../src/bin/proxmox-auto-installer.rs         | 12 ++++++-
 proxmox-low-level-installer                   |  3 +-
 unconfigured.sh                               | 31 ++++++++++++++++---
 4 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/proxmox-auto-installer/src/answer.rs b/proxmox-auto-installer/src/answer.rs
index c11818e..c15016f 100644
--- a/proxmox-auto-installer/src/answer.rs
+++ b/proxmox-auto-installer/src/answer.rs
@@ -56,10 +56,20 @@ pub struct Global {
     pub root_password_hashed: Option<String>,
     #[serde(alias = "reboot_on_error", default)]
     pub reboot_on_error: bool,
+    #[serde(alias = "reboot_mode", default)]
+    pub reboot_mode: RebootMode,
     #[serde(alias = "root_ssh_keys", default)]
     pub root_ssh_keys: Vec<String>,
 }
 
+#[derive(Clone, Deserialize, Debug, Default, PartialEq, Eq)]
+#[serde(rename_all = "kebab-case", deny_unknown_fields)]
+pub enum RebootMode {
+    #[default]
+    Reboot,
+    PowerOff,
+}
+
 #[derive(Clone, Deserialize, Debug)]
 #[serde(rename_all = "kebab-case", deny_unknown_fields)]
 pub struct PostNotificationHookInfo {
diff --git a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
index 0f86af0..05d1801 100644
--- a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
+++ b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
@@ -17,7 +17,7 @@ use proxmox_installer_common::{
 };
 
 use proxmox_auto_installer::{
-    answer::{Answer, FirstBootHookInfo, FirstBootHookSourceMode},
+    answer::{Answer, FirstBootHookInfo, FirstBootHookSourceMode, RebootMode},
     log::AutoInstLogger,
     udevinfo::UdevInfo,
     utils::parse_answer,
@@ -126,6 +126,16 @@ fn main() -> ExitCode {
         }
     }
 
+    if answer.global.reboot_mode == RebootMode::PowerOff {
+        if let Err(err) = File::create("/run/proxmox-poweroff-after-install") {
+            error!("failed to create poweroff-after-install flag-file: {err}");
+        } else {
+            info!("Powering off system after successful installation");
+        }
+    } else {
+        info!("Rebooting system after successful installation");
+    }
+
     match run_installation(&answer, &locales, &runtime_info, &udevadm_info, &setup_info) {
         Ok(_) => {
             info!("Installation done.");
diff --git a/proxmox-low-level-installer b/proxmox-low-level-installer
index bcfe60e..9d5d0a2 100755
--- a/proxmox-low-level-installer
+++ b/proxmox-low-level-installer
@@ -74,9 +74,10 @@ sub read_and_merge_config {
 
 sub send_reboot_ui_message {
     if (Proxmox::Install::Config::get_autoreboot()) {
+	my $action = -f '/run/proxmox-poweroff-after-install' ? 'powering off' : 'rebooting';
 	my $secs = 5;
 	while ($secs > 0) {
-	    Proxmox::UI::finished(1, "Installation finished - auto-rebooting in $secs seconds ..");
+	    Proxmox::UI::finished(1, "Installation finished - auto $action in $secs seconds ..");
 	    sleep 1;
 	    $secs -= 1;
 	}
diff --git a/unconfigured.sh b/unconfigured.sh
index a5621a0..4d641b2 100755
--- a/unconfigured.sh
+++ b/unconfigured.sh
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+reboot_action="reboot"
+
 trap "err_reboot" ERR
 
 # NOTE: we nowadays get exec'd by the initrd's PID 1, so we're the new PID 1
@@ -52,9 +54,17 @@ eject_and_reboot() {
 
     umount -l -n /dev
 
-    echo "rebooting - please remove the ISO boot media"
-    sleep 3
-    reboot -nf
+    # at this stage, all disks are sync'd & unmounted, so `-n/--no-sync` is safe to use here
+    if [ "$reboot_action" = "poweroff" ]; then
+	echo "powering off - please remove the ISO boot media"
+	sleep 3
+	poweroff -nf
+    else
+	echo "rebooting - please remove the ISO boot media"
+	sleep 3
+	reboot -nf
+    fi
+
     sleep 5
     echo "trigger reset system request"
     # we do not expect the reboot above to fail, so rather to avoid kpanic when pid 1 exits
@@ -103,9 +113,12 @@ real_reboot() {
     exit 0 # shouldn't be reached, kernel will panic in that case
 }
 
-# reachable through the ERR trap
 err_reboot() {
     printf "\nInstallation aborted - unable to continue (type exit or CTRL-D to reboot)\n"
+
+    # in case of error, always default to rebooting
+    reboot_action="reboot"
+
     debugsh || true
     real_reboot
 }
@@ -274,6 +287,10 @@ elif [ $start_auto_installer -ne 0 ]; then
             err_reboot
         fi
     fi
+
+    if [ -f /run/proxmox-poweroff-after-install ]; then
+	reboot_action="poweroff"
+    fi
 else
     echo "Starting the installer GUI - see tty2 (CTRL+ALT+F2) for any errors..."
     xinit -- -dpi "$DPI" -s 0 >/dev/tty2 2>&1
@@ -287,7 +304,11 @@ if [ $proxdebug -ne 0 ]; then
     debugsh || true
 fi
 
-echo "Installation done, rebooting... "
+if [ "$reboot_action" = "poweroff" ]; then
+    echo 'Installation done, powering off...'
+else
+    echo 'Installation done, rebooting...'
+fi
 
 killall5 -15
 
-- 
2.48.1



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


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

* [pve-devel] [PATCH installer 2/2] post-hook: add `reboot_mode` field
  2025-03-31 12:20 [pve-devel] [PATCH installer 0/2] auto: add option to poweroff system after installation Christoph Heiss
  2025-03-31 12:20 ` [pve-devel] [PATCH installer 1/2] auto: answer: add option to poweroff the machine instead of reboot Christoph Heiss
@ 2025-03-31 12:20 ` Christoph Heiss
  2025-04-04  9:04 ` [pve-devel] applied-series: [PATCH installer 0/2] auto: add option to poweroff system after installation Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Heiss @ 2025-03-31 12:20 UTC (permalink / raw)
  To: pve-devel

This just takes the option from the answer file and reproduces it for
the post-hook.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-auto-installer/src/answer.rs | 2 +-
 proxmox-post-hook/src/main.rs        | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/proxmox-auto-installer/src/answer.rs b/proxmox-auto-installer/src/answer.rs
index c15016f..1c30178 100644
--- a/proxmox-auto-installer/src/answer.rs
+++ b/proxmox-auto-installer/src/answer.rs
@@ -62,7 +62,7 @@ pub struct Global {
     pub root_ssh_keys: Vec<String>,
 }
 
-#[derive(Clone, Deserialize, Debug, Default, PartialEq, Eq)]
+#[derive(Copy, Clone, Deserialize, Serialize, Debug, Default, PartialEq, Eq)]
 #[serde(rename_all = "kebab-case", deny_unknown_fields)]
 pub enum RebootMode {
     #[default]
diff --git a/proxmox-post-hook/src/main.rs b/proxmox-post-hook/src/main.rs
index d03ce21..6a679b4 100644
--- a/proxmox-post-hook/src/main.rs
+++ b/proxmox-post-hook/src/main.rs
@@ -21,7 +21,7 @@ use std::{
 
 use anyhow::{Context, Result, anyhow, bail};
 use proxmox_auto_installer::{
-    answer::{Answer, PostNotificationHookInfo},
+    answer::{Answer, PostNotificationHookInfo, RebootMode},
     udevinfo::{UdevInfo, UdevProperties},
 };
 use proxmox_installer_common::{
@@ -144,7 +144,7 @@ struct PostHookInfoSchema {
 }
 
 impl PostHookInfoSchema {
-    const SCHEMA_VERSION: &str = "1.0";
+    const SCHEMA_VERSION: &str = "1.1";
 }
 
 impl Default for PostHookInfoSchema {
@@ -193,6 +193,8 @@ struct PostHookInfo {
     network_interfaces: Vec<NetworkInterfaceInfo>,
     /// Public parts of SSH host keys of the installed system
     ssh_public_host_keys: SshPublicHostKeys,
+    /// Action to will be performed, i.e. either reboot or power off the machine.
+    reboot_mode: RebootMode,
 }
 
 /// Defines the size of a gibibyte in bytes.
@@ -269,6 +271,7 @@ impl PostHookInfo {
                 ed25519: read_file("/etc/ssh/ssh_host_ed25519_key.pub")?,
                 rsa: read_file("/etc/ssh/ssh_host_rsa_key.pub")?,
             },
+            reboot_mode: answer.global.reboot_mode,
         })
     }
 
-- 
2.48.1



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


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

* [pve-devel] applied-series: [PATCH installer 0/2] auto: add option to poweroff system after installation
  2025-03-31 12:20 [pve-devel] [PATCH installer 0/2] auto: add option to poweroff system after installation Christoph Heiss
  2025-03-31 12:20 ` [pve-devel] [PATCH installer 1/2] auto: answer: add option to poweroff the machine instead of reboot Christoph Heiss
  2025-03-31 12:20 ` [pve-devel] [PATCH installer 2/2] post-hook: add `reboot_mode` field Christoph Heiss
@ 2025-04-04  9:04 ` Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2025-04-04  9:04 UTC (permalink / raw)
  To: Proxmox VE development discussion, Christoph Heiss

Am 31.03.25 um 14:20 schrieb Christoph Heiss:
> Fixes #5880 [0].
> 
> This can be useful for certain scenarios, such as being able to
> provision a stack of servers using the auto-installer and afterwards
> being able to work on the servers without time pressure, such as e.g.
> removing the installation medium, before booting them into the OS for
> the first time [1].
> 
> [0] https://bugzilla.proxmox.com/show_bug.cgi?id=5880
> [1] https://forum.proxmox.com/threads/deploying-multiple-proxmox-host-easily.156129/post-721166
> 
> Christoph Heiss (2):
>   auto: answer: add option to poweroff the machine instead of reboot
>   post-hook: add `reboot_mode` field
> 
>  proxmox-auto-installer/src/answer.rs          | 10 ++++++
>  .../src/bin/proxmox-auto-installer.rs         | 12 ++++++-
>  proxmox-low-level-installer                   |  3 +-
>  proxmox-post-hook/src/main.rs                 |  7 +++--
>  unconfigured.sh                               | 31 ++++++++++++++++---
>  5 files changed, 54 insertions(+), 9 deletions(-)
> 


applied series, thanks!


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


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

end of thread, other threads:[~2025-04-04  9:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-31 12:20 [pve-devel] [PATCH installer 0/2] auto: add option to poweroff system after installation Christoph Heiss
2025-03-31 12:20 ` [pve-devel] [PATCH installer 1/2] auto: answer: add option to poweroff the machine instead of reboot Christoph Heiss
2025-03-31 12:20 ` [pve-devel] [PATCH installer 2/2] post-hook: add `reboot_mode` field Christoph Heiss
2025-04-04  9:04 ` [pve-devel] applied-series: [PATCH installer 0/2] auto: add option to poweroff system after installation Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal