From 9f0c8841888929d0814b67b345a5c94ae9b08a29 Mon Sep 17 00:00:00 2001 From: clayton craft Date: Fri, 13 Oct 2017 18:52:43 +0000 Subject: [PATCH] Generating rootfs image is now 110% less scary (#758) This adds a check to make sure there is enough disk space for creating the device image. One of the two proposed improvements of #708. --- pmb/install/blockdevice.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pmb/install/blockdevice.py b/pmb/install/blockdevice.py index 3c11ecee..9ef092d6 100644 --- a/pmb/install/blockdevice.py +++ b/pmb/install/blockdevice.py @@ -66,16 +66,16 @@ def create_and_mount_image(args, size): raise RuntimeError("Failed to remove old image file: " + img_path_outside) - # Convert to MB and ask for confirmation - mb = str(round(size / 1024 / 1024)) + "M" - logging.info("(native) create " + args.device + ".img (" + mb + ")") - logging.info("WARNING: Make sure, that your target device's partition" - " table has allocated at least " + mb + " as system" - " partition!") - if not pmb.helpers.cli.confirm(args, default=True): - raise RuntimeError("Aborted.") + # Make sure there is enough free space + size_mb = round(size / (1024**2)) + disk_data = os.statvfs(args.work) + free = round((disk_data.f_bsize * disk_data.f_bavail) / (1024**2)) + if size_mb > free: + raise RuntimeError("Not enough free space to create rootfs image! (free: " + str(free) + "M, required: " + str(size_mb) + "M)") + mb = str(size_mb) + "M" # Create empty image file + logging.info("(native) create " + args.device + ".img (" + mb + ")") pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/rootfs"]) pmb.chroot.root(args, ["truncate", "-s", mb, img_path])