summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2025-06-23 09:17:55 +0100
committerGitHub <noreply@github.com>2025-06-23 09:17:55 +0100
commita4e2f96b133a9f753b6b9fd4686f3ff2a8694dfe (patch)
tree0ad8715f8213d3af68fe50186a4ec3bfd4b1fc34 /src
parentbdb5846987fa21f410204f0aa15670f37339da8c (diff)
parent0ea9b27c348130960dbb3185cd5e60a10e65e125 (diff)
downloadvyos-1x-a4e2f96b133a9f753b6b9fd4686f3ff2a8694dfe.tar.gz
vyos-1x-a4e2f96b133a9f753b6b9fd4686f3ff2a8694dfe.zip
Merge pull request #4569 from dmbaturin/T6144-update-free-space-check
installer: T6144: require at least 2GB of free space for image upgrade
Diffstat (limited to 'src')
-rwxr-xr-xsrc/op_mode/image_installer.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/op_mode/image_installer.py b/src/op_mode/image_installer.py
index 27371a18f..d1f670ae9 100755
--- a/src/op_mode/image_installer.py
+++ b/src/op_mode/image_installer.py
@@ -19,7 +19,7 @@
from argparse import ArgumentParser, Namespace
from pathlib import Path
-from shutil import copy, chown, rmtree, copytree
+from shutil import copy, chown, rmtree, copytree, disk_usage
from glob import glob
from sys import exit
from os import environ
@@ -62,6 +62,7 @@ from vyos.version import get_version_data
# define text messages
MSG_ERR_NOT_LIVE: str = 'The system is already installed. Please use "add system image" instead.'
MSG_ERR_LIVE: str = 'The system is in live-boot mode. Please use "install image" instead.'
+MSG_ERR_NOT_ENOUGH_SPACE: str = 'Image upgrade requires at least 2GB of free drive space.'
MSG_ERR_NO_DISK: str = 'No suitable disk was found. There must be at least one disk of 2GB or greater size.'
MSG_ERR_IMPROPER_IMAGE: str = 'Missing sha256sum.txt.\nEither this image is corrupted, or of era 1.2.x (md5sum) and would downgrade image tools;\ndisallowed in either case.'
MSG_ERR_INCOMPATIBLE_IMAGE: str = 'Image compatibility check failed, aborting installation.'
@@ -976,6 +977,14 @@ def add_image(image_path: str, vrf: str = None, username: str = '',
if image.is_live_boot():
exit(MSG_ERR_LIVE)
+ # Trying to upgrade with insufficient space can break the system.
+ # It's better to be on the safe side:
+ # our images are a bit below 1G,
+ # so one gigabyte to download the image plus one more to install it
+ # sounds like a sensible estimate.
+ if disk_usage('/').free < (2 * 1024**3):
+ exit(MSG_ERR_NOT_ENOUGH_SPACE)
+
environ['REMOTE_USERNAME'] = username
environ['REMOTE_PASSWORD'] = password