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.
This commit is contained in:
clayton craft 2017-10-13 18:52:43 +00:00 committed by Oliver Smith
parent a13623bbfb
commit 9f0c884188
1 changed files with 8 additions and 8 deletions

View File

@ -66,16 +66,16 @@ def create_and_mount_image(args, size):
raise RuntimeError("Failed to remove old image file: " + raise RuntimeError("Failed to remove old image file: " +
img_path_outside) img_path_outside)
# Convert to MB and ask for confirmation # Make sure there is enough free space
mb = str(round(size / 1024 / 1024)) + "M" size_mb = round(size / (1024**2))
logging.info("(native) create " + args.device + ".img (" + mb + ")") disk_data = os.statvfs(args.work)
logging.info("WARNING: Make sure, that your target device's partition" free = round((disk_data.f_bsize * disk_data.f_bavail) / (1024**2))
" table has allocated at least " + mb + " as system" if size_mb > free:
" partition!") raise RuntimeError("Not enough free space to create rootfs image! (free: " + str(free) + "M, required: " + str(size_mb) + "M)")
if not pmb.helpers.cli.confirm(args, default=True): mb = str(size_mb) + "M"
raise RuntimeError("Aborted.")
# Create empty image file # Create empty image file
logging.info("(native) create " + args.device + ".img (" + mb + ")")
pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/rootfs"]) pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/rootfs"])
pmb.chroot.root(args, ["truncate", "-s", mb, img_path]) pmb.chroot.root(args, ["truncate", "-s", mb, img_path])