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
This commit is contained in:
Johannes Marbach 2020-11-15 17:19:25 +01:00
parent e6543332de
commit 5dea31058d
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
5 changed files with 24 additions and 4 deletions

View file

@ -58,7 +58,8 @@ config_keys = ["aports",
"ui_extras", "ui_extras",
"user", "user",
"work", "work",
"boot_size"] "boot_size",
"extra_space"]
# Config file/commandline default values # Config file/commandline default values
# $WORK gets replaced with the actual value for args.work (which may be # $WORK gets replaced with the actual value for args.work (which may be
@ -94,6 +95,7 @@ defaults = {
"user": "user", "user": "user",
"work": os.path.expanduser("~") + "/.local/var/pmbootstrap", "work": os.path.expanduser("~") + "/.local/var/pmbootstrap",
"boot_size": "128", "boot_size": "128",
"extra_space": "0"
} }
# #

View file

@ -341,6 +341,7 @@ def ask_for_device(args):
def ask_for_additional_options(args, cfg): def ask_for_additional_options(args, cfg):
# Allow to skip additional options # Allow to skip additional options
logging.info("Additional options:" logging.info("Additional options:"
f" extra free space: {args.extra_space} MB,"
f" boot partition size: {args.boot_size} MB," f" boot partition size: {args.boot_size} MB,"
f" parallel jobs: {args.jobs}," f" parallel jobs: {args.jobs},"
f" ccache per arch: {args.ccache_size}") f" ccache per arch: {args.ccache_size}")
@ -349,6 +350,18 @@ def ask_for_additional_options(args, cfg):
default=False): default=False):
return 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 # Boot size
logging.info("What should be the boot partition size (in MB)?") logging.info("What should be the boot partition size (in MB)?")
answer = pmb.helpers.cli.ask(args, "Boot size", None, args.boot_size, answer = pmb.helpers.cli.ask(args, "Boot size", None, args.boot_size,

View file

@ -51,7 +51,7 @@ def get_subpartitions_size(args, suffix):
chroot = f"{args.work}/chroot_{suffix}" chroot = f"{args.work}/chroot_{suffix}"
root = pmb.helpers.other.folder_size(args, chroot) / 1024 / 1024 root = pmb.helpers.other.folder_size(args, chroot) / 1024 / 1024
root *= 1.20 root *= 1.20
root += 50 root += 50 + int(args.extra_space)
return (boot, root) return (boot, root)

View file

@ -357,6 +357,10 @@ def arguments():
pmb.config.defaults["mirror_alpine"], pmb.config.defaults["mirror_alpine"],
metavar="URL") metavar="URL")
parser.add_argument("-j", "--jobs", help="parallel jobs when compiling") 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", parser.add_argument("-B", "--boot-size",
help="specify an integer with your preferred boot" help="specify an integer with your preferred boot"
"partition size on target machine in MB (default" "partition size on target machine in MB (default"

View file

@ -261,9 +261,10 @@ def test_questions_additional_options(args, monkeypatch):
assert cfg == {"pmbootstrap": {}} assert cfg == {"pmbootstrap": {}}
# Answer everything # Answer everything
fake_answers(monkeypatch, ["y", "64", "5", "2G", "n"]) fake_answers(monkeypatch, ["y", "128", "64", "5", "2G", "n"])
func(args, cfg) func(args, cfg)
assert cfg == {"pmbootstrap": {"boot_size": "64", assert cfg == {"pmbootstrap": {"extra_space": "128",
"boot_size": "64",
"jobs": "5", "jobs": "5",
"ccache_size": "2G"}} "ccache_size": "2G"}}