From 5dea31058d456ae7e6de260c5a063442c3a6e81e Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Sun, 15 Nov 2020 17:19:25 +0100 Subject: [PATCH] Add option to specify extra free space in pmbootstrap init (MR 1989) This adds a new commandline flag -E / --extra-space for specifying the amount of additional space to be added to the image size to work around cases where the automatically determined size turns out to not actually be enough. The value is also asked for in the "Additional options" section of the interactive mode. Fixes: #1904 --- pmb/config/__init__.py | 4 +++- pmb/config/init.py | 13 +++++++++++++ pmb/install/_install.py | 2 +- pmb/parse/arguments.py | 4 ++++ test/test_questions.py | 5 +++-- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 5f93ae50..1c498cf2 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -58,7 +58,8 @@ config_keys = ["aports", "ui_extras", "user", "work", - "boot_size"] + "boot_size", + "extra_space"] # Config file/commandline default values # $WORK gets replaced with the actual value for args.work (which may be @@ -94,6 +95,7 @@ defaults = { "user": "user", "work": os.path.expanduser("~") + "/.local/var/pmbootstrap", "boot_size": "128", + "extra_space": "0" } # diff --git a/pmb/config/init.py b/pmb/config/init.py index 915bc3fe..094b4b5f 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -341,6 +341,7 @@ def ask_for_device(args): def ask_for_additional_options(args, cfg): # Allow to skip additional options logging.info("Additional options:" + f" extra free space: {args.extra_space} MB," f" boot partition size: {args.boot_size} MB," f" parallel jobs: {args.jobs}," f" ccache per arch: {args.ccache_size}") @@ -349,6 +350,18 @@ def ask_for_additional_options(args, cfg): default=False): return + # Extra space + logging.info("Set extra free space to 0, unless you ran into a 'No space" + " left on device' error. In that case, the size of the" + " rootfs could not be calculated properly on your machine," + " and we need to add extra free space to make the image big" + " enough to fit the rootfs (pmaports#1904)." + " How much extra free space do you want to add to the image" + " (in MB)?") + answer = pmb.helpers.cli.ask(args, "Extra space size", None, + args.extra_space, validation_regex="[0-9]+") + cfg["pmbootstrap"]["extra_space"] = answer + # Boot size logging.info("What should be the boot partition size (in MB)?") answer = pmb.helpers.cli.ask(args, "Boot size", None, args.boot_size, diff --git a/pmb/install/_install.py b/pmb/install/_install.py index 42fa2468..d40c7e4c 100644 --- a/pmb/install/_install.py +++ b/pmb/install/_install.py @@ -51,7 +51,7 @@ def get_subpartitions_size(args, suffix): chroot = f"{args.work}/chroot_{suffix}" root = pmb.helpers.other.folder_size(args, chroot) / 1024 / 1024 root *= 1.20 - root += 50 + root += 50 + int(args.extra_space) return (boot, root) diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 4ad7bd8f..73406f61 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -357,6 +357,10 @@ def arguments(): pmb.config.defaults["mirror_alpine"], metavar="URL") parser.add_argument("-j", "--jobs", help="parallel jobs when compiling") + parser.add_argument("-E", "--extra-space", + help="specify an integer with the amount of additional" + "space to allocate to the image in MB (default" + " 0)") parser.add_argument("-B", "--boot-size", help="specify an integer with your preferred boot" "partition size on target machine in MB (default" diff --git a/test/test_questions.py b/test/test_questions.py index c98f2d54..02d66c23 100644 --- a/test/test_questions.py +++ b/test/test_questions.py @@ -261,9 +261,10 @@ def test_questions_additional_options(args, monkeypatch): assert cfg == {"pmbootstrap": {}} # Answer everything - fake_answers(monkeypatch, ["y", "64", "5", "2G", "n"]) + fake_answers(monkeypatch, ["y", "128", "64", "5", "2G", "n"]) func(args, cfg) - assert cfg == {"pmbootstrap": {"boot_size": "64", + assert cfg == {"pmbootstrap": {"extra_space": "128", + "boot_size": "64", "jobs": "5", "ccache_size": "2G"}}